Problem solve Get help with specific problems with your technologies, process and projects.

Produce the structure of an internal table

This tip is useful for senior ABAP developers looking to find the structure of an internal table.

If you want to know the structure of internal table dynamically, you can use CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA method.
 

TYPE-POOLS: ABAP.
TYPES: BEGIN OF TY_ISEG ,
        IBLNR LIKE ISEG-IBLNR,            "Doc no
        GJAHR LIKE ISEG-GJAHR,            "Year
        ZEILI LIKE ISEG-ZEILI,            "Position
        MATNR LIKE ISEG-MATNR,            "Material
        WERKS LIKE ISEG-WERKS,            "Plant
        USNAD LIKE ISEG-USNAD,            "User
        BUDAT LIKE ISEG-BUDAT,            "Posting Date
        DMBTR LIKE ISEG-DMBTR,            "Posted Amount (Line Item)
        WAERS LIKE ISEG-WAERS,            "Local Currency
        WRTBM LIKE ISEG-WRTBM,            "Doc Total Amt
      END   OF TY_ISEG.


DATA: T_ISEG TYPE STANDARD TABLE OF TY_ISEG,
      V_ISEG TYPE TY_ISEG,
      FNAME  TYPE FIELDNAME.

DATA: L_REF TYPE REF TO CL_ABAP_TABLEDESCR,
      L_TYP TYPE REF TO CL_ABAP_TYPEDESCR.


FIELD-SYMBOLS: &ltKEY_COMP_WA> TYPE ABAP_KEYDESCR,
               &ltFS> TYPE ANY.

V_ISEG-IBLNR = '0100000053'.
V_ISEG-GJAHR = '2005'.
V_ISEG-ZEILI = '001'.
V_ISEG-MATNR = '000000000000000041'.
V_ISEG-WERKS = 'Z1I1'.
V_ISEG-USNAD = 'RSUBBARAYAN'.
V_ISEG-BUDAT = '20050405'.
V_ISEG-DMBTR = 40000.
V_ISEG-WAERS = 'USD'.
V_ISEG-WRTBM = 50000.

APPEND V_ISEG TO T_ISEG.

V_ISEG-IBLNR = '0100000053'.
V_ISEG-GJAHR = '2005'.
V_ISEG-ZEILI = '001'.
V_ISEG-MATNR = '000000000000000041'.
V_ISEG-WERKS = 'Z1I1'.
V_ISEG-USNAD = 'RSUBBARAYAN'.
V_ISEG-BUDAT = '20050405'.
V_ISEG-DMBTR = 40000.
V_ISEG-WAERS = 'USD'.
V_ISEG-WRTBM = 50000.

APPEND V_ISEG TO T_ISEG.

L_REF ?= CL_ABAP_TYPEDESCR=&gtDESCRIBE_BY_DATA( T_ISEG ).

LOOP AT T_ISEG INTO V_ISEG.
  WRITE:/.
  LOOP AT L_REF->KEY ASSIGNING &ltKEY_COMP_WA&gt.    WRITE:/ &ltKEY_COMP_WA&gt-NAME.    CONCATENATE 'V_ISEG-' &ltKEY_COMP_WA&gt-NAME INTO FNAME.
    ASSIGN (FNAME) TO &ltFS&gt.    CHECK SY-SUBRC = 0.
    L_TYP ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA_REF( &ltFS> ).
    WRITE: &ltFS>, 50 L_TYP-&gtTYPE_KIND.  ENDLOOP.
ENDLOOP.

Dig Deeper on SAP Basis

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchContentManagement

SearchHRSoftware

Close