‎2007 Aug 02 6:00 PM
Hi All,
When does the READ Statement returns sy-subrc value equals 4 <u>eventhough it fetches a record</u>
Thanks,
S S K
‎2007 Aug 02 6:05 PM
Hi
I hope when you don't have authorization to Read the required table data then it may return sy-subrc = 4.
but generally in the internal table reading we check for sy-subrc = 0. then take the necessary record and use.
<b>Reward points for useful Answers</b>
Regards
Anji
‎2007 Aug 02 6:05 PM
Hi
I hope when you don't have authorization to Read the required table data then it may return sy-subrc = 4.
but generally in the internal table reading we check for sy-subrc = 0. then take the necessary record and use.
<b>Reward points for useful Answers</b>
Regards
Anji
‎2007 Aug 02 6:11 PM
Hi Anji,
I am not sure how authorization comes into picture with internal table.
Anyways..... This is the scenario which was asked in an interview to one of my friend. The READ statement fetches the record from the internal table but its also returns subrc value as 4. When does it happen ?
Rgrds,
S S K
‎2007 Aug 02 7:54 PM
Friend.
if read statement reads a data then there is no way that sy-subrc eq 4 , if read is successful then sy-subrc is 0 else its 4, interviewer might have tried to confuse ur friend... .
Thanks
Mahesh
‎2007 Aug 02 8:03 PM
IF the read statement has performed sucessfully no way it could get the SY-SUBRC = 4. the value has to be 0.
It was a question just to confuse.
Shreekant
‎2007 Aug 02 8:10 PM
If your itab has a header record and it is not cleared before the read statement, then the header will retain the previous values even if the read fails (even though they are not the correct values). So here you have a situation where the header has values even when the READ failed. See the simple example below. This illustrates the importance of CLEAR and if not used what chaos it may create.
DATA: BEGIN OF itab OCCURS 0,
field.
DATA: END OF itab.
itab-field = 'X'.
APPEND itab.
CLEAR itab.
itab-field = 'Y'.
APPEND itab.
CLEAR itab.
READ TABLE itab INDEX 1.
WRITE:/ itab-field.
*-- Now read the table again where sy-subrc will be 4
READ TABLE itab WITH KEY field = 'Z'.
WRITE:/ itab-field.
‎2007 Aug 02 8:22 PM
‎2007 Aug 02 8:01 PM
Hi SSK,
I think the interviewer intentionally want to confuse. Probably he is checking how confident you are with the answer.Sometimes during interviews one should be enought confident with their answer though it might be wrong.This strengthens the impression.Without any second thought sy-subrc gives '0' when it fetches any record. Else it will give the value 4.
Hope this helps.
Please reward if useful.
Thanks,
Srinivasa
‎2007 Aug 02 8:03 PM