12-27-2018 6:54 AM
Hi All,
I have a dynamic internal table. I want to get the number of fields in the work area. Is there any FM for the same?
Thanks,
Samriddhi
12-27-2018 7:37 AM
Hi,
You can refer to cl_abap_structdescr and cl_abap_typedescr
Here is a snippet
data lr_structdescr type ref to cl_abap_structdescr,
lt_components type abap_component_tab,
l_component like line of lt_components.
lr_structdescr ?= cl_abap_typedescr=>describe_by_data( <dyn_wa> ). "here you describe your field symboL
lt_components = lr_structdescr->get_components( ). "get fields names into internal table
"check out LT_COMPONENTS in debugger for your needs
Regards,
Nam
12-27-2018 7:37 AM
Hi,
You can refer to cl_abap_structdescr and cl_abap_typedescr
Here is a snippet
data lr_structdescr type ref to cl_abap_structdescr,
lt_components type abap_component_tab,
l_component like line of lt_components.
lr_structdescr ?= cl_abap_typedescr=>describe_by_data( <dyn_wa> ). "here you describe your field symboL
lt_components = lr_structdescr->get_components( ). "get fields names into internal table
"check out LT_COMPONENTS in debugger for your needs
Regards,
Nam
12-27-2018 9:48 AM
12-27-2018 8:38 AM
Hi Samriddhi,
DATA(lines) = lines( CAST cl_abap_structdescr(
CAST cl_abap_tabledescr(
cl_abap_tabledescr=>describe_by_name( p_name = 'MAKT_TAB' ) )->get_table_line_type( )
"cl_abap_tabledescr=>describe_by_data( p_data = 'Your Internal Table' ) )->get_table_line_type( )
)->components ).
Regards,
Cenkay
12-27-2018 9:10 AM
describe_by_name is quite unusual, we use more often cl_abap_tabledescr=>describe_by_data( <dynitab> or paramitab ) (without quotes around!)
12-27-2018 9:53 AM
Hi Cenky,
Thanks for the answer! However, This is throwing me a dump.
Regards,
Samriddhi
12-27-2018 12:39 PM
@nsamriddhi probably you didn't adapt the code adequately, no doubt it should work (and it's basically the same answer as Nam but with more complete code).
12-27-2018 11:28 AM
Hi Samriddhi,
Did you assigned your dynamic tab to internal table?
Basic demo program:
TYPES : tty_mseg TYPE TABLE OF mseg.
DATA : gr_tab TYPE REF TO data.
FIELD-SYMBOLS : <fs_tab> TYPE STANDARD TABLE.
"creation demo table
CREATE DATA gr_tab TYPE tty_mseg.
"assign data to itab
ASSIGN gr_tab->* TO <fs_tab>.
TRY.
DATA(gv_lines) = lines( CAST cl_abap_structdescr(
CAST cl_abap_tabledescr(
cl_abap_tabledescr=>describe_by_data( p_data = <fs_tab> ) )->get_table_line_type( )
)->components ).
CATCH cx_sy_move_cast_error.
ENDTRY.
cl_demo_output=>display_text( text = |{ gv_lines }| ).