1、可以使用str获取结构
2、可以使用透明表获取结构。
REPORT TEST_01. TYPE-POOLS:SLIS. "调用该类型池 TABLES:SPFLI. *定义FIELDCAT与LAYOUT DATA:FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE, LAYOUT TYPE SLIS_LAYOUT_ALV, W_REPID LIKE SY-REPID. DATA:FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE. DATA:FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE. DATA:FIELDCAT3 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE. DATA:BEGIN OF WA_DATA ,"自定义结构 A(10) TYPE C, B(10) TYPE C, C(10) TYPE C, D(10) TYPE C, END OF WA_DATA. DATA:BEGIN OF WA_DATA1 , "系统字段加自定义字段 MATNR LIKE MARA-MATNR, MAKTX LIKE MAKT-MAKTX, C(10) TYPE C, D(10) TYPE C, END OF WA_DATA1. DATA:GSPFLI TYPE SPFLI ."参照透明表的结构 DATA:GTSPFLI LIKE TABLE OF GSPFLI. DATA:BEGIN OF TEST."各种混搭 INCLUDE STRUCTURE WA_DATA. INCLUDE STRUCTURE GSPFLI. DATA: E(10) TYPE C, END OF TEST. *屏幕开始事件 START-OF-SELECTION. PERFORM GETDATA. PERFORM CATALOG. BREAK-POINT. *The Function Of GETDATA FORM GETDATA. SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE GTSPFLI. ENDFORM. *FORM CATALOG 根据结构体获取FIELDCAT FORM CATALOG. W_REPID = SY-REPID. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING I_PROGRAM_NAME = W_REPID I_INTERNAL_TABNAME = 'WA_DATA' "对于自定义结构使用这个参数并且大写 * I_STRUCTURE_NAME = * I_CLIENT_NEVER_DISPLAY = 'X' I_INCLNAME = W_REPID * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = CHANGING CT_FIELDCAT = FIELDCAT[] EXCEPTIONS INCONSISTENT_INTERFACE = 1 PROGRAM_ERROR = 2 OTHERS = 3. IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING I_PROGRAM_NAME = W_REPID I_INTERNAL_TABNAME = 'WA_DATA1' "对于自定义结构使用这个参数并且大写 * I_STRUCTURE_NAME = * I_CLIENT_NEVER_DISPLAY = 'X' I_INCLNAME = W_REPID * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = CHANGING CT_FIELDCAT = FIELDCAT1[] EXCEPTIONS INCONSISTENT_INTERFACE = 1 PROGRAM_ERROR = 2 OTHERS = 3. IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING I_PROGRAM_NAME = SY-REPID * I_INTERNAL_TABNAME = I_STRUCTURE_NAME = 'SPFLI' "对于参考透明表的结构使用这个参数并且大写 * I_CLIENT_NEVER_DISPLAY = 'X' * I_INCLNAME = * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = CHANGING CT_FIELDCAT = FIELDCAT2[] EXCEPTIONS INCONSISTENT_INTERFACE = 1 PROGRAM_ERROR = 2 OTHERS = 3. IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING I_PROGRAM_NAME = W_REPID I_INTERNAL_TABNAME = 'TEST' "对于自定义结构使用这个参数并且大写 * I_STRUCTURE_NAME = * I_CLIENT_NEVER_DISPLAY = 'X' I_INCLNAME = W_REPID * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = CHANGING CT_FIELDCAT = FIELDCAT3[] EXCEPTIONS INCONSISTENT_INTERFACE = 1 PROGRAM_ERROR = 2 OTHERS = 3. IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. ENDFORM.