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
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) | | 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 ) EndSrIf a field is used in factor 2, the corresponding ECR expression is throw *new ASNA.QSys.Runtime.InfSrException( |