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
1,409

Hi Gurus,

Why there is 0 instead of other number representing the successful return of the code result for the system-variable sy-subrc.

can u please explain this in detail

points would be rewarded

asuthosh

1 ACCEPTED SOLUTION

RoySayak
Active Participant
0 Kudos
313

Hi Asuthosh,

Its very simple to explain...

For successful return of the code result sy-subrc = 0...

The other number returns the other details like...

Sy-subrc = 0 <Success>

Sy-subrc = 4 <Failure(known reason)>

Sy-subrc = 8 <Internal error(Unknown reason)>

But 0 (Zero) is the standard for anyother cases to return the sucessful execution.

Regards,

Sayak... "if u think its helpful then reward points"

9 REPLIES 9

Former Member
0 Kudos
313

SY-SUBRC

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

· ASSIGNsets 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.

· CREATE OBJECT sets SY-SUBRC if the exceptions of the instance constructor are handled.

· CREATE OBJECT in OLE2 sets SY-SUBRC to 0 if an external object was created, otherwise 1,2, 3 with different causes.

· DELETEsets SY-SUBRC to 0 if 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.

· DESCRIBE LIST sets SY-SUBRC to 0 if row or list exists, otherwise 4 or 8.

· EXEC SQL - ENDEXEC sets SY-SUBRC to 0 in almost all cases. Only if no set was read with FETCH is SY-SUBRC 4.

· FETCHsets SY-SUBRC to 0 if at least one row was read, otherwise 4.

· GENERATE SUBROUTINE POOL sets SY-SUBRC to 0 if generation was successful, otherwise 8.

· GET CURSOR sets SY-SUBRC to 0 if the cursor is correctly positioned, otherwise 4.

· GET PARAMETER sets SY-SUBRC to 0 if value found in SAP Memory, otherwise 4.

· IMPORTsets SY-SUBRC to 0 if import of data objects was successful, otherwise 4.

· INSERTsets SY-SUBRC to 0 if operation was successful, otherwise 4.

· LOAD REPORT sets SY-SUBRC to 0 if operation was successful, otherwise 4 or 8 depending on cause.

· LOOPsets SY-SUBRC to 0 if loop over extract was passed at least once, otherwise 4.

· LOOP ATsets SY-SUBRC to 0 if loop over internal table was passed at least once, otherwise 4.

· MODIFYsets SY-SUBRC to 0 if operation was successful, otherwise 4.

· MODIFY LINE sets SY-SUBRC to 0 if list row was changed, otherwise 0.

· MODIFYsets SY-SUBRC to 0 if operation was successful, otherwise 4.

· OLE2 automation, bundled commands set SY-SUBRC to 0 if all were successfully executed, otherwise 1, 2, 3, 4 depending on cause.

· OPEN DATASET sets SY-SUBRC to 0 if the file was opened, otherwise 8.

· Open SQL commands set SY-SUBRC to 0 if operation was successful, otherwise 0.

· OVERLAYsets SY-SUBRC to 0 if at least one character is overlayed, otherwise 4.

· READ DATASET sets SY-SUBRC to 0 if the read operation was successful, otherwise 4 or 8 depending on cause.

· READ LINE sets SY-SUBRC to 0 if list row exists, otherwise 0.

· READ TABLE sets SY-SUBRC to 0 if the table row was found, otherwise 2, 4, 8 depending on cause.

· REPLACEsets SY-SUBRC to 0 if search string could be replaced, otherwise 0.

· ROLLBACK WORK always sets SY-SUBRC to 0.

· SCROLLsets SY-SUBRC to 0 if scrolling in list successful, otherwise 4 or 8 depending on cause.

· SEARCHsets SY-SUBRC to 0 if search string was found, otherwise 4.

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

· SET COUNTRY sets SY-SUBRC to 0 if country ID was found in table T005X, otherwise 4.

· SET BITsets SY-SUBRC to 0 if bit was set, otherwise 0.

· SET TITLEBAR sets SY-SUBRC to 0 if title exists, otherwise 4.

· SHIFT … UP TO sets SY-SUBRC to 0 if position was found in character string, otherwise 4.

· SPLITsets SY-SUBRC to 0 if size of target fields is sufficient, otherwise 4.

· UPDATEsets SY-SUBRC to 0 if operation successful, otherwise 4.

· WRITE … TO sets SY-SUBRC to 0 if assignment successful, otherwise 4.

REward Points if useful.

Former Member
0 Kudos
313

Hi asuthosh

SY-SUBRC

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

· ASSIGNsets 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.

· CREATE OBJECT sets SY-SUBRC if the exceptions of the instance constructor are handled.

· CREATE OBJECT in OLE2 sets SY-SUBRC to 0 if an external object was created, otherwise 1,2, 3 with different causes.

· DELETEsets SY-SUBRC to 0 if 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.

· DESCRIBE LIST sets SY-SUBRC to 0 if row or list exists, otherwise 4 or 8.

· EXEC SQL - ENDEXEC sets SY-SUBRC to 0 in almost all cases. Only if no set was read with FETCH is SY-SUBRC 4.

· FETCHsets SY-SUBRC to 0 if at least one row was read, otherwise 4.

· GENERATE SUBROUTINE POOL sets SY-SUBRC to 0 if generation was successful, otherwise 8.

· GET CURSOR sets SY-SUBRC to 0 if the cursor is correctly positioned, otherwise 4.

· GET PARAMETER sets SY-SUBRC to 0 if value found in SAP Memory, otherwise 4.

· IMPORTsets SY-SUBRC to 0 if import of data objects was successful, otherwise 4.

· INSERTsets SY-SUBRC to 0 if operation was successful, otherwise 4.

