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

sy-subrc

Former Member
0 Likes
3,775

hi guys

i am confusing with sy-subrc, whay we need it every time with abap command/statements

sometimes it happen that

sy-subrc=0

sy-subrc=4 and it print 0.

so could u please explain in details.

thanks a lot

u will be rewarded !!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,182

Hi Sanjeev,

Sy-subrc statement is used to check whether the processing statement before the sy-subrc has been processed successfully.

For eg.

If you are inserting, updataing, modifying or deleting an entry in a database or internal table then immediately after those statements you have to specify the sy-subrc statement which will retrun an integer.

If it is 0 then the processing is successful.

If it is other than zero then the processing is a failure.

Including the Sy-Subrc statement will also increase the performance in the ABAP Side.

See these similar threads,

1.

2.

3.

4.

5.

Hope it helps.

Regards,

Maheswaran.B

hi guys

i am confusing with sy-subrc, whay we need it every time with abap command/statements

sometimes it happen that

sy-subrc=0

sy-subrc=4 and it print 0.

so could u please explain in details.

thanks a lot

u will be rewarded !!!

10 REPLIES 10
Read only

Former Member
0 Likes
2,182

Hi

IF SY-SUBRC = 0 means the command has worked fine, if SY-SUBRC <> 0, it means it has failed.

The value of SY-SUBRC is always in order last command, but some stataments don't have any influence on SY-SUBRC, because they always work fine.

When SY-SUBRC isnn't 0, the value (4,8....) depends on why the statament has failed and you should find out this information from help of the command.

Max

Message was edited by: max bianchi

Message was edited by: max bianchi

Read only

Former Member
0 Likes
2,182

HI sanjeev,

1. SY-SUBRC

This is the concpet used

in abap to check

whether the

abap statment is successful or not.

2. we have to check sy-subrc

IMMEDIDATELY AFTER THE LINE IS EXECUTED.

3. 0 = EVERYTHING IS ALLRIGHT

4 = SOME ERROR. (non-zero)

4. depending on different statement,s

non-zero 4, 8, 12, 16 etc,

has some SPECIAL MEANING !

regards,

amit m.

Read only

Former Member
0 Likes
2,182

Hi,

If you are dealing with selects if you don't get any data you will get sy-subrc = 4, if you get the data it will be 0.

similarly for others...

similarly FM's ,and read table and others...

regards

vijay

Read only

Former Member
0 Likes
2,182

SY_SUBRC

indicates the whether the just last statement executed successfully or not.

sy-subrc = 0. means "successful

sy-subrc<>0. "4, 8 having different meaning

indicates reson of failure.

Regards

savita

Read only

Former Member
0 Likes
2,182

HI ,

SY-SUBRC check is very much essential in Performance point of view of the code.

e.g we always add sy-subrc check after read statement this reduces possibility of executing the code unnecessarily if READ statement fails.

also sy-subrc check is added after select query ju st to ensure that query has failed or not.

Regards

Saurah.

Read only

Former Member
0 Likes
2,182

hi Sanjeev,

sy-subrc is a system variable.It returns the value after the execution of statement.Each statement does not return sy-subrc. As for eg subrotines doesn't return sy-subrc.When sy-subrc returs 0 this means your statemant executes successfully.If anything else than 0 then this means your stament does n't execute with success.

ok

Aashish

Read only

Former Member
0 Likes
2,183

Hi Sanjeev,

Sy-subrc statement is used to check whether the processing statement before the sy-subrc has been processed successfully.

For eg.

If you are inserting, updataing, modifying or deleting an entry in a database or internal table then immediately after those statements you have to specify the sy-subrc statement which will retrun an integer.

If it is 0 then the processing is successful.

If it is other than zero then the processing is a failure.

Including the Sy-Subrc statement will also increase the performance in the ABAP Side.

See these similar threads,

1.

2.

3.

4.

5.

Hope it helps.

Regards,

Maheswaran.B

Read only

Former Member
0 Likes
2,182

Hi Sanjeev,

First of all I am sure that you must be aware that SY_SUBRC is a system field. It has three values viz.

0 : When Record is found on execution of query.

4 : When record isn't found on execution of query.

8 : Applies only to SELECT SINGLE FOR UPDATE: You did not specify all of the primary key fields in the WHERE condition. The result table is empty.

Now when you are printing the value of SY-SUBRC just before check the value. whatever the value is that time that will be printed.

Moreover if you are printing the same in the loop and in goeds inside the loop then the value of SY-SUBRC will become 0 instead of 4. thats why output is 0.

Reward the points if answer is useful.

Regards,

Siddarth.

Read only

Former Member
0 Likes
2,182

Hi,

Please find the <b>Complete details about SY-SUBRC</b>

in the SAP Help Portal link under topic <b>Return Value</b>

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

Sample of the details is given below.

<b>Return Value

SY-SUBRC</b>

Return value set by the following ABAP statements. In general, a content of 0 means that the statement was executed without problems.

ASSIGN sets SY-SUBRC to 0 if assignment to field symbol is possible, otherwise 4.

ASSIGN <dref>->* sets SY-SUBRC to 0 if dereferencing is possible, otherwise 4.

AUTHORITY-CHECK sets SY-SUBRC to 0 if the user has the necessary authorization, otherwise 4, 8, 12, 16, 24, 28, 32, or 36 depending on the cause.

CALL DIALOG with USING sets SY-SUBRC to 0, if processing was successful, otherwise <>0.

CALL FUNCTION sets SY-SUBRC according to the exception handling.

CALL METHOD sets SY-SUBRC according to the exception handling.

CALL SELECTION-SCREEN sets SY-SUBRC to 0 if the user chose Enter or Execute and 4 if the user chose Cancel.

CALL TRANSACTION with USING sets SY-SUBRC to 0 if processing was successful, otherwise <>0.

CATCH SYSTEM-EXCEPTIONS sets SY-SUBRC if there are runtime errors after the ENDCATCH statement. The value is specified in the program.

COMMIT WORK sets SY-SUBRC to 0.

COMMIT WORK AND WAIT sets SY-SUBRC to 0 if update was successful, otherwise <>0.

COMMUNICATION INIT DESTINATION … RETURNCODE sets SY-SUBRC as specified.

CONCATENATE sets SY-SUBRC to 0 if the result fits into target variable, otherwise 4.

DELETE sets SY-SUBRC to 0 if the operation was successful, otherwise 4 or <> 0 depending on cause.

DEMAND … MESSAGES INTO sets SY-SUBRC to 0 if a message table is empty, otherwise <> 0.

Message was edited by: Santhosh Kumar Subramanian

Read only

Former Member
0 Likes
2,182

One other point. A non zero return code doesn't really mean that the statement failed. It's really just a processing status that you can use to decide how to proceed. For example, if you do a binary read on a table and get a return code of 4, it means that there was no record found. Sso your processing might be something like:


read table ... binary search.
case sy-subrc.
  when 0.
*    process the record.
  when 4.
*    add a new record.
  when others.
endcase.

Rob