我用 from tCode = SE38 创建了一个程序我正在使用本机SQL。
这是我的代码:
DATA: BEGIN OF GetData OCCURS 0,
AUFNR Type COAS-AUFNR,
AUART Type COAS-AUART,
END OF GetData.
EXEC SQL PERFORMING loop_output.
SELECT AUFNR, AUART
INTO STRUCTURE :GetData
FROM Mytable
Where (MANDT = 450)
ENDEXEC.
FORM loop_output.
WRITE: / GetData-AUFNR,
GetData- AUART.
ENDFORM.
一切运作良好。
现在我想将此报告添加到 ALV 布局中,我该怎么做?
首先,我会将您的结构创建为类型,然后创建一个该类型的表以传递给 SALV。我在这个例子中使用 SALV,因为它要容易得多。您需要一个表类型作为结构格式传递给 SALV,它目前无法识别您的声明。我删除了代码中的 mandt where 子句,因为在我们的系统中我们无法按客户端查询。执行设置 alv 设置,然后显示方法执行它。
TYPES: BEGIN OF ty_getdata,
aufnr TYPE coas-aufnr,
auart TYPE coas-auart,
END OF ty_getdata.
DATA: lt_getdata type TABLE OF ty_getdata.
DATA: gr_salv TYPE REF TO cl_salv_table,
gr_functions TYPE REF TO cl_salv_functions,
gr_display TYPE REF TO cl_salv_display_settings,
gr_columns TYPE REF TO cl_salv_columns.
SELECT aufnr auart
INTO CORRESPONDING FIELDS OF TABLE lt_getdata
FROM mytable.
PERFORM alvsettings.
gr_salv->display( ).
*&---------------------------------------------------------------------*
*& Form alvsettings
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alvsettings .
cl_salv_table=>factory( IMPORTING r_salv_table = gr_salv
CHANGING t_table = lt_getdata ).
gr_functions = gr_salv->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_salv->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'SALV Output' ).
gr_columns = gr_salv->get_columns( ).
gr_columns->set_optimize( 'X' ).
ENDFORM. " alvsettings
下面是一个带有一些注释的示例。
一、数据定义
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 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。