公开内部 table 作为报告

Expose internal table as report

我从我的 Select 中获得了一个内部 table,其中包含一些连接并完成了一些操作。现在我想打印整个 table。我现在得到的是:

LOOP AT g_it_material INTO g_wa_material.

  WRITE AT:/(19) g_wa_material-MATNR,
  ...
  (9) g_wa_material-LAEDA.
ENDLOOP.

TOP-OF-PAGE.
  WRITE AT:/(19)'MATNR',
  ...
  (9) 'LAEDA'.

还有比这更好的方法吗?

我认为没有内置函数可以将内部 table 打印到报告中..

您可以尝试使用 ALV 列表,使用 class cl_salv_table:

DATA: gt_outtab TYPE STANDARD TABLE OF bkpf.

DATA: gr_table TYPE REF TO cl_salv_table.

* Fill your output table
SELECT *
  FROM bkpf
  INTO TABLE gt_outtab
  UP TO 40 ROWS.

* Try it!
TRY.
    cl_salv_table=>factory(
      EXPORTING
        list_display = abap_true
      IMPORTING
        r_salv_table = gr_table
      CHANGING
        t_table      = gt_outtab ).
  CATCH cx_salv_msg.                                 
ENDTRY.

gr_table->display( ).

这是我的解决方案和一些评论。我用动态生成的字段目录制作了 ALV 报告。

首先,数据定义:

TYPE-POOLS slis. "import you need for REUSE_ALV_FIELDCATALOG_MERGE

DATA:
  lt_fieldcat TYPE slis_t_fieldcat_alv,

  BEGIN OF G_IT_MATERIAL occurs 0,
    MATNR LIKE MARA-MATNR,
    MTART LIKE MARA-MTART,
    MAKTX_DE LIKE MAKT-MAKTX,
    MAKTX_FR LIKE MAKT-MAKTX,
    MAKTX_IT LIKE MAKT-MAKTX,
    ERNAM LIKE MARA-ERNAM,
    ERSDA LIKE MARA-ERSDA,
    LAEDA LIKE MARA-LAEDA,
  END OF G_IT_MATERIAL.

绝对有必要直接用 LIKE 定义本地结构,否则 REUSE_ALV_FIELDCATALOG_MERGE 的解析器将找不到它。

select你的东西:

 SELECT ma~matnr ma~mtart ma~ernam ma~ersda ma~laeda
 de~maktx as maktx_de fr~maktx as maktx_fr it~maktx as maktx_it
 FROM mara as ma
 LEFT JOIN MAKT as de ON de~matnr = ma~matnr AND de~spras = 'DE'
 LEFT JOIN MAKT as fr ON fr~matnr = ma~matnr AND fr~spras = 'FR'
 LEFT JOIN MAKT as it ON it~matnr = ma~matnr AND it~spras = 'IT'
 INTO CORRESPONDING FIELDS OF TABLE g_it_material
      WHERE ...

动态创建字段目录

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME        = sy-repid

I_INTERNAL_TABNAME    = 'G_IT_MATERIAL'

I_INCLNAME            = sy-repid
CHANGING
ct_fieldcat            = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error          = 2
OTHERS                 = 3.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

现在显示 ALV 网格

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat   = lt_fieldcat                 "you could also give a structure
"i_structure_name      = 'ZMM_SMATERIAL'    "here instead of the fieldcat
TABLES
t_outtab      = g_it_material
EXCEPTIONS
program_error = 1
OTHERS        = 2.

请注意,解析器还需要 72 行的最大行数。