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: 

How to use EXIT in a LOOP AT when the first condition is met?

walkerist
Participant
0 Kudos
299

Hi, I have a loop within a loop and I'm having problems in which the value of LFS_IT_LIPS is always constant because of the EXIT. Is there a way that when the condition inside the it_lips is met it will exit the loop but the LFS_IT_LIPS-VBELN will be refreshed? Because the LFS_IT_LIPS-VBELN is always at 800000123. I'm assuming that it will change.

LOOP AT it_vbap ASSIGNING FIELD-SYMBOLS (<lfs_it_vbap>).

LOOP AT it_lips ASSIGNING FIELD-SYMBOLS(<lfs_it_lips>).

"Conditions here

EXIT.

ENDLOOP.

ENDLOOP.

5 REPLIES 5

raymond_giuseppi
Active Contributor
0 Kudos
210

Since you didn't put a WHERE condition in the inner loop, I assume you should use a CONTINUE (next record) and not an EXIT (exit loop).
It seems that you are actually always reading the first record of the delivery items and immediately exiting the inner loop at each sales order item?

But you haven't provided enough information to be sure of your requirement, could you elaborate?

0 Kudos
210

raymond.giuseppi

Here's the code:

Internal tables that were populated via Select SQL statement:

it_vbap
-entries 12345, 12346, 12347, 12348
it_lips
-entries 9870, 0971, 0982
it_item_stock
it_for_delivery
-entries has both
LOOP AT it_vbap ASSIGNING FIELD-SYMBOL(<lfs_it_vbap>).
LOOP AT it_lips ASSINING FIELD-SYMBOL(<lfs_it_lips>).
****The logic inside the loop checks if the <LFS_IT_VBAP>-VBELN is in it_item_stock
****If yes, it should check if the <LFS_IT_LIPS>-VBELN is in it_for_delivery.
****When successfully checked, it should check for another pair of Sales Document and Delivery Document.
****Current situation: Sales Document 12345 has been checked, then the loop will proceed to check for delivery document 9870.
****However, upon checking the delivery document 9870 and sales doc 12345, only the value of LFS_IT_LIPS-VBELN will change.
****I was expecting that the loop will check the pair of sales doc of 12346 and delivery doc of 0971.
ENDLOOP.
ENDLOOP.

0 Kudos
210

the two loop are independent, the inner loop will read from 1st to last record of internal table.

  • If you want to process every delivery item vs every sales order item then use continue.
  • But there is a relation between lips and vbap, you could look for vbfa for the link between a SO item (previous) and the Delvery Item (next) that followed it, read data from vbfa and use a read table to identify lips record and use a where clause /or/ use LIPS-VGBEL = VBAP-VBELN and LIPS-VGPOS = VBAOP-POSNR in a where clause in inner loop

matt
Active Contributor
210

I'm fairly sure that we've pointed out the use of the "code" button in the question editor.

Try to use it.

walkerist
Participant
0 Kudos
210

Hi matthew.billingham thanks. I think my question is wrong as I'm looking on how to improve my code.

I want to loop LFS_IT_VBAP and LFS_IT_LIPS at the same time. Is it possible?

it_vbap
-entries 12345, 12346, 12347, 12348
it_lips
-entries 9870, 0971, 0982
it_item_stock
it_for_delivery
-entries has both
LOOP AT it_vbap ASSIGNING FIELD-SYMBOL(<lfs_it_vbap>).
LOOP AT it_lips ASSINING FIELD-SYMBOL(<lfs_it_lips>).
****The logic inside the loop checks if the <LFS_IT_VBAP>-VBELN is in it_item_stock
****If yes, it should check if the <LFS_IT_LIPS>-VBELN is in it_for_delivery.
****When successfully checked, it should check for another pair of Sales Document and Delivery Document.
****Current situation: Sales Document 12345 has been checked, then the loop will proceed to check for delivery document 9870.
****However, upon checking the delivery document 9870 and sales doc 12345, only the value of LFS_IT_LIPS-VBELN will change.
****I was expecting that the loop will check the pair of sales doc of 12346 and delivery doc of 0971.
ENDLOOP.
ENDLOOP.