2008 May 02 10:56 AM
How to exit from a loop. for eg
C = sy-tabix.
LOOP AT IT_GRAPH1.
D = SY-TABIX.
IF D GT C.
EXIT.
ENDIF.
<cond>
I want that when D becomes greater then C then it should exit the whole loop processing.
But this code is not working even if D becomes greater then C still the loop processing continue.
Please Help.
How to exit from a loop. for eg
C = sy-tabix.
LOOP AT IT_GRAPH1.
D = SY-TABIX.
IF D GT C.
EXIT.
ENDIF.
<cond>
I want that when D becomes greater then C then it should exit the whole loop processing.
But this code is not working even if D becomes greater then C still the loop processing continue.
Please Help.
2008 May 02 10:58 AM
2008 May 02 10:59 AM
hi priya
instead of if statement try once check statment
it will work
thanks and regards
snehi chouhan
2008 May 02 11:01 AM
hi
assign some value to varible C not Sy-tabix.
or try with condition operator GE.
this will work. plz reward me if it helps out.
regars,
munvar.
2008 May 02 11:02 AM
Hi,
Check the below logic.
data: c like sy-tabix, d like c.
data: begin of itab occurs 0,
num type i,
end of itab.
do 5 times.
itab-num = sy-index.
append itab.
enddo.
C = 2 ."sy-tabix.
LOOP AT ITAB.
D = SY-TABIX.
IF D GT C.
EXIT.
ENDIF.
write:/ itab-num.
ENDLOOP.
2008 May 02 11:12 AM
C = sy-tabix.
LOOP AT IT_GRAPH1.
D = SY-TABIX.
IF D GT C.
EXIT.
ENDIF.
IF IT_GRAPH1-type = 'DO'.
M = M + 1.
ELSEIF IT_GRAPH1-type = 'ENDDO'.
N = N + 1.
ELSEIF IT_GRAPH1-type = 'LOOP'.
L = L + 1.
ELSEIF IT_GRAPH1-type = 'ENDLOOP'.
E = E + 1.
ELSEIF IT_GRAPH1-type = 'IF'.
I = I + 1.
ELSEIF IT_GRAPH1-type = 'ENDIF'.
P = P + 1.
ELSEIF IT_GRAPH1-type = 'CASE'.
R = R + 1.
ELSEIF IT_GRAPH1-type = 'ENDCASE'.
S = S + 1.
ENDIF.
ENDLOOP.
HII THIS IS MY CODE....the given logic is not working here
2008 May 02 11:27 AM
I can't see anything wrong with that code. 'EXIT' will exit a loop. Are you looping within a loop so that C is reset each time? It is worth break-pointing and checking what happens and what values are being set.
2008 May 02 11:40 AM
Firstly Do not Use the variable names as C or D , N as they are the types of declaration in ABAP as well ,
Change the names and try your Code ,, Logically should work .
Or else .
Instead of
IF D GT C.
EXIT.
ENDIF.
use ,
While D_temp LT C_temp .
IF IT_GRAPH1-type = 'DO'.
M = M + 1.
ELSEIF IT_GRAPH1-type = 'ENDDO'.
N = N + 1.
ELSEIF IT_GRAPH1-type = 'LOOP'.
L = L + 1.
ELSEIF IT_GRAPH1-type = 'ENDLOOP'.
E = E + 1.
ELSEIF IT_GRAPH1-type = 'IF'.
I = I + 1.
ELSEIF IT_GRAPH1-type = 'ENDIF'.
P = P + 1.
ELSEIF IT_GRAPH1-type = 'CASE'.
R = R + 1.
ELSEIF IT_GRAPH1-type = 'ENDCASE'.
S = S + 1.
ENDIF.
ENDWHILE .
regards
Badari,
2008 May 02 11:57 AM
hi,
try this code
C = sy-tabix.
LOOP AT IT_GRAPH1 TO C.
<processing goes here>
ENDLOOP.
or this one
C = sy-tabix.
LOOP AT IT_GRAPH1.
D = SY-TABIX.
IF D GT C.
EXIT FROM STEP-LOOP.
ENDIF.
ENDLOOP.
regards,
Peter
2008 May 02 1:25 PM
Hi Priya,
at first glance your code should work. The only thing I can think of is something in the typing of variables C and D that make the comparison not work.
Can you give us your definition of C and D?
Greetings,
Gert.
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |