Variables Associated with Files

Using File specification keywords, you can associate several variables with a file. For example, the INFDS keyword associates a File Information Data Structure with the file; this data structure is updated by RPG during file operations with information about the current state of the file. The SFILE keyword defines a numeric variable that you set to the relative record number for a record that you are writing.

When a file is passed as a parameter, the file parameter in the called procedure continues to be associated with the same physical variables that it was associated with in the calling procedure. The called procedure has access to the associated variables of the file parameter, although this access is only available to the RPG compiler. This allows the RPG compiler to work with the associated variables when the called procedure performs operations on the file parameter. If a file operation to a file parameter requires the value of an associated variable, the current value of the associated variable will be used. If a file operation to a file parameter changes the contents of an associated variable, the associated variable will immediately be updated with the new value. Passing a file parameter does not give the called procedure direct access to the associated variables. The called procedure can only access the associated variables if they are global variables, or if they were passed as additional parameters to the procedure.

Tip: If you pass a file parameter to another procedure, and the procedure needs to be able to access the associated variables, define a data structure with a subfield for each associated variable, and pass that data structure as an additional parameter to the procedure. See Figure 41. The following table lists the keywords that you can use to associate variables with a file.

Table 29. File specification keywords for associated variables
Keyword Usage Description
COMMIT Input The RPG programmer sets it to indicate whether the file is opened for commitment control.
DEVID Input/Feedback The RPG programmer sets it to direct file operations to a particular device. The RPG compiler sets it to indicate which device was used for the previous file operation.
EXTFILE Input The RPG programmer sets it to indicate the external file that is to be opened. The application developer sets it before the program is called to control whether a file is to be used. The RPG programmer sets it to indicate the external member that is to be opened.
EXTIND Input The RPG programmer sets some output-capable indicators for use by file operation. The system sets input-capable indicators during a operation.
EXTMBR Input The RPG compiler sets it to indicate the current state of a file.
INDDS Input/Output The RPG programmer sets some output-capable indicators for use by file operation. The system sets input-capable indicators during a operation
INFDS Input The RPG compiler sets it to indicate the current state of a file.
PRTCTL Input/Feedback The RPG programmer sets the space and skip fields to control the printer file.
RECNO Input/Feedback The RPG compiler sets it to indicate the current line of the printer file.
SAVEDS Any The RPG programmer sets it to indicate which relative record number is to be written to the subfile record.
SFILE Input/Feedback The RPG compiler sets it to indicate the relative record number that was retrieved by an input operation to the subfile record.
SLN Input The RPG programmer sets it to indicate the starting line for a display file record format.


[ Top of Page | Previous Page | Next Page | Contents | Index ]