我得到了一个内部表从我的选择与一些连接,并做了一些东西。现在我要打印整个表格。我现在得到的是:
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'.
还有比这更好的方法吗?
我不认为没有内置的功能打印一个内部表到一个报告。
您可以尝试使用ALV列表,使用类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报告。
首先,Datadefinition:
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 your stuff:
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。