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: 

Master Data table update with Abap

amine_lamkaissi
Active Contributor
0 Kudos
133

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos
78

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.

4 REPLIES 4

jan_dahl
Explorer
0 Kudos
78

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.

Former Member
0 Kudos
79

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.

0 Kudos
78

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:

amine_lamkaissi
Active Contributor
0 Kudos
78

Thanks a lot guys.

Amine