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
2,079

Hi all,

is it required to check after select single statement ' if sy-subrc eq 0.' Please give me suggestions.

Thanks & Regards,

sudhakar

Hi all,

is it required to check after select single statement ' if sy-subrc eq 0.' Please give me suggestions.

Thanks & Regards,

sudhakar

8 REPLIES 8
Read only

Former Member
0 Likes
1,492

hI,

It is a good programming to check sy-subrc value after READ and select single.

Thanks CSR.

Message was edited by:

CSR

Read only

varma_narayana
Active Contributor
0 Likes
1,492

Hi..

You must always check SY-SUBRC after the Select SINGLE.

Bcoz then only you will come to whether the the Record is fetched or Not.

Other wise the work area will contain the Previous record.

<b>Reward if Helpful.</b>

Read only

Former Member
0 Likes
1,492

Hi,

check out the below code

read table IT_EKPO INTO WA_EKPO .

SELECT single kunnr

ADRNR

FROM KNA1

INTO CORRESPONDING FIELDS OF wa_KNA1 WHERE KUNNR = wa_EKPO-KUNNR

IF SY-SUBRC = 0.

SELECT SINGLE ADDRNUMBER

NAME1

STREET

HOUSE_NUM1

MC_CITY1

POST_CODE1

REGION

COUNTRY

FROM ADRC INTO CORRESPONDING FIELDS OF WA_ADRC1.

since if SY-SUBRC = 0 Entry found then only the contents are written ie., you come to know that the table contains some values.

***********please reward points if the information is helpful to you************

Read only

Former Member
0 Likes
1,492

if sy-subrc = 0.Return code following an ABAP statement

success.

4

error.

Read only

Former Member
0 Likes
1,492

Hi,

its good to check always.

rgds,

bharat.

Read only

former_member194669
Active Contributor
0 Likes
1,492

Hi,

Its not mandatory to check sy-subrc eq 0. after select you can check this way also

refresh : itab.

select single * from mara into table itab where matnr eq 'ABC'.

if not itab[] is initial.

endif.

aRs

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,492

Hi,

Its not mandatory to check SY-SUBRC after any statement for that instance,

but if you want to make sure that the statement was successful then you should check it.

Here is the list of statements that effect sy-subrc.

Its little difficult to get all the statements at once, I have got that info stored on my machine for all those who wants to know the list of statements that effect sy-subrc here is the list.

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.

Regards,

Sesh

Read only

Former Member
0 Likes
1,492

Thanks.

sudhakar