简体   繁体   English

SAP ABAP - 尚未分配字段符号

[英]SAP ABAP - Field Symbol Has not yet been assigned

I am trying to use table from another report program as in the following:我正在尝试使用另一个报告程序中的表格,如下所示:

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

DATA lr_pay_data              TYPE REF TO data.

FIELD-SYMBOLS: <lt_pay_data>   TYPE ANY TABLE,
               <pos_data> type any.

  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.
    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.

LOOP AT <lt_pay_data> ASSIGNING <pos_data>.

 APPEND INITIAL LINE to lt_report ASSIGNING <fs_rep>.
 MOVE-CORRESPONDING <pos_data> TO <fs_rep>.

WRITE: / <pos_data>.

ENDLOOP.

Write: 'Program End!'.

I am getting the following runtime error:我收到以下运行时错误:

you attenpted to access an anassigned field symbol (data segment 12)您试图访问指定的字段符号(数据段 12)

Maybe (as suggested by arrows in the code) that <'lt_pay_data'> has not been initialized or assigned but I do not know how assign any table type variable.也许(如代码中的箭头所示) <'lt_pay_data'> 尚未初始化或分配,但我不知道如何分配任何表类型变量。

This could be what's going on in your program:这可能是您的程序中发生的事情:

PROGRAM zref.

DATA          lr_pay_data   TYPE REF TO data.
FIELD-SYMBOLS <lt_pay_data> TYPE ANY TABLE.

From F1 on ASSIGN: " If the reference variable dref does not reference a data object, the assignment is not performed and sy-subrc is set to 4 "从 ASSIGN 上的 F1 开始:“如果引用变量 dref 未引用数据对象,则不会执行赋值并将 sy-subrc 设置为 4”

ASSIGN lr_pay_data->* TO <lt_pay_data>.
IF sy-subrc <> 0.
  MESSAGE 'You need to CREATE DATA for your REF TO variable before dereferencing it' TYPE 'S'.
ENDIF.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM