Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 10548

How to avoid complex looping?

$
0
0

Hi Experts,

 

My Scenario is like below. How can I avoid loop inside the loop.

 

I have to derive my final internal table from my first internal table (Say IT_VBRK2).

 

My internal table IT_VBRK2 looks like below.

 

VBELN  PSTYV     POSNR  FKIMG      LFIMG

 

30001    TAN       10                13            0

30001    YB99      900001         13           4

30001    YB99      900002         13           4

30001    YB99      900003         13           5

 

30002   TAN        10                 1              0

30002   TAN         20                1              0

30002   TAN         30                1              0

30002   YB99       900001         1              1

30002   YB99       900002         1              1

30002    YB99      900003         1              1

 

I need to manipulate my Final internal table from this and the logic is that,

 

> The rows with TAN values have to be header lines and the corresponding YB99 have to be item values.

> The logic for deciding the line items for a particular TAN is that...

    Consider VBELN - 30001----- Here the FKIMG of TAN is 13. So it has to be compared with the YB99 of the same VBELN. So for the first line of YB99 it is 4. which is less than 13. 13 > 4. Next line 13 > 4 + 4     . Next line 13 = 4 + 4+ 5. So the loop has to end there. So our final internal table has to have values like.

30001    TAN       10                13            0

30001    YB99      900001         13           4

30001    YB99      900002         13           4

30001    YB99      900003         13           5                     (Same as that of IT_VBRK2)

 

Now consider VBELN = 30002. and first line.

30002   TAN        10                 1              0. So we have to take the first corresponding YB99 value of the same VBELN.

30002   YB99       900001         1              1.

So here the TAN line FKIMG is 1 and YB99 line LFIMG = 1 ...So matching ..

So iterate to next TAN line and next corresponding YB99 line.

30002   TAN         20                1              0

30002   YB99       900001         1              1     TAN-FKIMG = YB99-LFIMG...So iterate to next line.

 

Like wise I need my final internal table like below.

 

30001    TAN       10                13            0

30001    YB99      900001         13           4

30001    YB99      900002         13           4

30001    YB99      900003         13           5

 

30002   TAN        10                 1              0

30002   YB99       900001         1              1

30002   TAN         20                1              0

30002   YB99       900002         1              1

30002   TAN         30                1              0

30002    YB99      900003         1              1


I got the output. But I had to use Loop inside loop and it is quite time consuming. (Even for one record it takes so much of time.) Can anyone please guide me to simpler solution. Here I am also attaching the psedo code. (The LOOP statements).








Viewing all articles
Browse latest Browse all 10548

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>