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: 

Problem in Checking and Incrementing while Looping

Former Member
0 Kudos
117

See I have this problem I have table A and Table B

Let's say for example,Table A has field customer of,

1

2

3

4

5

And table b has field customer of,

3

4

5

6

I am suppose to compare A with B if A has a customer number equal to one of the values in B. It has to increment until it reaches a number not available in B. so in table A 1 is ok. 2 as well. but 3 has to be incremented to 7. 4 is next from table A next available is 7, but im suppose to make the customer field unique so next increment is 8. How do I go about doing this. Having a hard time checking while looping

1 REPLY 1

Former Member
0 Kudos
69

Hi,

In the loop you can have the value in a seprate variable which you are updating.

e.g.

Sort A by customer number descending.

v_custno = a-custno. ( This will have value as 6 )

v_custno = v_custno + 1.

Loop at A.

read table b with key custno = A-custno.

if sy-subrc is initial.

A-custno = v_custno.

v_custno = v_custno + 1.

endif.

endloop.

Hope this logic shud meet your requirement.

Regards,

Lalit