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: 

Generate delta records by comparing multiple fields from two tables?

Former Member
0 Kudos

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?

1 ACCEPTED SOLUTION

bbalci
Contributor
0 Kudos

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

2 REPLIES 2

bbalci
Contributor
0 Kudos

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

Former Member
0 Kudos

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!