Wednesday, April 23, 2008

*PSSR:

In RPG, there are Program Exception/Errors (divide by zero, array index error, etc.)
and File Exception Errors (any file error). As with MONMSG in CL, you can trap errors
at the program level or the command level.

Program Exceptions:
If a program encounters a program error, it checks to see if there is a *PSSR subroutine coded in the program. If there is, it executes the subroutine. If there isn't, the program "fails" with an error message.
A *PSSR subroutines may be executed like any other subroutine (using ExSR or CASxx). The EndSR for a *PSSR subroutine can contain a return-point instruction.
The following return-point operands can be specified on the EndSR operation for a
*PSSR subroutine, but most of them apply only if you are using the RPG cycle.
• *DETL. Continue at the beginning of detail output lines
• *GETIN. Input Record Routine
• *TOTC. Total Time Calculations
• *TOTL. Continue at the beginning of total output lines
• *OFL. Continue at the beginning of overflow lines
• *DETC. Continue at the beginning of detail calculations.
• *CANCL. Cancel the Execution of the program
• Blank. Return control to the RPG default error handler. If the subroutine was
called by the EXSR operation and factor 2 is blank, control returns to the next
sequential instruction.
When *PSSR is invoked by an error, it does not return to the statement in error. It
should be used as an exit from the program.
File Exceptions:
Just as the program has an error handling subroutine in *PSSR, each file that you define on an F spec can also have its own error handling subroutine, identified by the INFSR keyword. Each file can have its own subroutine or a subroutine can be shared between different files.
These subroutines act in exactly the same way as *PSSR, so why not use the *PSSR
subroutine? Below is an example of INFSR being defined on the F specs.
FDisplay CF E WorkStn InfSR(*PSSR)

FCustomer UF E K Disk InfSR(*PSSR)
Now, if there is an I/O error with a file, the *PSSR subroutine will be executed.
Well, not quite. The INFSR subroutine will trap all I/O errors except file open errors.
The RPG cycle is automatically opening the files before the code is loaded, therefore it cannot execute *PSSR if there is a problem during file open (e.g., level check).
To trap file open errors, you need to perform an implicit open of the file by
specifying conditional open for the file (USROPN keyword on F Spec) and use the
OPEN operation to open the file (usually coded in the *INZSR subroutine).

3 comments:

Sakti said...

Nice and informative. Thanks.
Sakti Samanta Rout

Sakti said...
This comment has been removed by the author.
Nisha said...

Nice article on PSSR. Thanks for writing this. Please keep posting more.. thank you.