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 would sy-subrc be initial?

Former Member
0 Likes
11,075

The below code is supposed to check if a background job is currently running this program. It seems to me that the line

IF sy-subrc is initial.

should be

IF sy-subrc = 0.

Here is the code:


 IF sy-batch IS NOT INITIAL.
    SELECT SINGLE
           jobname
           strtdate
           status
           progname
      FROM v_op
      INTO s_op
     WHERE progname = sy-repid
       AND strtdate = sy-datum
       AND strttime LT d_time
       AND status   = 'R'  .
    IF sy-subrc IS INITIAL.
      MESSAGE a000(zz_messages) WITH text-005.
    ENDIF.
  ENDIF.

What we are seeing is that the sy-subrc is initial sometimes and I'm not sure why. I do know that it is not happening because its finding a record of the job running in the v_op table, since that I believe should return a 0 value.

1 ACCEPTED SOLUTION
Read only

former_member191735
Active Contributor
4,203

Both have same meaning.

Sy-SUBRC initial value is ZERO (0) so should be the same.

This is like....

data: sy-subrc type int4 value '0'.

if sy-subrc is initial -> means if sy-subrc = 0.

The below code is supposed to check if a background job is currently running this program. It seems to me that the line

IF sy-subrc is initial.

should be

IF sy-subrc = 0.

Here is the code:


 IF sy-batch IS NOT INITIAL.
    SELECT SINGLE
           jobname
           strtdate
           status
           progname
      FROM v_op
      INTO s_op
     WHERE progname = sy-repid
       AND strtdate = sy-datum
       AND strttime LT d_time
       AND status   = 'R'  .
    IF sy-subrc IS INITIAL.
      MESSAGE a000(zz_messages) WITH text-005.
    ENDIF.
  ENDIF.

What we are seeing is that the sy-subrc is initial sometimes and I'm not sure why. I do know that it is not happening because its finding a record of the job running in the v_op table, since that I believe should return a 0 value.

9 REPLIES 9
Read only

former_member191735
Active Contributor
4,204

Both have same meaning.

Sy-SUBRC initial value is ZERO (0) so should be the same.

This is like....

data: sy-subrc type int4 value '0'.

if sy-subrc is initial -> means if sy-subrc = 0.

Read only

brad_bohn
Active Contributor
0 Likes
4,203

It's lazy coding. INITIAL indicates the 'initial' value for the data type in question, in this case '0' for an integer. To me, it represents that the developer doesn't care or know enough to do a direct comparison.

Read only

Former Member
0 Likes
4,203

Actually I was taught that this is the correct way - in case domains are changed.

Rob

Read only

brad_bohn
Active Contributor
0 Likes
4,203

That's definitely a valid point but I don't think I've ever seen a data type change between initial types, at least not one I've used or noticed. I normally only use the syntax for references or internal table bodies.

Read only

0 Likes
4,203

Rob, god forbid if SAP ever thinks of changing data type for SY-SUBRC. I can't even begin to imagine how many reports would need code changes.

Read only

Former Member
0 Likes
4,203

... SAP ever thinks of changing data type for SY-SUBRC.

Well, I meant in general.

SY-SUBRC man not change, but custom domains?

Rob

Read only

Former Member
0 Likes
4,203

A better example :

A form returns a flag and someone changes the form to return an 'x' instead of an 'X', checking INITIAL or NOT INITIAL is less error prone. Use this construct when you care whether or not there is a value, but not the specific value.

Rob

Read only

brad_bohn
Active Contributor
0 Likes
4,203

A form returns a flag and someone changes the form to return an 'x' instead of an 'X', checking INITIAL or NOT INITIAL is less error prone. Use this construct when you care whether or not there is a value, but not the specific value.

Well, I can't help it if your coding is error prone. However, I am perfect and never make mistakes ;-b.

Read only

Former Member
0 Likes
4,203

Thank you all for your help!