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: 

Z is the only difference between list of fields

Former Member
0 Kudos

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?

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

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.

5 REPLIES 5

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

kesavadas_thekkillath
Active Contributor
0 Kudos

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.

vinod_vemuru2
Active Contributor
0 Kudos

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.

SuhaSaha
Advisor
Advisor
0 Kudos

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.