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
967

Hi All,

When does the READ Statement returns sy-subrc value equals 4 <u>eventhough it fetches a record</u>

Thanks,

S S K

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
911

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

8 REPLIES 8
Read only

Former Member
0 Likes
912

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

Read only

0 Likes
911

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

Read only

0 Likes
911

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

Read only

0 Likes
911

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

Read only

0 Likes
911

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.

Read only

0 Likes
911

Perfect Srini !!!!!!!

Thanks,

S S K

Read only

Former Member
0 Likes
911

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

Read only

Former Member
0 Likes
911

From the help for "read":

SY-SUBRC = 4:

No entry was read.

Rob