我在类中具有一个参数类型为P的方法,但是在尝试激活时遇到以下语法错误:
表达式中不能使用通用类型的变量(例如I_DISCOUNT)。
代码是:
METHODS ceil_floor_abs IMPORTING i_discount TYPE p .
METHOD ceil_floor_abs.
SELECT carrid, connid, paymentsum, paymentsum * @i_discount AS disc_payment,
ceil( paymentsum * @i_discount ) AS ceil_payment,
floor( paymentsum * @i_discount ) AS floor_payment,
abs( paymentsum ) AS abs_payment
INTO TABLE @DATA(it_sflight4) UP TO 10 ROWS
FROM sflight.
ENDMETHOD.
怎么了?
答案 0 :(得分:3)
用lv_discount
(或您需要的内容)定义TYPE p LENGTH 16 DECIMALS 2
,并用i_discount
的内容填充,然后在SELECT中使用它:
METHODS ceil_floor_abs IMPORTING i_discount TYPE p .
DATA: lv_discount TYPE p LENGTH 16 DECIMALS 2.
lv_discount = i_discount.
METHOD ceil_floor_abs.
SELECT carrid, connid, paymentsum, paymentsum * @lv_discount AS disc_payment,
ceil( paymentsum * @lv_discount ) AS ceil_payment,
floor( paymentsum * @lv_discount ) AS floor_payment,
abs( paymentsum ) AS abs_payment
INTO TABLE @DATA(it_sflight4) UP TO 10 ROWS
FROM sflight.
ENDMETHOD.
答案 1 :(得分:1)
SQL表达式中不允许使用泛型类型。您需要通过Internal Table
进行操作。
SELECT carrid, connid, paymentsum, paymentsum AS disc_payment,
paymentsum AS ceil_payment,
paymentsum AS floor_payment,
abs( paymentsum ) AS abs_payment
INTO TABLE @DATA(lt_sflight4) UP TO 10 ROWS
FROM sflight.
DATA:
lt_sflight_ceil_floor_abs LIKE lt_sflight4.
lt_sflight_ceil_floor_abs = VALUE #( FOR sflight IN lt_sflight4 (
carrid = sflight-carrid
connid = sflight-connid
paymentsum = sflight-paymentsum
disc_payment = sflight-paymentsum * i_discount
ceil_payment = ceil( sflight-paymentsum * i_discount )
floor_payment = floor( sflight-paymentsum * i_discount )
abs_payment = sflight-abs_payment ) ).