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

Adding fields to Internal table dynamically

Former Member
0 Likes
1,067

Hi All,

I have a internal table, in that i have 13 fields, i want to add some more fields to the internal table dynamically based on the conditions. The number of fields to be added to the internal table can be any number. Pls let me know how to do this.

Thanks,

Raju

4 REPLIES 4
Read only

Former Member
0 Likes
748

Refer below code :

DATA gv_ref TYPE REF TO data.

DATA gv_area TYPE REF TO data.

FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,

<fs_update> TYPE STANDARD TABLE,

<fs_data> TYPE ANY.

CREATE DATA gv_ref TYPE STANDARD TABLE OF (p_table).

CREATE DATA gv_area LIKE gv_ref.

ASSIGN gv_ref->* TO <fs_table>.

ASSIGN gv_ref->* TO <fs_update>.

ASSIGN gv_area->* TO <fs_data>.

Now, these field-symbols you can use as your internal tables and work areas.

P_TABLE is variable containg any database table name.

Read only

Former Member
0 Likes
748

Hi,

Consider your internal table as follows:-

Begin of itab,

f1,

f2,

f3,

till

f13,

Dynamic f1,

Dynamic f2,

Dynamic f3,

Dynamic f4,

and so on

end of itab

So basically you will have to make of the class CL_ALV_TABLE_CREATE and the method CREATE_DYNAMIC_TABLE.

Prepare a fieldcatalog table first.

Pass the 13 fields first with their details.

Then within a loop pass the dynamic fields.

Pass this fieldcatlog to the method and you will get your internal table.

Please check the demo program BCALV_TABLE_CREATE

Regards,

Ankur Parab

Read only

0 Likes
748

Hi Ankur,

Can you pls send the code, to takle my issue. In that example based on no of parameters i am getting the output list. But here in my case, i have to display the first 13 fileds in the table, and then based on some other conditions, i have to add some fields to my internal table and then display. Pls send the code for the same.

Prob :

in internal table i have 13 fields

f1

f2...

so on

f13.

Now based on some conditions, i have to append the fields in the internal table. pls send the code.

Thanks,

Raju

Read only

0 Likes
748

Hi,

You will not be able to add fields in the existing internal table.

But you will have to create a new internal table and add the new fields to it.

I will try to give an example code.

Regards,

Ankur Parab