A SAP job step can also have an application return code.
You can access it as described below:
R3_GET_APPLICATION_RC can be used to check the application return code of one or several job steps and cancel the AE job if required.
This specific report type contains information about the steps plus the application return code. The return code can be read using the XML script elements.
Example:
:SET &xmlreport# = XML_OPEN(REPORT,,SSTP)
! Reading the first element
:SET &job# = XML_GET_FIRST_CHILD(&xmlreport#)
:SET &name# = XML_GET_NODE_NAME(&job#)
:PRINT "First element: &name#"
! Reading the second element
:SET &child# = XML_GET_FIRST_CHILD(&step#)
! Reading the step's children
:WHILE &child# <> ""
:SET &name# = XML_GET_NODE_NAME(&child#)
! Reading the application return code
:IF &name# = "RC"
: SET &applrc# = XML_GET_NODE_TEXT(&child#)
: PRINT "Applicationreturncode: &applrc#"
:ENDIF
:SET &child# = XML_GET_NEXTSIBLING(&child#)
:ENDWHILE
:XML_CLOSE
Information about SAP job steps is logged in the job report. This report also informs about the application return code if you use the AE interface.
"Appl-RC n/a" is written to the job report if a step has no application return code.
Use the script function PREP_PROCESS_REPORT to read and further process application return codes.
In the following example, the ABAP ZZ_TEST_APPL_RC is called in a job once. Its application return code should be read.
! Select the line containing ABAP and the application return code.
:SET &HND# = PREP_PROCESS_REPORT(,,REP,"*ZZ_TEST_APPL_RC*Appl-RC*")
:PROCESS &HND#
: SET &ZEILE# = GET_PROCESS_LINE(&HND#)
! Find the exact position in a line where the "Appl RC" starts.
: SET &POS_STR# = STR_FIND(&ZEILE#,"Appl-RC")
! The application return code is located after 8 characters.
: SET &POS_ARC# = ADD(&POS_STR#,8)
! Read the application return code.
: SET &ARC# = STR_CUT(&ZEILE#,&POS_ARC#)
! Check if the step really supplies an application return code.
: IF &ARC# <> "n/a"
! The read value is a string and must therefore be converted to a number.
: SET &ARC# = CINT(&ARC#)
! Beyond this point there are any script statements which further process the application return code.
: PRINT &ARC#
: ENDIF
:ENDPROCESS
The application return code is not available with the XBP interface.