2014 Feb 11 3:33 PM
Hi experts,
I have a master data table as follwing (simplified version)
Field1 | Field2 | Field3 |
A | B | Y |
A | B | Y |
A | E | Z |
A | E | Z |
A | E | Z |
A | M | V |
I need to update field3 of the master data as following:
-The same combination of field1 and Field2 need to have the field3 filled only one time, so what I expect at the end of treatment is the following:
Field1 | Field2 | Field3 |
A | B | Y |
A | B | |
A | E | Z |
A | E | |
A | E | |
A | M | V |
To do so, I thought about creating a program with the following logic:
Sort itable by Field1 Field2.
Loop at itable into wa.
Concatenate wa-field1 wa-field2 into var1
If wa-field3 is not initial.
Concatenate wa-field1 wa-field2 into var2.
Endif.
If var1 ne var2.
Clear wa-field3.
Endif.
Endloop.
What do you think? Are they any simple ways to do it.
Thanks for your support.
Amine
2014 Feb 11 4:05 PM
Hi Amine.
May be you can use field-symbols:
SORT itable BY field1 field2.
LOOP AT itable ASSIGNING <wa>.
CONCATENATE <wa>-field1 <wa>-field2
INTO var1.
IF var1 EQ var2. "Only if the current record is the same as above, field3 is cleared
<wa>-field3 = ''.
ENDIF.
MOVE var1 TO var2.
ENDLOOP.
2014 Feb 11 4:01 PM
This is a perfect case to use 'at' in loops.
loop table1 into wa.
at new field2.
CONTINUE.
endat.
wa-field3 = space.
MODIFY table1 from wa.
ENDLOOP.
2014 Feb 11 4:05 PM
Hi Amine.
May be you can use field-symbols:
SORT itable BY field1 field2.
LOOP AT itable ASSIGNING <wa>.
CONCATENATE <wa>-field1 <wa>-field2
INTO var1.
IF var1 EQ var2. "Only if the current record is the same as above, field3 is cleared
<wa>-field3 = ''.
ENDIF.
MOVE var1 TO var2.
ENDLOOP.
2014 Feb 12 9:39 AM
Yes, using field symbols makes it even more easy. I realy shuld use them more often. Thanks Renzo.
I checked my coding and changed it:
SORT itable BY field1 field2.
LOOP AT itable ASSIGNING <wa>.
AT NEW field2.
CONTINUE. " Skip first accurence of new field2
ENDAT.
<wa>-field3 = space.
ENDLOOP.
Result:
2014 Feb 12 1:58 PM