*&———————————————————————*
*& Report ZTEST_TABLE_TYPE
*&
*&———————————————————————
REPORT ZTEST_TABLE_TYPE.
types:
begin of typ_tb,
id type char5,
name type char10,
other type char50,
end of typ_tb. DATA:
s_tb type typ_tb,
t_tb type TABLE OF typ_tb. START-OF-SELECTION.
clear:s_tb.
s_tb-id = ‘01′.
s_tb-name = ‘IBM’.
s_tb-other = ‘GBS’.
APPEND s_tb to t_tb.
clear:s_tb.
s_tb-id = ‘02′.
s_tb-name = ‘SAP’.
s_tb-other = ‘Labs’.
APPEND s_tb to t_tb.
clear:s_tb.
s_tb-id = ‘03′.
s_tb-name = ‘HP’.
s_tb-other = ‘GDCC’.
APPEND s_tb to t_tb. * get the field and output
PERFORM output_field USING t_tb. *&———————————————————————*
*& Form OUTPUT_FIELD
*&———————————————————————*
* get the field and output
*———————————————————————-*
* –>IT_TB table
*———————————————————————-*
FORM OUTPUT_FIELD USING IT_TB type ANY TABLE . DATA:
*— Line type of Import table
lo_line type REF TO data.
DATA:
*— Table Descr
lo_tbdesc type REF TO cl_abap_tabledescr,
*— Structure Descr
lo_scdesc type REF TO cl_abap_structdescr,
lt_comptab TYPE cl_abap_structdescr=>component_table,
lo_comp TYPE cl_abap_structdescr=>component. FIELD-SYMBOLS:
type any. *1. get the line’s reference
CREATE DATA lo_line LIKE LINE OF it_tb.
“get the real type to FS
ASSIGN lo_line->* to . *2. get components
lo_scdesc ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_DATA_REF( lo_line ).
lt_comptab = lo_scdesc->get_components( ). LOOP AT lt_comptab into lo_comp.
write:/ ‘Field name:’, lo_comp-name.
ENDLOOP. ENDFORM. “ OUTPUT_FIELD |