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: 

Question about SY-SUBRC

Former Member
0 Kudos

Hi Experts,

Can anyone clear my doubt that is SY-SUBRC works inside the Nested loop or loop statement or not? If not Why?

Thanks a lot in advance..

14 REPLIES 14

Former Member
0 Kudos

search SCN

it works

Former Member
0 Kudos

hi,

Yes it works.

Regards,

Tarun

Former Member
0 Kudos

Hi,

Sy-subrc will work in loop also

thanks

Gowri Sankar

Former Member
0 Kudos

hi,

Please check this link for all queries on SY-SUBRC

https://www.sdn.sap.com/irj/sdn/wiki

Former Member
0 Kudos

Hi Moni,

Yes, It works inside the loop also.

Sy-subrc check whether an ABAP statement is succesful or not.

Executing a loop itself means that we are processing the correct and valid records. Then where is the issue of checking sy-subrc value, It will always be equal to 0 (zero).

Regards,

Nitin.

Former Member
0 Kudos

But in my code it is not working.. I have placed a nested loop and was counting if SY-SUBRC = 0 then it should do something. But its not checking the value if it is equal to 0 but giving me the value of sy-subrc as 4.??

0 Kudos

if check fails it will be 4 otherwise it will be 0

0 Kudos

but my condition is matching with the criteria but inspite of this sy-subrc = 4. I was checking it in debugging, sy-subrc should be = 0 with my records. But it is not

0 Kudos

Hi Moni,

Can you copy the part of code in your case?

starting from LOOP AT.... to ENDLOOP. ?

Then we can help better

Cheers,

Kothand

Former Member
0 Kudos

Hi Moni,

SY-SUBRC cannot be used for Counting.

For that you need to declare separate variable and then

ADD 1 TO counter.

Cheers,

Kothand

Former Member
0 Kudos

hii

sy-subrc can also check whether an ABAP statement is succesful or not..you can use it with READ statament.

regards

twinkal

Former Member
0 Kudos

Hi Moni,

If it is showing you value 4 for sy-subrc in nested loop,

It means there is no record satisfying your WHERE condition for that loop.

Thats why it must be showing 4.

Regards,

Nitin.

Former Member
0 Kudos

Hi,

Can you please show us your code so that we can analyse where the problem is .

Regards,

Nitin.

Former Member
0 Kudos

Hi,

Its works in loop or outside loop alos

WHEN SELECT QUERY EXECUTE THAN VALUE OF SY-SUBARC = 0 OTHER WISE ITS 4

WITH EXAMPLE

DATA : ITAB LIKE MARA OCCURS 0 WITH HEADER LINE.

SELECT * FROM MARA INTO TABLE ITAB.

IF SY-SUBRC = 0.

WRITE : 'EXECUTE'.

ENDIF.

LOOP AT ITAB.

IF SY-SUBRC = 0.

WRITE 😕 ITAB-MATNR.

ENDIF.

ENDLOOP.