如何使用cl_salv_bs_runtime_info
How to use cl_salv_bs_runtime_info
我正在尝试检索由程序 RFKSLD00
生成的 ALV table,但我无法使 cl_salv_bs_runtime_info
工作。这是我拥有的:
REPORT ZSAM3.
TYPES: BEGIN OF ty_report,
rec_acc TYPE skont,
vendor TYPE LFA1-LIFNR,
jan_deb TYPE BSEG-WRBTR,
jan_cred TYPE BSEG-WRBTR,
feb_deb TYPE BSEG-WRBTR,
feb_cred TYPE BSEG-WRBTR,
mar_deb TYPE BSEG-WRBTR,
mar_cred TYPE BSEG-WRBTR,
apr_deb TYPE BSEG-WRBTR,
apr_cred TYPE BSEG-WRBTR,
may_deb TYPE BSEG-WRBTR,
may_cred TYPE BSEG-WRBTR,
jun_deb TYPE BSEG-WRBTR,
jun_cred TYPE BSEG-WRBTR,
jul_deb TYPE BSEG-WRBTR,
jul_cred TYPE BSEG-WRBTR,
aug_deb TYPE BSEG-WRBTR,
aug_cred TYPE BSEG-WRBTR,
sep_deb TYPE BSEG-WRBTR,
sep_cred TYPE BSEG-WRBTR,
oct_deb TYPE BSEG-WRBTR,
oct_cred TYPE BSEG-WRBTR,
nov_deb TYPE BSEG-WRBTR,
nov_cred TYPE BSEG-WRBTR,
dec_deb TYPE BSEG-WRBTR,
dec_cred TYPE BSEG-WRBTR,
acc_bal_deb TYPE BSEG-WRBTR,
acc_bal_cred TYPE BSEG-WRBTR,
END OF ty_report,
tt_report TYPE TABLE OF ty_report.
DATA: lt_report TYPE tt_report,
lv_ukurs type tcurr-ukurs,
Tcurr1 type tcurr,
fieldname(4) type c,
fnamedebit(20) type c,
fnamecredit(20) type c.
FIELD-SYMBOLS: <fs_rep> LIKE LINE OF lt_report.
select single ukurs from tcurr
into lv_ukurs
where fcurr = 'EUR'
and tcurr = 'AUD'. "<- your local currency
FIELD-SYMBOLS: <lt_pay_data> TYPE ANY TABLE,
<pos_data> TYPE ANY.
DATA lr_pay_data TYPE REF TO data.
cl_salv_bs_runtime_info=>set(
EXPORTING display = abap_false
metadata = abap_false
structure = ''
data = abap_true ).
SUBMIT RFKSLD00 via SELECTION-SCREEN and return.
TRY.
cl_salv_bs_runtime_info=>get_data(
IMPORTING t_data = lr_pay_data ).
ASSIGN lr_pay_data->* TO <lt_pay_data>.
CATCH cx_salv_bs_sc_runtime_info.
MESSAGE `Unable to retrieve ALV data` TYPE 'E'.
ENDTRY.
LOOP AT <lt_pay_data> ASSIGNING <pos_data>.
APPEND INITIAL LINE to lt_report ASSIGNING <fs_rep>.
MOVE-CORRESPONDING <pos_data> TO <fs_rep>.
CASE <pos_data>-monat. "<- your period
WHEN '01'.
<fs_rep>-jan_deb = w_tab-debit.
<fs_rep>-jan_cred = w_tab-credit.
fieldname = 'jan'.
WHEN '02'.
<fs_rep>-feb_deb = w_tab-debit.
<fs_rep>-feb_cred = w_tab-credit.
fieldname = 'feb'.
WHEN '03'.
<fs_rep>-mar_deb = w_tab-debit.
<fs_rep>-mar_cred = w_tab-credit.
fieldname = 'mar'.
WHEN '04'.
<fs_rep>-apr_deb = w_tab-debit.
<fs_rep>-apr_cred = w_tab-credit.
fieldname = 'apr'.
WHEN '05'.
<fs_rep>-may_deb = w_tab-debit.
<fs_rep>-may_cred = w_tab-credit.
fieldname = 'may'.
WHEN '06'.
<fs_rep>-jun_deb = w_tab-debit.
<fs_rep>-jun_cred = w_tab-credit.
fieldname = 'jun'.
WHEN '07'.
<fs_rep>-jul_deb = w_tab-debit.
<fs_rep>-jul_cred = w_tab-credit.
fieldname = 'jul'.
WHEN '08'.
<fs_rep>-aug_deb = w_tab-debit.
<fs_rep>-aug_cred = w_tab-credit.
fieldname = 'aug'.
WHEN '09'.
<fs_rep>-sep_deb = w_tab-debit.
<fs_rep>-sep_cred = w_tab-credit.
fieldname = 'sep'.
WHEN '10'.
<fs_rep>-oct_deb = w_tab-debit.
<fs_rep>-oct_cred = w_tab-credit.
fieldname = 'oct'.
WHEN '11'.
<fs_rep>-nov_deb = w_tab-debit.
<fs_rep>-nov_cred = w_tab-credit.
fieldname = 'nov'.
WHEN '12'.
<fs_rep>-dec_deb = w_tab-debit.
<fs_rep>-dec_cred = w_tab-credit.
fieldname = 'dec'.
ENDCASE.
concatenate '<fs_rep>' fieldname '_deb'into fnamedebit.
concatenate '<fs_rep>' fieldname '_cred'into fnamecredit.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
DATE = sy-datum
FOREIGN_CURRENCY = 'EUR'
LOCAL_CURRENCY = 'AUD'
FOREIGN_AMOUNT = <fnamedebit>
TYPE_OF_RATE = 'M'
IMPORTING
EXCHANGE_RATE = lv_ukurs
LOCAL_AMOUNT = <w_tab-debit>.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
DATE = sy-datum
FOREIGN_CURRENCY = 'EUR'
LOCAL_CURRENCY = 'AUD'
FOREIGN_AMOUNT = <fnamecredit>
TYPE_OF_RATE = 'M'
IMPORTING
EXCHANGE_RATE = lv_ukurs
LOCAL_AMOUNT = <w_tab-credit>.
ENDLOOP.
Write: 'Program End!'.
我不得不在 SET
方法中指定一个强制性参数结构(我不知道它的值是什么,所以我只输入了 ''
)。此外,方法 GET_DATA_REF
不存在,所以我使用 GET_DATA
代替,现在我得到:
"LR_PAY_DATA" is not type compatible with formal parameter "T_DATA".
可能是因为有更新或其他帖子没有这些问题。
我做错了什么?
T_DATA
参数属于 TABLE
类型,您正试图将 REF TO DATA
传递给它。
您需要传递一个 table.
变量
在你的例子中,它可以像这样完成。
TRY.
ASSIGN lr_pay_data->* TO <lt_pay_data>.
cl_salv_bs_runtime_info=>get_data(
IMPORTING t_data = <lt_pay_data> ).
CATCH cx_salv_bs_sc_runtime_info.
MESSAGE `Unable to retrieve ALV data` TYPE 'E'.
ENDTRY.
当然,首先你必须在某个时候初始化 lr_pay_data
,因为我在你的代码中没有看到它。
我正在尝试检索由程序 RFKSLD00
生成的 ALV table,但我无法使 cl_salv_bs_runtime_info
工作。这是我拥有的:
REPORT ZSAM3.
TYPES: BEGIN OF ty_report,
rec_acc TYPE skont,
vendor TYPE LFA1-LIFNR,
jan_deb TYPE BSEG-WRBTR,
jan_cred TYPE BSEG-WRBTR,
feb_deb TYPE BSEG-WRBTR,
feb_cred TYPE BSEG-WRBTR,
mar_deb TYPE BSEG-WRBTR,
mar_cred TYPE BSEG-WRBTR,
apr_deb TYPE BSEG-WRBTR,
apr_cred TYPE BSEG-WRBTR,
may_deb TYPE BSEG-WRBTR,
may_cred TYPE BSEG-WRBTR,
jun_deb TYPE BSEG-WRBTR,
jun_cred TYPE BSEG-WRBTR,
jul_deb TYPE BSEG-WRBTR,
jul_cred TYPE BSEG-WRBTR,
aug_deb TYPE BSEG-WRBTR,
aug_cred TYPE BSEG-WRBTR,
sep_deb TYPE BSEG-WRBTR,
sep_cred TYPE BSEG-WRBTR,
oct_deb TYPE BSEG-WRBTR,
oct_cred TYPE BSEG-WRBTR,
nov_deb TYPE BSEG-WRBTR,
nov_cred TYPE BSEG-WRBTR,
dec_deb TYPE BSEG-WRBTR,
dec_cred TYPE BSEG-WRBTR,
acc_bal_deb TYPE BSEG-WRBTR,
acc_bal_cred TYPE BSEG-WRBTR,
END OF ty_report,
tt_report TYPE TABLE OF ty_report.
DATA: lt_report TYPE tt_report,
lv_ukurs type tcurr-ukurs,
Tcurr1 type tcurr,
fieldname(4) type c,
fnamedebit(20) type c,
fnamecredit(20) type c.
FIELD-SYMBOLS: <fs_rep> LIKE LINE OF lt_report.
select single ukurs from tcurr
into lv_ukurs
where fcurr = 'EUR'
and tcurr = 'AUD'. "<- your local currency
FIELD-SYMBOLS: <lt_pay_data> TYPE ANY TABLE,
<pos_data> TYPE ANY.
DATA lr_pay_data TYPE REF TO data.
cl_salv_bs_runtime_info=>set(
EXPORTING display = abap_false
metadata = abap_false
structure = ''
data = abap_true ).
SUBMIT RFKSLD00 via SELECTION-SCREEN and return.
TRY.
cl_salv_bs_runtime_info=>get_data(
IMPORTING t_data = lr_pay_data ).
ASSIGN lr_pay_data->* TO <lt_pay_data>.
CATCH cx_salv_bs_sc_runtime_info.
MESSAGE `Unable to retrieve ALV data` TYPE 'E'.
ENDTRY.
LOOP AT <lt_pay_data> ASSIGNING <pos_data>.
APPEND INITIAL LINE to lt_report ASSIGNING <fs_rep>.
MOVE-CORRESPONDING <pos_data> TO <fs_rep>.
CASE <pos_data>-monat. "<- your period
WHEN '01'.
<fs_rep>-jan_deb = w_tab-debit.
<fs_rep>-jan_cred = w_tab-credit.
fieldname = 'jan'.
WHEN '02'.
<fs_rep>-feb_deb = w_tab-debit.
<fs_rep>-feb_cred = w_tab-credit.
fieldname = 'feb'.
WHEN '03'.
<fs_rep>-mar_deb = w_tab-debit.
<fs_rep>-mar_cred = w_tab-credit.
fieldname = 'mar'.
WHEN '04'.
<fs_rep>-apr_deb = w_tab-debit.
<fs_rep>-apr_cred = w_tab-credit.
fieldname = 'apr'.
WHEN '05'.
<fs_rep>-may_deb = w_tab-debit.
<fs_rep>-may_cred = w_tab-credit.
fieldname = 'may'.
WHEN '06'.
<fs_rep>-jun_deb = w_tab-debit.
<fs_rep>-jun_cred = w_tab-credit.
fieldname = 'jun'.
WHEN '07'.
<fs_rep>-jul_deb = w_tab-debit.
<fs_rep>-jul_cred = w_tab-credit.
fieldname = 'jul'.
WHEN '08'.
<fs_rep>-aug_deb = w_tab-debit.
<fs_rep>-aug_cred = w_tab-credit.
fieldname = 'aug'.
WHEN '09'.
<fs_rep>-sep_deb = w_tab-debit.
<fs_rep>-sep_cred = w_tab-credit.
fieldname = 'sep'.
WHEN '10'.
<fs_rep>-oct_deb = w_tab-debit.
<fs_rep>-oct_cred = w_tab-credit.
fieldname = 'oct'.
WHEN '11'.
<fs_rep>-nov_deb = w_tab-debit.
<fs_rep>-nov_cred = w_tab-credit.
fieldname = 'nov'.
WHEN '12'.
<fs_rep>-dec_deb = w_tab-debit.
<fs_rep>-dec_cred = w_tab-credit.
fieldname = 'dec'.
ENDCASE.
concatenate '<fs_rep>' fieldname '_deb'into fnamedebit.
concatenate '<fs_rep>' fieldname '_cred'into fnamecredit.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
DATE = sy-datum
FOREIGN_CURRENCY = 'EUR'
LOCAL_CURRENCY = 'AUD'
FOREIGN_AMOUNT = <fnamedebit>
TYPE_OF_RATE = 'M'
IMPORTING
EXCHANGE_RATE = lv_ukurs
LOCAL_AMOUNT = <w_tab-debit>.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
DATE = sy-datum
FOREIGN_CURRENCY = 'EUR'
LOCAL_CURRENCY = 'AUD'
FOREIGN_AMOUNT = <fnamecredit>
TYPE_OF_RATE = 'M'
IMPORTING
EXCHANGE_RATE = lv_ukurs
LOCAL_AMOUNT = <w_tab-credit>.
ENDLOOP.
Write: 'Program End!'.
我不得不在 SET
方法中指定一个强制性参数结构(我不知道它的值是什么,所以我只输入了 ''
)。此外,方法 GET_DATA_REF
不存在,所以我使用 GET_DATA
代替,现在我得到:
"LR_PAY_DATA" is not type compatible with formal parameter "T_DATA".
可能是因为有更新或其他帖子没有这些问题。
我做错了什么?
T_DATA
参数属于 TABLE
类型,您正试图将 REF TO DATA
传递给它。
您需要传递一个 table.
变量在你的例子中,它可以像这样完成。
TRY.
ASSIGN lr_pay_data->* TO <lt_pay_data>.
cl_salv_bs_runtime_info=>get_data(
IMPORTING t_data = <lt_pay_data> ).
CATCH cx_salv_bs_sc_runtime_info.
MESSAGE `Unable to retrieve ALV data` TYPE 'E'.
ENDTRY.
当然,首先你必须在某个时候初始化 lr_pay_data
,因为我在你的代码中没有看到它。