‎2007 May 17 4:12 PM
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.
‎2007 May 17 4:25 PM
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
‎2007 May 17 4:13 PM
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.
‎2007 May 17 4:15 PM
Hi saritha,
1.
Loop at ITAB1.
MOVE-CORRESPONDING ITAB1 TO ITAB2.
APPEND ITAB2.
ENDLOOP.
regards,
amit m.
‎2007 May 17 4:17 PM
‎2007 May 17 4:17 PM
hi vinni,
wow your code looks super,
but does that really work, are you sure.
and also thank you very much for suggestion.
‎2007 May 17 4:23 PM
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.
‎2007 May 17 4:17 PM
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.
‎2007 May 17 4:18 PM
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.
‎2007 May 17 4:19 PM
Hi,
loop at itab1.
MOVE-CORRESPONDING itab1 TO itab2.
append itab2.
clear itab2.
endloop.
Regards,
Azaz Ali.
‎2007 May 17 4:20 PM
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>
‎2007 May 17 4:25 PM
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