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 more fields to the internal table dynamically.

Former Member
0 Likes
2,300

Hello Friends,

I need to add fields to the internal table dynamically.

Here is my situation.

begin of itab1 ,

material

material type

endof itab1.

begin of itab2 occurs 0,

material

material type

xxxxxxxx

xxxxxxxxx

xxxxxxx

xxxxxxxxx

endof itab2.

I am populating the data from mara to the above internal table work area itab1.

based on the itab1-material type, i need to add some more fields to the another internal table i.e itab2.

It will vary depends on the material type.

could you pls help me how to add some more fields dynamically to the already defined table.

I will appreciate, if you send the code.

plz help, its urgent.

Thanks in advance

5 REPLIES 5
Read only

naimesh_patel
Active Contributor
0 Likes
786

Instead of creating ITAB2 and than adding some fields to that, try to create ITAB2 dynamically.

You can use the Run time Type Service class like cl_abap_tabledescr to generate table dynamically.

Regards,

Naimesh Patel

Read only

0 Likes
786

Could you pls expalin clearly. If possible could you pls send me the code.

If anybody have different solution for this issue, please forward it.

This is very urgent.

Thanks in advance

Read only

Former Member
0 Likes
786

HI,

Find the code for dynamical internal table., which helps to increase the fields in the internal table dynamically.

REPORT ZTEST_R3.

FIELD-SYMBOLS: <L_TABLE> TYPE TABLE,

<L_LINE> TYPE ANY,

<L_FIELD> TYPE ANY.

DATA: IS_LVC_CAT TYPE LVC_S_FCAT,

IT_LVC_CAT TYPE LVC_T_FCAT.

DATA: NEW_TABLE TYPE REF TO DATA,

NEW_LINE TYPE REF TO DATA.

START-OF-SELECTION.

IS_LVC_CAT-FIELDNAME = 'KUNNR'.

APPEND IS_LVC_CAT TO IT_LVC_CAT.

IS_LVC_CAT-FIELDNAME = 'NAME1'.

APPEND IS_LVC_CAT TO IT_LVC_CAT.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = IT_LVC_CAT

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>.

DO 2 TIMES.

ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <L_LINE> TO <L_FIELD>.

<L_FIELD> = SY-INDEX.

ASSIGN COMPONENT 'NAME1' OF STRUCTURE <L_LINE> TO <L_FIELD>.

<L_FIELD> = 'A'.

INSERT <L_LINE> INTO TABLE <L_TABLE>.

ENDDO.

LOOP AT <L_TABLE> INTO <L_LINE>.

WRITE:/ <L_LINE>.

ENDLOOP.

READ TABLE <L_TABLE> INTO <L_LINE> INDEX 2.

<L_LINE>+10(2) = 'B'.

MODIFY <L_TABLE> FROM <L_LINE> INDEX 2.

LOOP AT <L_TABLE> INTO <L_LINE>.

WRITE:/ <L_LINE>.

ENDLOOP.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Jun 12, 2008 12:46 PM

Read only

0 Likes
786

Hi Ravi Kumar,

Half of my issue was solved with your solution.

If I declare the field symbols like below, it is considering all the field length only 10.

FIELD-SYMBOLS: <L_TABLE> TYPE TABLE,

<L_LINE> TYPE ANY,

<L_FIELD> TYPE ANY.

In my situation, the field length is more than 10. i.e 108.

Could you pls let me know, how to proceed/ declare if at all i want more than 10 characters length?

Any how Thanks a lot.

Regards

Raghu

Read only

0 Likes
786

Thanks a lot.

problem solved.