Application Development 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: 

itab move corresponding

Former Member
0 Kudos
181

hello abap gurus,

in my requirement,

all the records in ITAB1 need to be moved to ITAB2 where

both have a common key field which should match.

Note: ITAB1 and ITAB2 have only few common fields. ITAB2 is completely empty.

can someone tell the best way of coding this.

thank you.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
95

Hi Saritha,

Do not use MOVE-CORRESPONDING , we need to use MOVE statment,

if you look at the Performance side, then we need to use only MOVE statment .

so use like this

Loop at ITAB1.
ITAB2-<field1> = ITAB1-<field1>.
ITAB2-<field2> = ITAB1-<field2>.
-----------------------------
-----------------------------
-----------------------------
APPEND ITAB2.
ENDLOOP.

Regards

Sudheer

10 REPLIES 10

former_member191977
Contributor
0 Kudos
95

Hi,

Loop at itab1.

populate itab2.

append itab2.

clear itab2.

endloop.

if itab1 and itab2 are of the same structure you cud have done like itab2[] = itab1[]. which moves everything but since they are of different structure i prefer to use the loop.

Former Member
0 Kudos
95

Hi saritha,

1.

Loop at ITAB1.

MOVE-CORRESPONDING ITAB1 TO ITAB2.

APPEND ITAB2.

ENDLOOP.

regards,

amit m.

0 Kudos
95

thanks amit,

i will try yours too.

Former Member
0 Kudos
95

hi vinni,

wow your code looks super,

but does that really work, are you sure.

and also thank you very much for suggestion.

0 Kudos
95

Hi Saritha,

I could have suggested move corresponding fields of itab1 to itab2 also but if you have too many fields in itab1 i feel assigning the fields individually is better.

Btw, my first solution works well. I am sure about it. Why did u get such a doubt ? Did u face any problem. When i said populate itab2. you have to assign field by field like itab2-x = itab1-x and so on.

Reward with points if it helps.

Thanks.

Former Member
0 Kudos
95

Loop at ITAB1.

MOVE-CORRESPONDING ITAB1 TO ITAB2.

APPEND ITAB2.

ENDLOOP.

or....

Loop at ITAB1.

ITAB2-<field1> = ITAB1-<field1>.

ITAB2-<field2> = ITAB1-<field2>.

so.....on

APPEND ITAB2.

ENDLOOP.

Former Member
0 Kudos
95

check out this example.would be helpfull

DATA: BEGIN OF INT_TABLE OCCURS 10,

WORD(10),

NUMBER TYPE I,

INDEX LIKE SY-INDEX,

END OF INT_TABLE,

BEGIN OF RECORD,

NAME(10) VALUE 'not WORD',

NUMBER TYPE I,

INDEX(20),

END OF RECORD.

...

MOVE-CORRESPONDING INT_TABLE TO RECORD.

This MOVE-CORRESPONDING statement is equivalent to both the following statements:

MOVE INT_TABLE-NUMBER TO RECORD-NUMBER.

MOVE INT_TABLE-INDEX TO RECORD-INDEX.

Former Member
0 Kudos
95

Hi,

loop at itab1.

MOVE-CORRESPONDING itab1 TO itab2.

append itab2.

clear itab2.

endloop.

Regards,

Azaz Ali.

Former Member
0 Kudos
95

Hi,

LOOP AT ITAB1 INTO WA1.

CLEAR WA2.

*Assign the common fields

MOVE WA1-Field1 TO WA2-Field1.

APPEND WA2 TO ITAB2.

ENDLOOP.

Regards,

Ranjit Thakur.

<b>Please Mark The Helpful Answer.</b>

Former Member
0 Kudos
96

Hi Saritha,

Do not use MOVE-CORRESPONDING , we need to use MOVE statment,

if you look at the Performance side, then we need to use only MOVE statment .

so use like this

Loop at ITAB1.
ITAB2-<field1> = ITAB1-<field1>.
ITAB2-<field2> = ITAB1-<field2>.
-----------------------------
-----------------------------
-----------------------------
APPEND ITAB2.
ENDLOOP.

Regards

Sudheer