Application Development and Automation 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: 
Read only

read statement

Former Member
0 Likes
723

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

6 REPLIES 6
Read only

former_member195383
Active Contributor
0 Likes
655

LOOP AT lt_itab into wa_itab

where field1 EQ 'kna1'

And field2 EQ 'zcc1.

raise error message

exit.

Endloop

Read only

0 Likes
655

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

Read only

0 Likes
655

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.

Read only

0 Likes
655

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?

Read only

0 Likes
655

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.

Read only

0 Likes
655

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.