Using the InfSR keyword

Estimated reading time: 2 minutes

As of 2017, the file declaration commands for DB files, print files, and workstation files have been enhanced with the INFSR keyword (last position). This keyword supports the automatic calling of a parameterless subroutine when a file operation fails.

DclDiskFile … UseKeyBufer(…) InfSR(…)
DclPrintFile … IndDS(…) InfSR(…)
DclWorkStnFile … IndDS(…) InfSR(…)

The default value is ‘not given’.

When used, InfSR indicates the subroutine that is called when a file error occurs in a file operation that is NOT using an error indicator. For example, an error here will invoke InfSR (if given):

Chain Customerl1 Key(CmCustNo)

While an error here will not call InfSR but will set *IN33 instead:

Chain Customerl1 Key(CmCustNo) Err(*in33)

In RPG the INFSR subroutine specifies where to continue execution as an optional Factor 2 in the ENDSR command, using either a character constant or a character field containing a special value that indicates the point in the cycle where execution should continue. In ECR, instead of using ENDSR with Factor 2, you explicitly code a throw of the ASNA.QSys.Runtime.InfSrException. The argument to the exception describes the point in the cycle where the program execution should continue. *CANCEL terminates the program, and re-throws the file exception. In case of it is not necessary to code the ```InfSrException``` throw. See the table for accepted values:

RPG values in ENDSR Factor 2 ECR exception arguments
*DETL "*DETL" ASNA.QSys.Runtime.InFSrReturnPoint.StarDetL
*GETIN "*GETIN" ASNA.QSys.Runtime.InFSrReturnPoint.StarGetIn
*TOTC "*TOTC" ASNA.QSys.Runtime.InFSrReturnPoint.StarTotC
*TOTL "*TOTL" ASNA.QSys.Runtime.InFSrReturnPoint.StarTotL
*OFL "*OFL" ASNA.QSys.Runtime.InFSrReturnPoint.StarOfL
*DETC "*DETC" ASNA.QSys.Runtime.InFSrReturnPoint.StarDetC
*CANCL "*CANCL" ASNA.QSys.Runtime.InFSrReturnPoint.StarCancel
Blanks (factor 2 not specified) </td> </td></tr> </table> #### Example:
dclDiskFile CMastNewL1 File("Examples/CMastNewL1") Type(*input) DB( myDb ) Designation(*primary) Org(*indexed) InfSR(MastNewErrSR)

...

BegSr MastNewErrSR
  Console.Writeline("File error!!!!")
  throw *new ASNA.QSys.Runtime.InfSrException( ASNA.QSys.Runtime.InFSrReturnPoint.StarTotC )
EndSr
If a field is used in factor 2, the corresponding ECR expression is
throw *new ASNA.QSys.Runtime.InfSrException(  )</pre>

If the field contains blanks the ECR runtime will correctly re-throw the file exception as the RPG semantics specifies.

#### Example:
BegSr MastNewErrSR
    DclFld retPoint *string
    if CMCustNo > 100 
        retPoint = "*DETC"
    else
        retPoint = ""
    endif
    throw *new ASNA.QSys.Runtime.InfSrException( retPoint )
EndSr