07-27-2010 2:57 PM
I have two tables with similar fields. Let's say Table 1 (T1) has fields Customer, A, B and C. Table 2 (T2) has fields Customer0002, A0002, B0002 and C0002. For each customer (each record) I want to check whether there is any difference in field A and A0002 or B and B0002 or C and C0002. If there is a difference between any of these pairs of fields then I will update that customer's record. Currently I have a piece of code
DATA: ls_source TYPE y_source_fields,
ls_target TYPE y_target_fields.
LOOP AT it_source INTO ls_source.
if not ( ls_source-A = ls_source-A0002 ).
MOVE-CORRESPONDING ls_source TO ls_target.
APPEND ls_target TO et_target.
endif.
ENDLOOP.
This checks for the difference between one pair - A and A0002. How can I make it check 3 pairs and update when any of them have differences?
07-27-2010 3:15 PM
Hello Khaled
Why don't you add B and B0002 - C and C0002 fields into your if declaration?
LOOP AT it_source INTO ls_source.
if not (
ls_source-A = ls_source-A0002 and
ls_source-B = ls_source-B0002 and
ls_source-C = ls_source-C0002
).
MOVE-CORRESPONDING ls_source TO ls_target.
APPEND ls_target TO et_target.
endif.
ENDLOOP.
I think you have more than 3 fields and the count of these fields are dynamic right?
Do you about the ASSIGN COMPONENT x OF STRUCTURE y TO <field_symbol>. usage?
Can you explain your need in detail please.
Edited by: Bulent Balci on Jul 27, 2010 4:18 PM
07-27-2010 3:15 PM
Hello Khaled
Why don't you add B and B0002 - C and C0002 fields into your if declaration?
LOOP AT it_source INTO ls_source.
if not (
ls_source-A = ls_source-A0002 and
ls_source-B = ls_source-B0002 and
ls_source-C = ls_source-C0002
).
MOVE-CORRESPONDING ls_source TO ls_target.
APPEND ls_target TO et_target.
endif.
ENDLOOP.
I think you have more than 3 fields and the count of these fields are dynamic right?
Do you about the ASSIGN COMPONENT x OF STRUCTURE y TO <field_symbol>. usage?
Can you explain your need in detail please.
Edited by: Bulent Balci on Jul 27, 2010 4:18 PM
07-27-2010 5:48 PM
I changed the AND to an OR statement, since I wanted to add the record if any of the fields were different, not just if all of them were different, and this works. Thanks - points assigned!