2014 Oct 14 5:03 PM
Hi everybody,
my requirement is to create an internal table depending on a dynamic type.
then create another itab wich have the same structure but with different types (char50).
exemple :
parameters p_tab type dd02l-tabname.
data itab ref to data.
create data itab type table of (p_tab).
in this case, if user enter bseg as parameter, my itab will have this structure: mandt(clnt3) bukrs(char4) belnr(char10) gjahr(numc4) ....
my requirement is to create an itab2 with this structure like this: mandt(char50) bukrs(char50) belnr(char50) gjahr(char50) ....
thanks.
2014 Oct 14 5:46 PM
Hi Raj,
You could use RTTS & classes related to RTTI.
I have tested this code which will fulfill your purpose.
PARAMETERS p_tab TYPE dd02l-tabname.
DATA itab TYPE REF TO data.
CREATE DATA itab TYPE TABLE OF (p_tab).
DATA:
wa_structure TYPE REF TO data,
li_table TYPE REF TO data,
lr_field_descr TYPE REF TO cl_abap_elemdescr,
lo_structure TYPE REF TO cl_abap_structdescr,
lo_table TYPE REF TO cl_abap_tabledescr,
ls_component TYPE cl_abap_structdescr=>component,
li_tot_comp TYPE cl_abap_structdescr=>component_table.
DATA lr_structdescr TYPE REF TO cl_abap_structdescr.
DATA l_component TYPE abap_compdescr .
lr_structdescr ?= cl_abap_typedescr=>describe_by_name( p_tab ).
LOOP AT lr_structdescr->components INTO l_component.
ls_component-name = l_component-name.
lr_field_descr ?= cl_abap_elemdescr=>describe_by_name( 'CHAR50' ).
ls_component-type = lr_field_descr.
INSERT ls_component INTO TABLE li_tot_comp.
ENDLOOP.
*Create data
lo_structure = cl_abap_structdescr=>create( li_tot_comp ).
lo_table = cl_abap_tabledescr=>create( lo_structure ).
* Create dynamic objects
CREATE DATA wa_structure TYPE HANDLE lo_structure.
CREATE DATA li_table TYPE HANDLE lo_table.
Test this code & let me know your comments,
Thanks,
Sharath
Hi everybody,
my requirement is to create an internal table depending on a dynamic type.
then create another itab wich have the same structure but with different types (char50).
exemple :
parameters p_tab type dd02l-tabname.
data itab ref to data.
create data itab type table of (p_tab).
in this case, if user enter bseg as parameter, my itab will have this structure: mandt(clnt3) bukrs(char4) belnr(char10) gjahr(numc4) ....
my requirement is to create an itab2 with this structure like this: mandt(char50) bukrs(char50) belnr(char50) gjahr(char50) ....
thanks.
2014 Oct 14 5:46 PM
Hi Raj,
You could use RTTS & classes related to RTTI.
I have tested this code which will fulfill your purpose.
PARAMETERS p_tab TYPE dd02l-tabname.
DATA itab TYPE REF TO data.
CREATE DATA itab TYPE TABLE OF (p_tab).
DATA:
wa_structure TYPE REF TO data,
li_table TYPE REF TO data,
lr_field_descr TYPE REF TO cl_abap_elemdescr,
lo_structure TYPE REF TO cl_abap_structdescr,
lo_table TYPE REF TO cl_abap_tabledescr,
ls_component TYPE cl_abap_structdescr=>component,
li_tot_comp TYPE cl_abap_structdescr=>component_table.
DATA lr_structdescr TYPE REF TO cl_abap_structdescr.
DATA l_component TYPE abap_compdescr .
lr_structdescr ?= cl_abap_typedescr=>describe_by_name( p_tab ).
LOOP AT lr_structdescr->components INTO l_component.
ls_component-name = l_component-name.
lr_field_descr ?= cl_abap_elemdescr=>describe_by_name( 'CHAR50' ).
ls_component-type = lr_field_descr.
INSERT ls_component INTO TABLE li_tot_comp.
ENDLOOP.
*Create data
lo_structure = cl_abap_structdescr=>create( li_tot_comp ).
lo_table = cl_abap_tabledescr=>create( lo_structure ).
* Create dynamic objects
CREATE DATA wa_structure TYPE HANDLE lo_structure.
CREATE DATA li_table TYPE HANDLE lo_table.
Test this code & let me know your comments,
Thanks,
Sharath
2014 Oct 15 9:56 AM
Hi Sharath,
Thank you very much for your answer.
I tried your code using BSEG as parameter
I runned it in debug mode and the result was like this:
But it was supposed to be like this (but with char50 as type):
because after creating this dynamic itab i have to fill it by from an excel file by calling the FM 'TEXT_CONVERT_XLS_TO_SAP'
2014 Oct 15 10:09 AM
CHECK wa_structure AND li_table.
These are the work area and internal table created.
2014 Oct 15 10:24 AM
I am new at RTTI and RTTS programming so sorry for my ignorance .
can you tell me how to fill this kind of table (li_table)?
and then how to select from it?
thank you in advance.
2014 Oct 15 11:06 AM
FIELD-SYMBOLS : <fs_it> TYPE STANDARD TABLE, "Dynamic intenal table
<fs_wa>, "Dynamic work area
<fs_fvalue> TYPE any. "Component in work area
ASSIGN wa_structure->* TO <fs_wa>. "Dynamic work area
ASSIGN li_table->* TO <fs_it>. "Dynamic Internal Table
To fill data into work area...
ASSIGN COMPONENT 'BUKRS' OF STRUCTURE <fs_wa> TO <fs_fvalue>.
<fs_fvalue> = '1000'. "Company code
Append work area to itab.
APPEND <FS_WA> TO <FS_IT>.
Read table
READ TABLE <fs_it> INTO <fs_wa_1> WITH KEY ('BUKRS') = '1000'.
2014 Oct 15 1:56 PM