Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Internal table

Former Member
0 Kudos

Hi Guys,

I am having a requirement in which during runtime new columns get created so i have to use Dynamic Internal tables.can any body show me a example in which how to append rows from Internal table to a Dynamic Intenal table and how to create new columns within the loop of my logic?

Finally i have to display in the ALV grid.

Thanks,

3 REPLIES 3

Former Member
0 Kudos

REPORT zmaschl_create_data_dynamic . 

TYPE-POOLS: slis. 

DATA: it_fcat TYPE slis_t_fieldcat_alv, 
is_fcat LIKE LINE OF it_fcat. 
DATA: it_fieldcat TYPE lvc_t_fcat, 
is_fieldcat LIKE LINE OF it_fieldcat. 
DATA: new_table TYPE REF TO data. 
DATA: new_line TYPE REF TO data. 
FIELD-SYMBOLS: <l_table> TYPE ANY TABLE, 
<l_line> TYPE ANY, 
<l_field> TYPE ANY. 

* Build fieldcat 
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' 
EXPORTING 
i_structure_name = 'SYST' 
CHANGING 
ct_fieldcat = it_fcat[]. 
LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial. 
MOVE-CORRESPONDING is_fcat TO is_fieldcat. 
is_fieldcat-fieldname = is_fcat-fieldname. 
is_fieldcat-ref_field = is_fcat-fieldname. 
is_fieldcat-ref_table = is_fcat-ref_tabname. 
APPEND is_fieldcat TO it_fieldcat. 
ENDLOOP. 

* Create a new Table 
CALL METHOD cl_alv_table_create=>create_dynamic_table 
EXPORTING 
it_fieldcatalog = it_fieldcat 
IMPORTING 
ep_table = new_table. 

* Create a new Line with the same structure of the table. 
ASSIGN new_table->* TO <l_table>. 
CREATE DATA new_line LIKE LINE OF <l_table>. 
ASSIGN new_line->* TO <l_line>. 

* Test it... 
DO 30 TIMES. 
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>. 
<l_field> = sy-index. 
INSERT <l_line> INTO TABLE <l_table>. 
ENDDO. 

LOOP AT <l_table> ASSIGNING <l_line>. 
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>. 
WRITE <l_field>. 
ENDLOOP. 

0 Kudos

Hi Sudhakar,

Can u tell me how to add columns dynamically for that Dynamic Internal table which u send .while craeting the Dynamic Internal table u used Field Catalog as Exporting Paramter, but what my problem is the i dont know how many columns will be there until runtime ,so how can we add records to the field catalog?

Thanks,

Gopi .

0 Kudos

'Hi Gopi,

I believe you know the structure name at runtime.You use the following function module to create catalog dynamically at runtime.Hope it will solve your problem

call function 'LVC_FIELDCATALOG_MERGE'

exporting

i_structure_name = 'Structurename'

changing

ct_fieldcat = dyn_catalog

exceptions

inconsistent_interface = 1

program_error = 2

others = 3.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

Regds

Surendra