Application Development and Automation 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: 
Read only

Master Data table update with Abap

Former Member
0 Likes
1,052

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
Read only

Former Member
0 Likes
997

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
Read only

jan_dahl
Participant
0 Likes
997

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.

Read only

Former Member
0 Likes
998

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.

Read only

0 Likes
997

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:

Read only

Former Member
0 Likes
997

Thanks a lot guys.

Amine