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

moving data to final internal table

Former Member
0 Likes
1,183

hi friends,

I have two internal tables

Itab1 with fields A and B with data

Itab2 with fields C and D with data

I want to move data from itab1 and itab2 to finalitab where the finalitab fields are A B C and D

Pls code the following.

Thanx in advance.

Pravesh.

1 ACCEPTED SOLUTION
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,151

Hi,

You need a common field in tables itab1 and itab2.Then only,it will be meaningful to move the entries to finalitab.

loop at itab1 into wa1.

move-corresponding wa1 into wa_final.

loop at itab2 into wa2 where a = wa2-a.

move-corresponding wa2 into wa-final.

endloop.

append wa_final to finalitab.

endloop.

Kindly reward points by clicking the star on the left of reply,if it helps.

Message was edited by: Jayanthi Jayaraman

Hi,

You need a common field in tables itab1 and itab2.Then only,it will be meaningful to move the entries to finalitab.

loop at itab1 into wa1.

move-corresponding wa1 into wa_final.

loop at itab2 into wa2 where a = wa2-a.

move-corresponding wa2 into wa-final.

endloop.

append wa_final to finalitab.

endloop.

Kindly reward points by clicking the star on the left of reply,if it helps.

Message was edited by: Jayanthi Jayaraman

10 REPLIES 10
Read only

Former Member
0 Likes
1,151

U HAVE TO MAKE ANY RELATIONSHIP B/W ITAB1 AND ITAB2.

OTHERWISE JUST APPEND INDIVIDULAL TABLE INTO ITAB_FINAL.

EX-

itab have. field a,b,c.

itab2 have field c,d.

it is . becoz there is one field a which is common in both.

Read only

eddy_declercq
Active Contributor
0 Likes
1,151

Hi,

It doesn't seem that there is a common key for both tables. How do you want to join them? What do you want to happen when table 1 hasn't the same amount of records as table 2?

Eddy

PS.

Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.

Spread the wor(l)d!

Read only

Former Member
0 Likes
1,151

U can do this,but i think u are not clear as without key fields why do u want to move.

U can do like this,

loop at itab1.

move itab1 to final itab.

endloop.

loop at itab2.

move itab2 to final itab.

modify final itab.

endloop.

Make ur self clear and let me know if u face any problem

Regards

Read only

dani_mn
Active Contributor
0 Likes
1,151

HI,

there should be some matching field in itab1 and itab2 on which you transfer to final itab.

try like this.

LOOP AT itab1.

READ table itab2 index = sy-tabix.

IF sy-subrc = 0.

final_itab-A = itab1-A.

final_itab-B = itab1-B.

final_itab-C = itab2-C.

final_itab-D = itab2-D.

APPEND final_itab.

ENDIF.

ENDLOOP.

Regards,

Read only

Former Member
0 Likes
1,151

hi friends,

I have two internal tables

Itab1 with fields A and B with data

Itab2 with fields A and C with data

I want to move data from itab1 and itab2 to finalitab where the finalitab fields are A B and C.

Pls code the following.

Thanx in advance.

Pravesh.

Read only

0 Likes
1,151
sort itab1.
sort itab2.
itab_final[] = itab1[].
loop at itab_final.
reab table itab2 binary search with key a = itab_final-a.
itab_final-c = itab2-c.
modify itab_final.
endloop.
Read only

0 Likes
1,151

HI,

try the following code.

it will do you want.

<b>

LOOP AT itab1.

READ table itab2 with key  A = itab1-A.
IF sy-subrc = 0.
final_itab-A = itab1-A.
final_itab-B = itab1-B.
final_itab-C = itab2-C.
APPEND final_itab.
ENDIF.

ENDLOOP.

</b>

Regards,

Read only

0 Likes
1,151

u can do like this.

loop at itab1.

move itab1 to itab3.

loop at itab2 where a = itab1-a.

move itab2 to itab3.

endloop.

append itab3.

clear itab3.

endloop.

check and let me know if u face any problem.

Regards

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,152

Hi,

You need a common field in tables itab1 and itab2.Then only,it will be meaningful to move the entries to finalitab.

loop at itab1 into wa1.

move-corresponding wa1 into wa_final.

loop at itab2 into wa2 where a = wa2-a.

move-corresponding wa2 into wa-final.

endloop.

append wa_final to finalitab.

endloop.

Kindly reward points by clicking the star on the left of reply,if it helps.

Message was edited by: Jayanthi Jayaraman

Read only

Former Member
0 Likes
1,151

Hi Parvez,

Inorder to do that there should be one field in common between ITAB1 and ITAB2. Lets assume the field E is common between two tables. Then :

loop at itab1.

itabfinal-a = itab1-a.

itabfinal-b = itab1-b.

read table itab2 into watab2 with key e = itab1-e.

if sy-subrc eq 0.

itabfinal-c = watab2-c.

itabfinal-d = watab2-d.

endif.

append itabfinal.

endloop.

Best regards,

Prashant