IBM AS/400 Frozen Dessert Maker User Manual


 
*-----------------------------------------------------------------
* Procedure Enabler. This procedure enables a cancel handler,
* then gets an error which causes Enabler to be canceled.
*-----------------------------------------------------------------
P Enabler B
* Local variables
D Handler S * PROCPTR INZ(%PADDR('CANHDLR'))
D Msg S 20A
D pMsg S * INZ(%ADDR(Msg))
D Zero S 5P 0 INZ(0)
D Count S 5I 0 INZ(0) STATIC
D Array S 1A DIM(2)
*-----------------------------------------------------------------
* Enable the cancel handler. When this procedure gets canceled,
* procedure 'CANHDLR' will be called.
*-----------------------------------------------------------------
C CALLB 'CEERTX'
C PARM Handler
C PARM pMsg
C PARM *OMIT
*-----------------------------------------------------------------
* This procedure will be called three times. The first two times
* will get an error while the cancel handler is enabled.
*-----------------------------------------------------------------
C EVAL Count = Count + 1
C SELECT
C WHEN Count = 1
C EVAL Msg = 'Divide by zero'
C EVAL Zero = Zero / Zero
C WHEN Count = 2
C EVAL Msg = 'String error'
C 'A' SCAN 'ABC':Zero Zero
*-----------------------------------------------------------------
* On the third call, disable the cancel handler. The array index
* error will cause the procedure to fail, but the handler will
* not be invoked.
*-----------------------------------------------------------------
C WHEN Count = 3
C CALLB 'CEEUTX'
C PARM Handler
C PARM *OMIT
C EVAL Msg = 'Array index error'
C EVAL Array(Zero) = 'x'
C ENDSL
P Enabler E
Figure 118 (Part 3 of 4). Enabling and Coding a Cancel Handler for a Subprocedure
246 ILE RPG for AS/400 Programmer's Guide