In Example 11.2, the HELPTEXT file is defined on line 1 as a combined, full-procedural, workstation file. Also, the file HELPTEXT is a user-controlled file open. The USROPN keyword indicates that the file is opened by the program code (not by the RPG cycle). The USROPN isn't required for the OPEN or CLOSE operations to be used on a file after the file is opened by RPG. Therefore, when a file is opened by RPG (i.e., the USROPN keyword is not specified) and then closed with the CLOSE operation, the OPEN operation should successfully open the file.
Example 11.2: Open and close a workstation file.
.....FFileName++IFEASFRlen+LKeylnKFDevice+.Functions++++++++++++++++++++++++++++ 0001 FHELPTEXT CF E WORKSTN USROPN .....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq.... 0002 C OPEN HELPTEXT 73 0003 C EVAL IOError = *IN73 0004 C IF NOT (IOError) 0005 C EXFMT HELPRECD C . C . C . 0006 C CLOSE HELPTEXT 0007 C ENDIF
Line 2 opens the file HELPTEXT. Line 6 closes the file HELPTEXT.
Remember, if the OPEN operation attempts to open a file that has already been opened, an error occurs. Resulting indicator 2, if it is specified, is set on. If the CLOSE operation attempts to close a file that is already closed, an error occurs. Resulting indicator 2, if it is specified, is set on. *ALL can be specified for factor 2. When *ALL is specified, all open files are closed by the operation.