IBM AS/400 Frozen Dessert Maker User Manual


 
subroutine is called again. The procedure will loop unless you code the subrou-
tine to avoid this problem.
To see how to code an error subroutine to avoid such a loop, see “Avoiding a
Loop in an Error Subroutine” on page 235.
Using a File Error (INFSR) Subroutine
To handle a file error or exception in a main procedure you can write a file error
(INFSR) subroutine. When a file exception occurs:
1. The INFDS is updated.
2. A file error subroutine (INFSR) receives control if the exception occurs:
On an implicit (primary or secondary) file operation
On an explicit file operation that does not have an indicator specified in
positions 73 - 74.
A file error subroutine can handle errors in more than one file.
The following restrictions apply:
If a file exception occurs during the start or end of a program, (for example, on
an implicit open at the start of the cycle) control passes to the ILE RPG default
exception handler, and not to the error subroutine handler. Consequently, the
file error subroutine will not be processed.
If an error occurs that is not related to the operation (for example, an array-
index error on a CHAIN operation), then any INFSR error subroutine would be
ignored. The error would be treated like any other program error.
An INFSR cannot handle errors in a file used by a subprocedure.
To add a file error subroutine to your program, you do the following steps:
1. Enter the name of the subroutine after the keyword INFSR on a File
Description specification. The subroutine name can be *PSSR, which indicates
that the program error subroutine is given control for the exception on this file.
2. Optionally identify the file information data structure on a File Description spec-
ification using the keyword INFDS.
3. Enter a BEGSR operation where the Factor 1 entry contains the same subrou-
tine name that is specified for the keyword INFSR.
4. Identify a return point, if any, and code it on the ENDSR operation in the sub-
routine. For a discussion of the valid entries for Factor 2, see “Specifying a
Return Point in the ENDSR Operation” on page 237.
5. Code the rest of the file error subroutine. While any of the ILE RPG compiler
operations can be used in the file error subroutine, it is not recommended that
you use I/O operations to the same file that got the error. The ENDSR opera-
tion must be the last specification for the file error subroutine.
Figure 111 on page 230 shows an example of exception handling using an INFSR
error subroutine. The program TRNSUPDT is a simple inventory update program. It
uses a transaction file TRANSACT to update a master inventory file PRDMAS. If an
I/O error occurs, then the INFSR error subroutine is called. If it is a record lock
error, then the record is written to a backlog file. Otherwise, an inquiry message is
issued.
Chapter 12. Handling Exceptions 229