Accessing a file through different access paths (e.g. *OPNQRYF, POINT) in the same Function (or Form)
|Date:||26 July 2001|
|Product/Release:||LANSA for iSeries|
|Abstract:||You can access the same file through different access paths (e.g. standard SELECT, FETCH, using POINT or *OPNQRYF) as long as you close the file path after being processed|
|Submitted By:||LANSA Technical Support|
|Last Review||December 2010|
A problem was reported for the following scenario:
OPEN FILE(PSLMST) USE_OPTION(*OPNQRYF) QRYSLT('SURNAME *CT "BR"') ... process file CLOSE
Fetch (#EMPNO #GIVENAME #SURNAME) FROM_FILE(PSLMST) WITH_KEY(#EMPX) ... process employee
Routine A was executed, then Routine B, then Routine A again and subsequently Routine B which failed with an error (Invalid I/O Operation on File).
The reason for that was that the first time that Routine B accessed the file left the path open. Then the second time that Routine A was executed, created a new path for the same file (*OPNQRYF). Then, the CLOSE in Routine A actually closed the path for the file opened in Routine B (not for the new *OPNQRYF path). Finally, when Routine B attempted to access the file, it failed because the file path was closed. Note also that the default FILE parameter value for CLOSE command is *ALL (which has to be considered as well).
This situation was fixed by using the *ONDEMAND option on the OPEN command and explicitly closing the file in Routine B. Like:
OPEN USE_OPTION(*ONDEMAND) Fetch (#EMPNO #GIVENAME #SURNAME) FROM_FILE(PSLMST) WITH_KEY(#EMPX) ... process employee CLOSE FILE(PSLMST)
A similar approach can be used when using the POINT command. For example:
OPEN USE_OPTION(*ONDEMAND) FETCH (#SURNAME) FROM_FILE(PSLMST) POINT FILE(PSLMST) TO_FILE(MYPSLM) ... process file fields CLOSE FILE(PSLMST)
Or maybe, place the POINT command in an initial routine (e.g. after user's selection) under certain conditions (e.g. If Company = A, POINT to File A, etc.).