Application Development and Automation 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: 
Read only

Creating Internal Table with different names at runtime

Former Member
0 Likes
1,057

Dear All,

Could anyone help me in the below topic:

I want to create Internal Table at runtime with different Names.

Name of the Internal Table should be decided at runtime. Type of all Internal Tables is same.

Ex. In loop, I want to create the as many Internal Tables as much times the loop will be executed.

TAB1

TAB2

TAB3

...

...

...

TABn

i.e.Name of the Internal Table will be concatenation of 'TAB' & <Loop Index>.

Please help ASAP.

Thanks in advance.

Best Regards,

Prasad

Dear All,

Could anyone help me in the below topic:

I want to create Internal Table at runtime with different Names.

Name of the Internal Table should be decided at runtime. Type of all Internal Tables is same.

Ex. In loop, I want to create the as many Internal Tables as much times the loop will be executed.

TAB1

TAB2

TAB3

...

...

...

TABn

i.e.Name of the Internal Table will be concatenation of 'TAB' & <Loop Index>.

Please help ASAP.

Thanks in advance.

Best Regards,

Prasad

4 REPLIES 4
Read only

Former Member
0 Likes
684

Hi,

check the code below:

DATA: d_ref TYPE REF TO data,

d_ref2 TYPE REF TO data,

i_alv_cat TYPE TABLE OF lvc_s_fcat,

ls_alv_cat LIKE LINE OF i_alv_cat.

TYPES: tabname LIKE dcobjdef-name ,

fieldname LIKE dcobjdef-name,

desc LIKE dntab-fieldtext.

PARAMETER: p_tablen TYPE tabname. -


> Input table field

DATA: BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE dntab.

DATA: END OF itab.

FIELD-SYMBOLS : <f_fs> TYPE table,

<f_fs1> TYPE table,

<f_fs2> TYPE ANY,

<f_fs3> TYPE ANY,

<f_fs4> type any,

<f_field> TYPE ANY.

REFRESH itab.

CALL FUNCTION 'NAMETAB_GET' -


> Fetches the fields

EXPORTING

langu = sy-langu

tabname = p_tablen

TABLES

nametab = itab

EXCEPTIONS

no_texts_found = 1.

LOOP AT itab .

ls_alv_cat-fieldname = itab-fieldname.

ls_alv_cat-ref_table = p_tablen.

ls_alv_cat-ref_field = itab-fieldname.

ls_alv_cat-seltext = itab-fieldtext.

ls_alv_cat-reptext = itab-fieldtext.

APPEND ls_alv_cat TO i_alv_cat.

ENDLOOP.

internal table build

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = i_alv_cat

IMPORTING

ep_table = d_ref.

ASSIGN d_ref->* TO <f_fs>. -


> Dynamic table creation with fields of the table

DATA: l_field TYPE fieldname,

l_field1 type fieldname.

SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <f_fs>.

Fetching of the data from the table

LOOP AT <f_fs> ASSIGNING <f_fs2>.

Here u can check the validations and process

ASSIGN COMPONENT 2 OF STRUCTURE <f_fs2> TO <f_fs3>.

ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.

IF sy-subrc = 0.

MOVE <f_fs3> TO l_field.

MOVE <f_fs4> TO l_field1.

WRITE:/1 l_field(20),

22 l_field1(10).

ENDIF.

ENDLOOP.

Regards

Kannaiah

Read only

Former Member
0 Likes
684

Many thanks for the reply.

But, here Internal Table will be created with the same name at each time or with different names.

And can I decide the NAME of Internal Table (& not Transperent Table), as I explaied in my query?

Thanks in advance.

Best Regards,

Prasad

Read only

0 Likes
684

Here the structure of the internal table will be created dynamically, it will create internal table header based on the name what you have given inthe input.

Regards

Kannaiah

Read only

Former Member
0 Likes
684

No, my table type is same for all tables.

So, it will not work my my requirement as Internal tables will be created with same name.

Thanks in advance.

Kind Regards,

Prasad