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

Former Member
0 Kudos

y shouldnt v give SY-SUBRC with in select statement..

if yes y? wat z the use??

if no y??? wat z the use??

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi..

SELECTsets SY-SUBRC to 0 if at least one row was read, otherwise 4 or even 8 with SELECT SINGLE FOR UPDATE.

so you can use the sy-subrc to check weather the select statement has retrieved any data from the data base or not.

see the following example.

parameters g_matnt type mara-matnr.

select single matnr from mara into g_matnr where matnr = g_matnr.

at selection-screen.

<b>if sy-subrc ne 0.</b>

message 'Invalid material ' Type 'E'.

Endif.

Reward points if useful......

Suresh......

10 REPLIES 10

Former Member
0 Kudos

Hi,

Sy-subrc is used to check whether the select statement is executed successfully or not..

Meaning..

IF SY-SUBRC = 0.

***Record found.

ELSE.

***No record found..

ENDIF

Thanks,

Naren

Former Member
0 Kudos

Hi,

What do you mean by in SELECT statement?

Are you talking between SELECT and ENDSELECT? Between SELECT and END SELECT sy-subrc is always 0. Because if your code between SELECT .... ENDSELECT is being executed, that means that the record found in database. And if record found in database than sy-subrc = 0.

Let me know if you have any question.

Regards,

RS

Former Member
0 Kudos

chk this

This is because, only if the condition given (in WHERE) in the SELECT statement is true then only it will go inside the SELECT ...ENDSELECT.

In below select if there is an entry for the plant in p_werks in the table T001W then only the control will go inside. That means inside this SELECT ...ENDSELECT the value of sy-subrc will be always zero.

select SINGLE * from t001w where werks = p_werks.
if ( sy-subrc eq 0 ).
move '-Plant existing in table ' to msg.
else.
move '- Plant not existing in table ' to msg.
endif

.

Former Member
0 Kudos

Hi,

See if Sy-subrc = 0

success or ( you can use it accordingly)

else

not succes

http://help.sap.com/saphelp_nw2004s/helpdata/en/7b/fb96c8882811d295a90000e8353423/frameset.htm

regards

Chilla

Former Member
0 Kudos

Hi,

As Select EndSelect is generally used to fetch a lot of records and if inside it we use if sy-subrc = 0. then it will consume precious database time during which the table is locked for use.Hence it is unadvisable to use sy-subrc inside Select Endselect.

U can either use 'Select into Table' for the same along with 'Where' as the criteria.

<b>Award Suitable points for all the useful answers.</b>

cheers.

ashish.

Former Member

Sy-Subrc = 0 means records found as per the select statement. If sy-subrc is not equal to 0 then no records are found.

If you want to know how many records it selected, check sy-dbcnt. if a select statement finds 60 records in a table then sy-dbcnt = 60.

I guess this is helpful

Former Member
0 Kudos

Hi..

SELECTsets SY-SUBRC to 0 if at least one row was read, otherwise 4 or even 8 with SELECT SINGLE FOR UPDATE.

so you can use the sy-subrc to check weather the select statement has retrieved any data from the data base or not.

see the following example.

parameters g_matnt type mara-matnr.

select single matnr from mara into g_matnr where matnr = g_matnr.

at selection-screen.

<b>if sy-subrc ne 0.</b>

message 'Invalid material ' Type 'E'.

Endif.

Reward points if useful......

Suresh......

Former Member
0 Kudos

Hi Kota,

As a rule, if <b>SY-SUBRC = 0</b>, the statement was executed

successfully.SELECT sets <b>SY-SUBRC to 0</b> for <b>every pass by

value to an abap data object</b> ,Otherwise to <b>4 if the result set is

empty</b>, Possibly <b>8 in SELECT SINGLE FOR UPDATE</b> without the

primary key being specified after where clause, <b>Else 12 for warning

message</b>.

<b>Conclusion:</b>

sy-subrc would matter only if you give inside a <b>nested select statement</b>

Else it must be declared out for observing the stated rules above...

Thanks and regards,

Dhayanandh .S

Former Member
0 Kudos

hiii

Sy-subrc is used to check whether the query in the select statement is executrd or not.If sy-subrc is 0 then select query is successfully executed .

Regards

Hitesh

santhosh_kumarv
Active Contributor
0 Kudos

Hi kota sansy

SY in general means system variables. SUBRC is used to check whether the previous statement was executed successfully. If subrc is 0 means it was successful. It is used within the select statement to check whether some data have been selected using that select statement.

Regards

Santhosh Kumar .V