如何定义 CAST 在 OpenSQL 中浮动?

How to define CAST to float in OpenSQL?

我尝试用 CAST 写一个 select 语句,但我不知道如何输入浮点值。

这不起作用:

SELECT
  field1, field2,
  CAST( field3 AS FLTP ) * CAST( '0.03' AS FLTP )  AS out2  
FROM table1
INTO TABLE @DATA(lt_table1).

我收到此错误消息:CASTs to a numeric type are not allowed for '0.03' (the type is incorrect),所以我猜引号中的任何内容都被假定为文本。

我找到了这个解决方法:

DATA: lv_discount TYPE f VALUE '0.03'.

SELECT
  field1, field2,
  CAST( field3 AS FLTP ) * CAST( @lv_flt AS FLTP ) AS out1
FROM table1
INTO TABLE @DATA(lt_table1).

如果没有这个变通办法,我该怎么办?

ABAP 不支持数字字面量中的小数点,应按照建议here.
在字符字面量中指定小数点 陷阱是 CAST 运算符不支持字符文字,因为它的 syntax help 说:

For the operand operand, columns col of database tables or views plus host variables dobj and literals of all numeric types except decimal floating point numbers are possible.

可能的解决方法如下:

SELECT matnr, menge,
  CAST( menge AS FLTP ) * CAST( 3 AS FLTP ) / CAST( 100 AS FLTP ) AS out2
FROM mseg
INTO TABLE @DATA(lt_table1).

但更好的选择是在 Open 中使用 ABAP 表达式 SQL

   SELECT
      field1, field2,
      CAST( field3 AS FLTP ) * @( conv f( '0.03' ) ) AS out1
    FROM table1
    INTO TABLE @DATA(lt_table1).