This code can be helpful to get fields names of an Internal Table at Runtime.
The Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
report ztest_internal_tab_comp line-size 100. type-pools: abap.
types: begin of x_final, matnr type matnr, werks type werks_d, flag type c length 1, value type p length 10 decimals 2, end of x_final. data:
i_data type sorted table of x_final with unique key matnr,
tab_return type abap_compdescr_tab,
components like line of tab_return.
perform get_int_table_fields using i_data changing tab_return.
loop at tab_return into components. write: / components-name, components-type_kind, components-length,components-decimals. endloop.
form get_int_table_fields using t_data type any table changing t_return type abap_compdescr_tab. data: oref_table type ref to cl_abap_tabledescr, oref_struc type ref to cl_abap_structdescr, oref_error type ref to cx_root, text type string.
try. oref_table ?= cl_abap_tabledescr=>describe_by_data( t_data ). catch cx_root into oref_error. text = oref_error->get_text( ). write: / text. exit. endtry.
try. oref_struc ?= oref_table->get_table_line_type( ). catch cx_root into oref_error. text = oref_error->get_text( ). write: / text. exit. endtry. append lines of oref_struc->components to t_return. endform.
|
Now if we test it...
The code can also be used to get components of a structure.
Thank you so much for your clear explanation with coding really nice
ReplyDelete