10-23-2008 8:00 AM
Hello All,
I have an internal table ITAB1, which will get populated inside the program. This ITAB1 will have only one field.
I want to create an internal table dynamically with the values of ITAB1( single field internal table ) as fields.
Thanks in advance.
Best Regards,
Sasidhar Reddy Matli.
10-23-2008 8:32 AM
u can do it like this....
DATA: struct_type TYPE REF TO cl_abap_structdescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
dref TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
wa_comp LIKE LINE OF comp_tab,
index1 TYPE char10.
LOOP AT excel_tab.
index1 = sy-tabix.
CONCATENATE 'COL' '_' index1 INTO wa_comp-name.
CONDENSE wa_comp-name NO-GAPS.
wa_comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
APPEND wa_comp TO comp_tab.
ENDLOOP.
struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type = cl_abap_tabledescr=>create( struct_type ).
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO <dyn_table>.
CREATE DATA dref TYPE HANDLE struct_type.
ASSIGN dref->* TO <dyn_wa>.
10-23-2008 8:08 AM
Hi
try this code...
wa_ifc-col_pos = '1'.
wa_ifc-fieldname = 'LINE_COLOR'.
wa_ifc-tabname = 1.
wa_ifc-datatype = 'CHAR'.
APPEND wa_ifc TO ifc.
CLEAR wa_ifc.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_month.
ASSIGN dy_month->* TO <dyn_month>.
CREATE DATA dy_wa LIKE LINE OF <dyn_month>.
ASSIGN dy_wa->* TO <wa_month>.
Arunima
10-23-2008 8:21 AM
at this wiki
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/abap/individualcellcoloringindynamic+alv
you can find an example where I build an internal table
you can look at the coding where I loop though the internal table and at the value to the fieldname.
* dynamic fields
LOOP AT ta_pernrs INTO wa_pernrs.
WRITE wa_pernrs-pernr TO h_ri_pernr.
is_lvc_cat-fieldname = wa_pernrs-pernr.
is_lvc_cat-ref_field = 'massn'.
is_lvc_cat-ref_table = 'PERNR'.
is_lvc_cat-just = 'C'.
CONCATENATE it_0002-inits it_0002-nachn(1) INTO is_lvc_cat-scrtext_s SEPARATED BY space.
CONCATENATE it_0002-inits it_0002-nachn INTO is_lvc_cat-scrtext_m SEPARATED BY space.
CONCATENATE it_0002-inits it_0002-nachn INTO is_lvc_cat-scrtext_l SEPARATED BY space.
APPEND is_lvc_cat TO it_lvc_cat.
and then ofcourse the creation of the table which is also mentioned in the earlier reply
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_lvc_cat
IMPORTING
*ep_table = ta_output.*** Create a new Line with the same structure of the table.
ASSIGN ta_output->* TO <ta_output>.*
CREATE DATA new_line LIKE LINE OF <ta_output>.
ASSIGN new_line->* TO <l_line>.
kind regards
arthur de smidt
10-23-2008 8:32 AM
u can do it like this....
DATA: struct_type TYPE REF TO cl_abap_structdescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
dref TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
wa_comp LIKE LINE OF comp_tab,
index1 TYPE char10.
LOOP AT excel_tab.
index1 = sy-tabix.
CONCATENATE 'COL' '_' index1 INTO wa_comp-name.
CONDENSE wa_comp-name NO-GAPS.
wa_comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
APPEND wa_comp TO comp_tab.
ENDLOOP.
struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type = cl_abap_tabledescr=>create( struct_type ).
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO <dyn_table>.
CREATE DATA dref TYPE HANDLE struct_type.
ASSIGN dref->* TO <dyn_wa>.
10-23-2008 11:52 AM