IBM AS/400 Frozen Dessert Maker User Manual


 
*-----------------------------------------------------------------*
* Start of subprocedure definition
*-----------------------------------------------------------------*
P SubProc B
D SubProc PI 5P 0
...
*-----------------------------------------------------------------*
* Body of code goes here including division operation.
*-----------------------------------------------------------------*
C X DIV Divisor Result
C Return Result
*-----------------------------------------------------------------*
* An error occurs when division by zero takes place.
* Control is passed to the *PSSR subroutine.
*-----------------------------------------------------------------*
C *PSSR BEGSR
*-----------------------------------------------------------------*
* If this is a divide-by-zero error, return 0 from the subprocedure
*-----------------------------------------------------------------*
C IF Err = 102
C RETURN 0
C ENDIF
*-----------------------------------------------------------------*
* If control reaches ENDSR, the procedure will fail
*-----------------------------------------------------------------*
C ENDSR
P E
Figure 114. Example of Subprocedure *PSSR Subroutine with RETURN
Avoiding a Loop in an Error Subroutine
In the previous example, it is unlikely that an error would occur in the *PSSR and
thereby cause a loop. However, depending on how the *PSSR is written, loops may
occur if an exception occurs while processing the *PSSR.
One way to avoid such a loop is to set a first-time switch in the subroutine. If it is
not the first time through the subroutine, you can specify an appropriate return
point, such as *CANCL, for the Factor 2 entry of the ENDSR operation.
Figure 115 on page 236 shows a program NOLOOP which is designed to generate
exceptions in order to show how to avoid looping within a *PSSR subroutine. The
program generates an exception twice:
1. In the main body of the code, to pass control to the *PSSR
2. Inside the *PSSR to potentially cause a loop.
Chapter 12. Handling Exceptions 235