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: 

DO ..... ENDDO

Former Member
0 Kudos

i am using Do enddo to check 40 fields lga01 lga02 lga03 in any one of these 40 fields if i found any value which statisfies my condition i need to pick the value and come out of this loop.if no value present in do endo loop then i need to display a message in the report value not found

8 REPLIES 8

Former Member
0 Kudos

Hi,

You can use EXIT command for it.

Syntax

DO 40 times.

(Value check operation)


IF (Value satisfied)
   
  (Store value to global variable)
  EXIT.

ELSEIF SY_INDEX EQ 40.
  
   (Print the message).

ENDIF.

ENDDO.

Regards,

anirban

Former Member
0 Kudos

Hi Sachin,

Try the following:

data: w_temp type i.
  
Do 40 times.
   if <condition>
    w_temp = w_temp + 1.
    w_value = value.
   stop.
  endif.
enddo.

if  w_temp > 1.
message 'Not Found' Type I.
endif.

Hope this helps you.

Regards,

Chandra Sekhar

Former Member
0 Kudos

Use

DO.

if field1 eq something.

EXIT.

Else.

CONTINUE.

Endif.

if field2.

if field40 eq something.

EXIT.

else.

Message.

Endif.

ENDDO.

Regards

Kannaiah

Former Member
0 Kudos

Hi Sachin,

You can try something like as given below :

DO.

IF <condition> = lga01 or ... = lga02  or .. lga03 .

   ........
  EXIT.

ELSEIF counter = 40.
message .................

 EXIT.
ENDIF.
 counter = counter + 1.
ENDDO.

With luck,

Pritam.

Former Member
0 Kudos

Hi,

I think following code will be useful to you.

DATA: g_lgart TYPE t512t-lgart.

DO 40 TIMES VARYING g_lgart

FROM p0008-lga01

NEXT p0008-lga02.

*condition on g_lgart

ENDDO.

0 Kudos

Hi,

DO.. VARYING will help you resolve the issue.

Check the F1 help for the same.

Try the code given below.

Regards,

Wajid Hussain

  • * * * *

    • assuming p0008 has data

DATA: g_lgart TYPE t512t-lgart,

v_flag TYPE c.

DO 40 TIMES VARYING g_lgart

FROM p0008-lga01

NEXT p0008-lga02.

  • IF condition satisfied.

  • v_flag = 'X'.

  • EXIT.

  • ENDIF.

ENDDO.

IF NOT v_flag IS INITIAL.

WRITE: / g_lgart.

ENDIF.

Former Member
0 Kudos

Hi Sachin

You can try like this. I think this will work.

DATA: i TYPE i VALUE 0,

j TYPE i VALUE 0.

DO 40 TIMES.

IF i GT 100.

j = 1.

EXIT.

ENDIF.

ENDDO.

IF j NE 1.

MESSAGE 'not found' TYPE 'I'.

ENDIF.

Former Member
0 Kudos

Hi Sachin,

Try this code :

DO 40 TIMES.

  IF lg01 = <value>.

    w_value = <value>.  

  ELSEIF lg02 = <value>.

    w_value = <value>.
    .......
    .......
    ......

  ENDIF.

ENDDO.

If lg01 satisfies the condition it fetches the value into w_value and so on.

So it will give you the required value at one point.

Regards,

Swapna.