Sometime it might be required to get the components of the
structure i.e. list of fields present in structure.
Use function module GET_COMPONENT_LIST
to get the components of the structure.
Example:
REPORT ZVENU_TEST4.
DATA: t_components TYPE STANDARD TABLE OF RSTRUCINFO,
x_components TYPE RSTRUCINFO.
TYPES: BEGIN OF ty_tab,
kunnr type kna1-kunnr,
name1 type kna1-name1,
END OF ty_tab.
DATA: x_kna1 TYPE ty_tab.
*--CAll FM to get hte components of structure
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
PROGRAM = sy-repid
FIELDNAME = 'X_KNA1'
TABLES
COMPONENTS = t_components.
LOOP AT t_components INTO x_components.
WRITE:/ sy-tabix ,' - Field Name : ', x_components-COMPNAME.
ENDLOOP. Output:
DATA: t_components TYPE STANDARD TABLE OF RSTRUCINFO,
x_components TYPE RSTRUCINFO.
TYPES: BEGIN OF ty_tab,
kunnr type kna1-kunnr,
name1 type kna1-name1,
END OF ty_tab.
DATA: x_kna1 TYPE ty_tab.
*--CAll FM to get hte components of structure
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
PROGRAM = sy-repid
FIELDNAME = 'X_KNA1'
TABLES
COMPONENTS = t_components.
LOOP AT t_components INTO x_components.
WRITE:/ sy-tabix ,' - Field Name : ', x_components-COMPNAME.
ENDLOOP. Output:
Output:
Similarly, using this functional module we can get the components
of structure which is present in another program. In such a case pass the
program name to PROGRAM field and
structure name to FIELDNAME field.
NOTE: This
FM give the components of internal table with header line, whereas using this
FM we cannot get the component of structure without header line.
Regards,
Venugopal M N
No comments:
Post a Comment