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

Why is sy-subrc not zero?

Madjid_Khanevadegi
Participant
0 Likes
4,888

Hello

in sap s4 hana i used a simple statement read table , this statement not return record and sy-subrc is 4 , and after that i use clear statement but the sy-subrc is 4 and not set to zero.

thank you in advance

  Read Table it1
  Into wa1
  WITH KEY GUID = x_GUID.
  ...
  if sy-subrc ne 0 .
      clear wa1.
  endif.

1 ACCEPTED SOLUTION
Read only

BiberM
Contributor
4,010

The reason is that the clear Statement does not change sy-subrc at all. So it stays at the same value as before.

This is probably one of the reasons why most of the new commands do not rely on sy-subrc any more but uses exceptions instead.

10 REPLIES 10
Read only

Sandra_Rossi
Active Contributor
0 Likes
4,010

Probably that the data types of GUID/X_GUID are different, or their values have a different length, or trailing space if their types are string. If you don't find out the reason, please attach the screenshots from the debugger (types, hex values, etc.).

Anyway, probability is 99.9999% that it's not a bug in SAP.

Read only

BiberM
Contributor
4,011

The reason is that the clear Statement does not change sy-subrc at all. So it stays at the same value as before.

This is probably one of the reasons why most of the new commands do not rely on sy-subrc any more but uses exceptions instead.

Read only

0 Likes
4,010

thank you michael.biber2

that is right , i thought after clear statement the sy-subrc set to zero .

Read only

Sandra_Rossi
Active Contributor
0 Likes
4,010

Is your question about SY-SUBRC not set to 0 after CLEAR? If yes please forget my first comment and refer to Michael answer.

Read only

venkateswaran_k
Active Contributor
0 Likes
4,010

Probably, if you want to clear sy-subrc - try using FREE wa1

Clear - may clear the database object fields as well.

Read only

former_member1716
Active Contributor
0 Likes
4,010

madjied.khanevadegi,

SY-SUBRC is system field that will provide a return value for every ABAP statement executed as part of the program. The CLEAR is not among those commands that can change SY-SUBRC value.

The Value of the SY-SUBRC field will not be changed until another valid statement gets executed that will change the SY-SUBRC value, This is common for all system fields.

However you can clear the value of SY-SUBRC at any instant of the program.

The values and different commands in ABAP that alter SY-SUBRC is given below:

SY-SUBRC

Regards!

Read only

0 Likes
4,010

The first sentence of your answer is confusing "SY-SUBRC ... provide a return value for every ABAP statement".

If you say instead, "only a few ABAP statements set SY-SUBRC", that would be better.

Read only

FredericGirod
Active Contributor
4,010

That's true, SY-SUBRC is not a good friend, most of the developper used a variable because most of the time we didn't know when it will be updated. SELECT / READ ...

Read only

Sandra_Rossi
Active Contributor
4,010
frdric.girod and sadly, people don't read the documentation when they have a doubt... 😉
Read only

FredericGirod
Active Contributor
4,010

As a good developper; I never read documentation, even in real life 🙂