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: 

sy-subrc info req??

Former Member
0 Kudos

hi

I had seen many time inside loop,if I check the sy-subrc value,but i found it 4 many times inspite of having the records in loop.

IF it_final3[] IS NOT INITIAL.

LOOP AT it_final3.

IF p_doc-low NE 'NB'.

READ TABLE itab_1 WITH KEY banfn = it_final3-banfn.

ENDIF.

IF sy-subrc EQ '0'. -


>here in my loop records are there,but sy-subrc is coming 4.

gt_final2-banfn = it_final3-banfn.

gt_final2-bsart = it_final3-bsart.

gt_final2-badat = it_final3-badat.

gt_final2-werks = it_final3-werks.

gt_final2-udate1 = it_final3-udate1.

gt_final2-ekgrp = it_final3-ekgrp.

gt_final2-ebeln = it_final3-ebeln.

gt_final2-bnfpo = it_final3-bnfpo.

gt_final2-matnr = it_final3-matnr.

gt_final2-menge = it_final3-menge.

gt_final2-bsmng = it_final3-bsmng.

gt_final2-menge1 = it_final3-menge.

APPEND gt_final2.

CLEAR : it_final3.

ENDIF.

endloop.

endif.

here inspite of having records in my intab,this sy-subrc value is 4.

i had seen this prob many time.

plz tell me how it happens & what shd i keep in mind to avoid such cases.

regds.

10 REPLIES 10

Former Member
0 Kudos

hi vipin,

sy-subrc = 4...is coming for statement..

READ TABLE itab_1 WITH KEY banfn = it_final3-banfn.

it is not for loop.

better to assign sy-subrc of loop to other variable...and then read...

Former Member
0 Kudos

Hi ,

In this case ,

The sy-subrc value is 4 not because of the loop but because of the READ statement which doesnt read anything because the record do not match.

The READ statement also sets the value of sy-subrc.

Reward if helpful.

Regards.

Former Member
0 Kudos

Hi,

sy-subrc value changes every time it comes across read statement also.

here in ur case it is because of read statement.

rgds,

bharat.

Former Member
0 Kudos

Hi,

You can check how the value is there in the itab_1. whether it is external or internal value. This might be one cause.

Use conversion FM on that and check.

Thanks,

Krishna chaitanya.

ravisankara_varaprasad
Active Participant
0 Kudos

Hi ,

Sort the internal table itab_1 before loop at .. and endloop.

first SORT and then READ the internal table.

Kind Regards,

Ravi Sankar.Z

Former Member
0 Kudos

Check if the field banfin in itab_1 and it_final3 have the same

length and are of the same type.

sort itab_1 by banfn.

IF p_doc-low NE 'NB'.

LOOP AT it_final3.

READ TABLE itab_1 WITH KEY banfn = it_final3-banfn.

IF sy-subrc EQ '0'.

gt_final2-banfn = it_final3-banfn.

gt_final2-bsart = it_final3-bsart.

gt_final2-badat = it_final3-badat.

gt_final2-werks = it_final3-werks.

gt_final2-udate1 = it_final3-udate1.

gt_final2-ekgrp = it_final3-ekgrp.

gt_final2-ebeln = it_final3-ebeln.

gt_final2-bnfpo = it_final3-bnfpo.

gt_final2-matnr = it_final3-matnr.

gt_final2-menge = it_final3-menge.

gt_final2-bsmng = it_final3-bsmng.

gt_final2-menge1 = it_final3-menge.

APPEND gt_final2.

CLEAR : it_final3.

ENDIF.

endloop.

ENDIF.

Former Member
0 Kudos

Hi

You are writing SY-SUBRC under IF condition it will check for the IF condition if it fails

then it will return $ if IF condition is true then it will give 0

so check weather your IF condition is wrong or not

there may be records in LOOP but sy-subrc is for IF condition \

SY-SUBRC will check for what ever statment above to that statment

regards

naresh

Former Member
0 Kudos

Hi,

u check SY-SUBRC value as like this.

IF it_final3[] IS NOT INITIAL.

LOOP AT it_final3.

IF p_doc-low NE 'NB'.

READ TABLE itab_1 WITH KEY banfn = it_final3-banfn.

IF sy-subrc EQ '0'.

gt_final2-banfn = it_final3-banfn.

gt_final2-bsart = it_final3-bsart.

gt_final2-badat = it_final3-badat.

gt_final2-werks = it_final3-werks.

gt_final2-udate1 = it_final3-udate1.

gt_final2-ekgrp = it_final3-ekgrp.

gt_final2-ebeln = it_final3-ebeln.

gt_final2-bnfpo = it_final3-bnfpo.

gt_final2-matnr = it_final3-matnr.

gt_final2-menge = it_final3-menge.

gt_final2-bsmng = it_final3-bsmng.

gt_final2-menge1 = it_final3-menge.

APPEND gt_final2.

CLEAR : it_final3.

endif.

ENDIF.

endloop.

endif.

-


explaination-----

u r reading internal table itab_1 so check after read statement.

.....

Rewards if helpful

Thanks

Shambhu

S0025444845
Active Participant
0 Kudos

Hi Vipin,

Here sy-subrc you are checking is for read table not for loop.

sy-subrc is ccoming out to be 4 because in table itab1 there is no entry for banfn = it_final3-banfn.

regards,

sudha.

0 Kudos

Hi.

If in your READ statement you are using BINARY SEARCH on a table that you are APPENDING on the routine, you have to SORT the TABLE every time you APPEND it. Without the sort, the READ statement return SY-SUBRC = 4.

Darlei