‎2009 Oct 07 12:59 PM
HI
I have a requirement
i am looping to a internal table
LOOP AT lt_itab into wa_itab
where field1 EQ 'kna1'
And field2 EQ 'zcc1;
Endloop
now i want to check if the entry exits then raise error message and exit...
what is the posible way to check for sy-subrc...inside loop
here the table name and field name are not primary key
regards
arora
‎2009 Oct 07 1:08 PM
LOOP AT lt_itab into wa_itab
where field1 EQ 'kna1'
And field2 EQ 'zcc1.
raise error message
exit.
Endloop
‎2009 Oct 07 1:10 PM
hi Rudra
i suppose i didnt made myself clear as if inside the loop in th etable i just want to chck if the entry exist then code
for if condition say if sy-subrc = 0
flag = checked
else.
exit.
endif.
so my qustion was how to chck for sysubrc inside a loop
now i want to check if the entry exits then raise error message and exit...
what is the posible way to check for sy-subrc...inside loop
‎2009 Oct 07 1:30 PM
hi..
I hope your requirement is to show error message if there is no entry in the table, based on the conditions,
that you have given in the loop statements.
If there is no entry in the table, the control will not go into the loop.
So write the following logic, which may help.
Declare a flag say, wf_flag.
Loop at itab......
wf_flag = 'X' .
exit.
endloop.
if wf_flag NE 'X' .
write error message.
endif.
Hope it solves your p[roblem.
‎2009 Oct 07 2:03 PM
hi rudra
here is my code
if not it_itab is initial.
LOOP AT lt_itab into wa_itabe
where field1 EQ 'kna1'
And field2 EQ 'zc3'.
Iflag= 'X'.
ENDLOOP.
IF I_pricomp_flag is initial.
Exit.
ENDIF.
ENDIF.
now there is below code existing for the same now if i dont want that to execute so exit will come to the end of subroutine ? right?
‎2009 Oct 07 2:09 PM
If you just want to exit your subroutine if an entry is available in ITAB, you can use this:
LOOP AT itab INTO wa.
* SET a flag of some sort for returning to calling PERFORM.
ex_flag = 'X'.
RETURN.
ENDLOOP.
I hope I understood your requirement. If so, this would be the easiest solution to your problem.
‎2009 Oct 07 2:18 PM
this will do.
data:val1 type lt_itab-field1, "refer the field type here
val2 type lt_itab-field2.
val1 = 'kna1'.
val2 = 'zcc1'.
LOOP AT lt_itab into wa_itab where field1 EQ And field2 EQ .
exit.
Endloop.
if sy-subrc = 0.
message 'Entry Exists' type 'E'.
endif.
or
read table lt_itab with key field1 = val1 field2 = val2
transporting no fields.
if sy-subrc = 0.
error.
endif.