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

Two internal tables with different structures

Former Member
0 Likes
4,527

Hi Experts,

I Have two internal tables.

Table 1 structure:

Name

Age

Table 2 structure :

Name

age

branch

Now the table 1 has some 5 data's and table 2 is empty.

First i want to move that 5 data's from table 1 to table 2.

Then the branch field is same for all records. its stored in a separate field called 'Branch'.

finallay i need to move that branch to internal table 2 for all records.

So the Table 2 should has five records and each record should have the branch.Its like,

Name Age Branch

name1 10 ECE

name2 10 ECE

I didnt use with header line for both tables. In function module i declared as table parameter.

Please give me a logic.

Helps will be appreciated.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,948

hi,

Try this.

itab2 = itab1.

wa2-brach = 'ECE'. (wa2 is WA for ITab2)

Modify itab2 transporting branch from wa2.

Regards,

Komal

7 REPLIES 7
Read only

Former Member
0 Likes
1,948
itab2[] = itab1[].
Read only

Former Member
0 Likes
1,948

The logic is quite simple. Loop at the first table, inside that loop, loop through the branches appropiate for that name and age, and for each appropiate branch append a record in the second table.

Read only

Former Member
0 Likes
1,949

hi,

Try this.

itab2 = itab1.

wa2-brach = 'ECE'. (wa2 is WA for ITab2)

Modify itab2 transporting branch from wa2.

Regards,

Komal

Read only

Former Member
0 Likes
1,948

hi,

try this.


loop at itab1 into wa1.
read table itab2 into wa2.
wa2-name = wa1-name.
wa2-age = wa1-age.
append wa2 to itab2.
endloop.

clear wa1.
clear wa2.
loop at itab2 into wa2.
wa2-branch = 'ECE'.
modify itab2 transaporting wa2-branch.
endloop. 

regards,

sakshi

Read only

0 Likes
1,948

Dear Jain,

Since the second table is empty and we only move the data of first table to second table, in this case there is no need of read statement.

There is also no need of second loop because we can populate branch field in first loop itself.

Read only

Former Member
0 Likes
1,948

Since the structure of yur both internal table is different so you can't use ITAB1[] = ITAB2[] statements.

In this case you have to loop on first table then move data into second table and appned data into second table.

Declare work area for both table with like line of statement as follows

data: wa_itab1 like line of itab1,

wa_itab2 like line of itab2.

Loop at ita1 into wa_itab1.

wa_itab2-name = wa_itab1-name.

wa_itab2-age = wa_itab1-age.

wa_itab2-branch = 'ECE'.

append wa_itab to itab2.

clear wa_itab1, wa_itab2.

endloop.

Hope this will solve your problem.

Read only

Former Member
0 Likes
1,948

Thanks All.