我使用tCode = SE38创建了一个程序 我正在使用Native 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布局,我该怎么做?
答案 0 :(得分:1)
好的,首先我会将您的结构创建为一个类型,然后创建一个该类型的表以传递给SALV。我在这个例子中使用SALV因为它更容易。您需要一个表类型作为结构格式传递给SALV,它目前无法通过您的声明识别。我在我的代码中删除了mandt where子句,因为在我们的系统中我们无法通过客户端进行查询。执行设置alv设置,然后display方法执行它。
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
答案 1 :(得分:1)
以下是一些评论的例子。
首先,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 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行。