· LOAD REPORT sets SY-SUBRC to 0 if operation was successful, otherwise 4 or 8 depending on cause.

· LOOPsets SY-SUBRC to 0 if loop over extract was passed at least once, otherwise 4.

· LOOP ATsets SY-SUBRC to 0 if loop over internal table was passed at least once, otherwise 4.

· MODIFYsets SY-SUBRC to 0 if operation was successful, otherwise 4.

· MODIFY LINE sets SY-SUBRC to 0 if list row was changed, otherwise 0.

· MODIFYsets SY-SUBRC to 0 if operation was successful, otherwise 4.

· OLE2 automation, bundled commands set SY-SUBRC to 0 if all were successfully executed, otherwise 1, 2, 3, 4 depending on cause.

· OPEN DATASET sets SY-SUBRC to 0 if the file was opened, otherwise 8.

· Open SQL commands set SY-SUBRC to 0 if operation was successful, otherwise 0.

· OVERLAYsets SY-SUBRC to 0 if at least one character is overlayed, otherwise 4.

· READ DATASET sets SY-SUBRC to 0 if the read operation was successful, otherwise 4 or 8 depending on cause.

· READ LINE sets SY-SUBRC to 0 if list row exists, otherwise 0.

· READ TABLE sets SY-SUBRC to 0 if the table row was found, otherwise 2, 4, 8 depending on cause.

· REPLACEsets SY-SUBRC to 0 if search string could be replaced, otherwise 0.

· ROLLBACK WORK always sets SY-SUBRC to 0.

· SCROLLsets SY-SUBRC to 0 if scrolling in list successful, otherwise 4 or 8 depending on cause.

· SEARCHsets SY-SUBRC to 0 if search string was found, otherwise 4.

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

· SET COUNTRY sets SY-SUBRC to 0 if country ID was found in table T005X, otherwise 4.

· SET BITsets SY-SUBRC to 0 if bit was set, otherwise 0.

· SET TITLEBAR sets SY-SUBRC to 0 if title exists, otherwise 4.

· SHIFT … UP TO sets SY-SUBRC to 0 if position was found in character string, otherwise 4.

· SPLITsets SY-SUBRC to 0 if size of target fields is sufficient, otherwise 4.

· UPDATEsets SY-SUBRC to 0 if operation successful, otherwise 4.

· WRITE … TO sets SY-SUBRC to 0 if assignment successful, otherwise 4.

Reward points if useful

Thanks

swaroop

Former Member
0 Kudos
313

Hi asuthosh,

sy-subrc is a system field which is the return code.

ABAP programs will set this to 0 if execution is successfull or != (<>, not equal) 0 if otherwise.

The return code value of SY-SUBRC specifies whether a suitable entry was found. In turn, this determines the value of the table index SY-TABIX .

SY-SUBRC = 0 Entry found

SY-SUBRC <> 0 Entry not found

- Each ABAP sentence modifies sy-subrc with a return code.

- zero means "no error"

- not zero means "something happened", not necessary an error (sy-subrc from a read table sentence means "not found")

Once you have that things clear, you will find what sy-subrc ne 0 means checking the syntax of the last sentence ran.

I.e.:

COMMAND [parameters].

IF sy-subrc NE 0.

...

If you have a trouble because that IF sentence is being true (sy-subrc <> 0), then you must make a double-click over COMMAND, to read the ABAP help about that command. Generally, SAP provides the frequent return codes for each command, and you will find the sense of your sy-subrc value.

Rewqard if helpful.

Thankyou,

Regards.

Former Member
0 Kudos
313

Hi Asu,

That is standard one.At time of creation they will follow that notation.

Award poitns if helpful.

Kiran Kumar.G.A

Former Member
0 Kudos
313

hi,

i binary system, 0 means true and 1 means false.

On suceess return ,it has to be displayed as true. so ' 0 ' is used as number to represnt sucessful return

i guess that could be the correct reason .

reward if useful

thanks and regards

suma sailaja

Edited by: suma sailaja pvn on Jan 10, 2008 6:49 AM

Former Member
0 Kudos
313

Hi Ashutosh,

It's due to convention, generally in all languages return code 0 means successful processing.

Regards,

Mohaiyuddin

Former Member
0 Kudos
313

Hi,

SY-SUBRC is a system code to identify whether a transaction or a statement is executed succesfully or not.

They have set several types of failures for an execution and they have set numbers for them.

To differentiate Succesful execution and Failure they would have set 0 for succesful execution.

i.e. 0 - successful execution

anyother number - Failure in execution,

awrd points if helpful

Bhupal

Kanagaraja_L
Active Contributor
0 Kudos
313

Hi asuthosh,

SY-SUBRC is the system variable which is set after any SQL,Function call,etc.when these operations are entirely sucessful then it is set to a value of 0.else to any value like 2 3 4 5 6 7 etc.

For ABAP statements, it is usually, 0,4,8 which means success or failure.

Sy-subrc = 0 -


Success

Sy-subrc = 4 -


Failure(known reason)

Sy-subrc = 8 -


Internal error(Unknown reason).

From BDC CALL tranaction, 1001, will mean failure. Or if we are talking about sy-subrc value after calling a function module, it will depend on the exceptions list from the function module.

Kanagaraja J

RoySayak
Active Participant
0 Kudos
314

Hi Asuthosh,

Its very simple to explain...

For successful return of the code result sy-subrc = 0...

The other number returns the other details like...

Sy-subrc = 0 <Success>

Sy-subrc = 4 <Failure(known reason)>

Sy-subrc = 8 <Internal error(Unknown reason)>

But 0 (Zero) is the standard for anyother cases to return the sucessful execution.

Regards,

Sayak... "if u think its helpful then reward points"