03-12-2010 9:12 AM
Hello
There are two tables : table1 with fields F1 , F2 ... and table2 with fields ZF1, ZF2.....
Fields types are the same and Z is the only difference.
I need to move data from table1 to table2. Because each table contains of more than 50 fields I dont want to use direct assignement.
table1-F1 = table2-ZF1
Is there any intelligent way to move data from table1 to table2?
03-12-2010 9:38 AM
Can you try something like this using ASSIGN COMPONENT statement:
DATA: V_INDEX TYPE SY-INDEX.
FIELD-SYMBOLS: <VAL> TYPE ANY, <VAL1> TYPE ANY.
LOOP AT ITAB ASSIGNING WA.
DO.
V_INDEX = SY-INDEX.
ASSIGN COMPONENT V_INDEX OF STRUCTURE WA TO <VAL>.
IF SY-SUBRC = 0.
ASSIGN COMPONENT V_INDEX OF STRUCTURE WA1 TO <VAL1>.
IF SY-SUBRC = 0.
<VAL1> = <VAL>.
ENDIF.
ELSE.
EXIT. "Exit from the DO ... ENDDO loop
ENDIF.
ENDDO.
APPEND WA1 TO ITAB1.
ENDLOOP.
BR,
Suhas
PS: I am assuming you have the fields in sequence as well. If they are not in sequence you have to use RTTS to get the structure of the table ITAB & add 'Z' to the field name & proceed.
03-12-2010 9:15 AM
Hi,
Check the data type(CHAR, NUMC) for the fields in both table. If the data type is same for the both the tablethen you can do it below the way.
ITAB1 [ ] = ITAB2 [ ] .
Edited by: Thiruibm on Mar 12, 2010 10:16 AM
03-12-2010 9:16 AM
hi
You can use Move corresponding statement.More details press f1 on the statement
if the contenet is different
loop at itab into wa.
move corrspoding fields of itab1 to itab2.
append itab2.
endloop.
if the content is same
itab1 = itab2 .
You can use Field symbol.
03-12-2010 9:22 AM
Direct assignment is the best way.
But if the data types of both the fields are same then
try
append lines of it1 to it2.
03-12-2010 9:27 AM
Hi,
MOVE-CORRESPONDING won't work here as field names are different.
Direct assignment holds good if both the tables exactly has the same structure including data type, length and the order of the fields.
If at least one of the above differs then loop and use field by field assignment.
Thanks,
Vinod.
03-12-2010 9:38 AM
Can you try something like this using ASSIGN COMPONENT statement:
DATA: V_INDEX TYPE SY-INDEX.
FIELD-SYMBOLS: <VAL> TYPE ANY, <VAL1> TYPE ANY.
LOOP AT ITAB ASSIGNING WA.
DO.
V_INDEX = SY-INDEX.
ASSIGN COMPONENT V_INDEX OF STRUCTURE WA TO <VAL>.
IF SY-SUBRC = 0.
ASSIGN COMPONENT V_INDEX OF STRUCTURE WA1 TO <VAL1>.
IF SY-SUBRC = 0.
<VAL1> = <VAL>.
ENDIF.
ELSE.
EXIT. "Exit from the DO ... ENDDO loop
ENDIF.
ENDDO.
APPEND WA1 TO ITAB1.
ENDLOOP.
BR,
Suhas
PS: I am assuming you have the fields in sequence as well. If they are not in sequence you have to use RTTS to get the structure of the table ITAB & add 'Z' to the field name & proceed.