‎2009 Apr 07 11:13 AM
Hi All,
I need to create internal table dynamically, and below is the sample code:
DATA: tab_fieldcat TYPE lvc_t_fcat.
CREATE DATA dref_table TYPE (tabname).
ASSIGN dref_table->* TO <wa>.
structref ?= cl_abap_typedescr=>describe_by_data( <wa> ).
LOOP AT structref ->components ASSIGNING <wa_component>.
IF sy_tabix < 10.
wa_field-fieldname = <wa_component>-name.
wa_field-ref_table = g_table.
wa_field-ref_field = <wa_component>-name.
APPEND wa_field TO tab_fieldcat.
ENDIF.
ENDLOOP.
CREATE DATA eptable LIKE tab_fieldcat. <----------- PROBLEM !!!
ASSIGN eptable->* TO <itab>Problem face at the last statement CREATE DATA, where <itab> is containing field components ROW_POS, COL_POS, FIELDNAME, TABNAME, etc etc that those are fields coming from structure lvc_t_fcat.
But i want dynamic table created according to fields that i filtered during LOOP~ENDLOOP.
Please comment how i can achieve that.
FYI, i can't use method cl_alv_table_create=>create_dynamic_table since i've read the disadvantage abt it from internet.
‎2009 Apr 07 11:21 AM
Use create data statement as follows:
data: gv_struct_name TYPE w_tabname,
gv_dref TYPE REF TO data,.
FIELD-SYMBOLS: <gf_itab> TYPE STANDARD TABLE.
gv_struct_name = 'your structure or table name'
IF NOT gv_struct_name IS INITIAL.
CREATE DATA gv_dref TYPE TABLE OF (gv_struct_name).
ASSIGN gv_dref->* TO <gf_itab>.
ENDIF.
hope this will help you.
‎2009 Apr 07 11:34 AM
Hi Sheelesh, thanks for your reply however your code is leading me back to the problem that mentioned in my post.
Please comment.
‎2009 Apr 07 11:51 AM
The below statements will crate the dynamic internal table with reference to variable gv_struct_name but you need to populate the name of your table to the variable gv_struct_name.
IF NOT gv_struct_name IS INITIAL.
CREATE DATA gv_dref TYPE TABLE OF (gv_struct_name).
ASSIGN gv_dref->* TO <gf_itab>.
ENDIF.
I have used the same code previously and is working fine.
‎2009 Apr 07 11:59 AM
Hi,
You eg given is base on a table. For my case after i got a table, i need to further filter out those not required fields. That's why i need to Loop~Endloop to populate the fields that i need.
Problem comes when i create itab dynamically where it doesn't create according to the structure that i prepared.
‎2009 Apr 10 7:24 AM
Hi all, this is to update you that i get my problem solved by using SUBMIT.
(1)Main program -> (2)Submit subprogram -> (3)call subroutine in Main program
(1) & (2) - In main program, i SUBMIT xxx AND RETURN calling the subprogram.
- At this calling step, i EXPORT my fieldcat to memory ID
(2) & (3) - In subprogram, it only having the code to call back a subrountine in Main prog.
- In main program, it IMPORT back the fieldcat from memory ID and then resume the code for
dynamic table creation.
eg code:
Main prog - Z_MAIN
EXPORT IT_FIELDCAT TO MEMORY ID 'TEST'.
SUBMIT Z_SUB AND RETURN.
FORM TEST.
IMPORT IT_FIELDCAT FROM MEMORY ID 'TEST'.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = IT_FIELDCAT
IMPORTING
ep_table = ep_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
UNASSIGN <gf_table>.
ASSIGN ep_table->* TO <gf_table>.
ENDFORM.Subprog - Z_SUB
PERFORM TEST IN PROGRAM Z_MAIN.
‎2009 Apr 07 11:33 AM
Hi ,
You can use this class for dyanamic generation of class
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc (Field catalog)
IMPORTING
ep_table = dy_table.
dy_table is a pointer to an internal table .
and to be declared like
DATA: dy_table TYPE REF TO data.
ASSIGN dy_table->* TO <dyn_itrecord>.
Following fields of the fieldcatlog also should be filled
xfc-fieldname = 'MCODE'.
xfc-datatype = 'CHAR'.
xfc-inttype = 'D'.
xfc-intlen = '18'.
xfc-decimals = 0.
APPEND xfc TO ifc.
‎2009 Apr 07 11:35 AM
Hi varghese oommen, i can not use cl_alv_table_create=>create_dynamic_table due to it is having limitation on the memory.
Please comment.