2011 Apr 27 4:52 PM
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.
2011 Apr 27 4:57 PM
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.
2011 Apr 27 4:57 PM
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.
2011 Apr 27 5:00 PM
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.
2011 Apr 27 5:10 PM
Actually I was taught that this is the correct way - in case domains are changed.
Rob
2011 Apr 27 5:30 PM
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.
2011 Apr 27 5:45 PM
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.
2011 Apr 27 5:55 PM
... SAP ever thinks of changing data type for SY-SUBRC.
Well, I meant in general.
SY-SUBRC man not change, but custom domains?
Rob
2011 Apr 27 8:46 PM
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
2011 Apr 27 10:02 PM
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.
2011 Apr 27 6:13 PM