As in other BS2000 command sequences, an error in one of the commands in an
S procedure will prevent execution of all subsequent commands. In non-S procedures, this behavior is referred to as “spin-off”, in S procedures as “SDF-P error handling”. Unless otherwise specified, it will cause the procedure run to be aborted; the caller will receive an error report. This again results in a spin-off or SDF-P error handling in the calling procedure, so that eventually the batch task will be aborted or, in interactive mode, the system prompt will appear on the screen.
If it is possible (or even necessary) to continue processing even after a command error has occurred in an S procedure, the error must be intercepted at an appropriate location in the procedure by means of an error handling block:
/DELETE-FILE FILE.A /DELETE-FILE FILE.B /DELETE-FILE FILE.C /IF-BLOCK-ERROR / WRITE-TEXT 'At least one of the files cannot be opened.' /END-IF /"Continue processing"
The command sequence initiated by IF-BLOCK-ERROR is not executed unless one of the preceding commands triggers SDF-P error handling. The procedure may also contain an ELSE branch analogous to the IF block to be executed when no error occurs. This prevents the spin-off and procedure execution can be continued normally after the corresponding END-IF.
To supply more detailed information for evaluation than the mere “OK” or “not OK” returned by SDF-P error handling, each command reports the result of its execution in a standardized return code consisting of the components maincode, subcode1 and
subcode2. These are automatically saved by SDF-P if an error occurs. If no error condition is set, the SAVE-RETURNCODE command can be used to save the return code from the command executed last. The saved values are made available for use in SDF-P expressions by the predefined functions MAINCODE, SUBCODE1 and SUBCODE2.
Unless otherwise specified, SDF-P error handling is triggered by the same situations which result in a spin-off in non-S procedures. Specifying ERROR-MECHANISM=*BY-RETURNCODE (SET-PROCEDURE-OPTIONS command) makes error handling dependent on the return code (subcode1 not equal to zero results in an error). For more details see section “Error handling”.
The command name IF-BLOCK-ERROR is meant to indicate that the error handling it initiates is block-oriented. It takes effect only if the error occurs in the same block or a block nested in that block. If an error occurs, any error handling contained in a new block that starts after the error will be ignored:
/DELETE-FILE FILE.A /BEGIN-BLOCK / DELETE-FILE #TEMP.B / DELETE-FILE #TEMP.C / IF-BLOCK-ERROR / WRITE-TEXT 'error while deleting temporary files' / END-IF /END-BLOCK
In this example, an error during deletion of FILE.A will cause the entire BEGIN block that follows to be skipped; the error handling takes effect only if an error occurs in the DELETE-FILE commands for the files #TEMP.B and #TEMP.C which are part of the same block.
To permit error handling to take effect for a single command without having to enclose the command in a separate BEGIN block, SDF-P provides the IF-CMD-ERROR command. This command initiates a block that is not executed unless an error occurs in the command immediately preceding the block.