1. 程式人生 > >ABAP結構體,內表動態建立

ABAP結構體,內表動態建立

*&---------------------------------------------------------------------* *& Report ZDYNAMIC_STRUCTER_CREAT *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZDYNAMIC_STRUCTER_CREAT. *TYPES: * BEGIN OF MY_TYPE, * EMPLOYEE TYPE STRING, * MANAGER TYPE STRING, * END OF MY_TYPE. DATA : ZSTRING TYPE REF TO CL_ABAP_STRUCTDESCR, MY_TYPE TYPE REF TO CL_ABAP_STRUCTDESCR, LR_TYPE TYPE REF TO CL_ABAP_TYPEDESCR, COMP_TAB TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE, COMP LIKE LINE OF COMP_TAB, L_STRING TYPE STRING. DATA E_WA TYPE REF TO DATA. DATA E_TABLE TYPE REF TO DATA. DATA MY_TABLE TYPE REF TO CL_ABAP_TABLEDESCR. L_STRING = 'STRING'. *ZSTRING ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( ZSTRING ). CALL METHOD CL_ABAP_DATADESCR=>DESCRIBE_BY_NAME EXPORTING P_NAME = L_STRING RECEIVING P_DESCR_REF = LR_TYPE EXCEPTIONS TYPE_NOT_FOUND = 1 OTHERS = 2. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. COMP-NAME = 'EMPLOYEE'. COMP-TYPE ?= LR_TYPE. APPEND COMP TO COMP_TAB. COMP-NAME = 'MANAGER'. COMP-TYPE ?= LR_TYPE. APPEND COMP TO COMP_TAB. *MY_TYPE = CL_ABAP_STRUCTDESCR=>CREATE( COMP_TAB ). *TRY. CALL METHOD CL_ABAP_STRUCTDESCR=>CREATE EXPORTING P_COMPONENTS = COMP_TAB * P_STRICT = TRUE RECEIVING P_RESULT = MY_TYPE. . * CATCH CX_SY_STRUCT_CREATION . *ENDTRY. CALL METHOD CL_ABAP_TABLEDESCR=>CREATE EXPORTING P_LINE_TYPE = MY_TYPE RECEIVING P_RESULT = MY_TABLE. CREATE DATA E_WA TYPE HANDLE MY_TYPE. *E_WA-EMPLOYEE= ''. CREATE DATA E_TABLE TYPE HANDLE MY_TABLE. *APPEND E_WA TO E_TABLE. WRITE:/. * *DATA: CODE TYPE TABLE OF STRING, * REP(50) TYPE C. * *APPEND 'WRITE / HELLOW WORLD!.' TO CODE. *INSERT REPORT REP FROM CODE. *SUBMIT (REP) AND RETURN.