cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to start loop iteration from the beginning after meeting some condition within the loop

ABAPer_1631
Explorer
0 Kudos
596

Hello,

I need inputs on below scenario:

I have a changing parameter in the method of a Class which is table <ch_table_name> where I would like to process records in this table. The entries in the table are of same type with different data like, every 19 entries, type of data is same but values will be different.

I would like to delete data in this table if it meets the condition. suppose, continuously for couple of times if condition is satisfied.

I will delete these entries and loop iteration HAS to start from beginning to check data again. Is it possible, if Yes, How can I achieve this?

say, 

LOOP <ch_table_name> ASSIGNING <fs_> WHERE <condition>.

IF <cond>.

<logic to check entries and set index lv_start and lv_end to delete data>.

ELSE.

DELETE <ch_table_name> FROM lv_start TO lv_end.

<logic to start iteration from beginning> . ""=> How to handle this?

ENDIF.

ENDLOOP.

Thanks in Advance!!

Accepted Solutions (1)

Accepted Solutions (1)

RaymondGiuseppi
Active Contributor

Either find a logic that doesn't require a new loop (not enough information provided there, so I'm unable to understand your logic)

Else set a flag to indicate a new loop and exit current one

 

 

doitagain = abap_true.
WHILE doitagain = abap_true.
  doitagain = abap_false.
  LOOP AT <ch_table_name> ASSIGNING <fs> WHERE <condition>.
    " some logic triggers the do it again loop
    doitagain = abap_true.
	EXIT.
    " some other logic doesn't
  ENDLOOP.
ENDWHILE.

 

 

Numerous code variants are available, taking care not to trigger infinite loops.

 

ABAPer_1631
Explorer
0 Kudos

Hello @RaymondGiuseppi,

Thank you for your Inputs. this would help me to find proper solution to my problem statement..
It helps!

Answers (1)

Answers (1)

MBartsch71
Participant
0 Kudos

Hello,

for me personally it is bad practice to use changing parameters. Better is using importing and returning. Furthermore a delete statement is preferable over looping and deleting entries in the same time. When you use importing and returning parameters you can fill the returning table easy with the needed values.