Identifying files

To identify a file, you associate the file-name that is internal to your COBOL program with the corresponding system file-name by using the SELECT and the ASSIGN clauses in the FILE-CONTROL paragraph.

About this task

A simple form of this specification is:

SELECT internalFilename ASSIGN TO fileSystemID-externalFilename

internalFilename specifies the name that you use inside the program to refer to the file. The internal name is typically not the same as the external file-name or the system file-name.

In the ASSIGN clause, you designate the external name of the file (externalFilename) that you want to access, and optionally specify the file system (fileSystemID) in which the file exists or is to be created.

If you code fileSystemID to identify the file system, use one of the following values:

DB2®
DB2 relational database file system.
LSQ
Line sequential file system.
QSAM
Queued sequential access method file system.
RSD
Record sequential delimited file system.

You can specify RSD only for SEQUENTIAL files that have fixed or variable-length records.

SdU
SMARTdata Utilities file system.
SFS
Encina Structured File Server file system.
STL
Standard language file system.
VSA
Virtual storage access method, which implies either the SFS or SdU file system.

SFS is implied if the initial (leftmost) part of the system file-name matches the value of environment variable ENCINA_CDS_ROOT. Otherwise VSA implies the SdU file system.

For LINE SEQUENTIAL files, you can either specify or default to LSQ, the line sequential file system.

For INDEXED, RELATIVE, and SEQUENTIAL files, you can specify DB2, SdU, SFS, or STL. For SEQUENTIAL files that have fixed and variable-length records, RSD is also a valid choice.

If you do not specify the file system for a given file, its file system is determined according to the precedence described in the related reference about precedence.

You associate an internal file-name to a system file-name using one of these items in the ASSIGN clause, as described below:

Identifying files using a user-defined word:

To associate an internal file-name to a system file-name using a user-defined word, you can code a SELECT clause and an ASSIGN clause in the following form:

SELECT internalFilename ASSIGN TO userDefinedWord

The association of the internal file-name to a system file-name is completed at run time. The following example shows how you associate internal file-name LOG-FILE with file Transaction.log in the STL file system by using environment variable TRANLOG:

SELECT LOG-FILE ASSIGN TO TRANLOG
. . . 
export TRANLOG=STL-Transaction.log

If an environment variable TRANLOG has not been set or is set to the null string when an OPEN statement for LOG-FILE is executed, LOG-FILE is associated with a file named TRANLOG in the default file system.

Identifying files using a literal:

To associate an internal file-name to a system file-name using a literal, you can code a SELECT clause and an ASSIGN clause in the following form:

SELECT internalFilename ASSIGN TO 'fileSystemID-systemFilename'

In the literal, you specify the system file-name and optionally the file system.

The following example shows how you can associate an internal file-name myFile with file extFile on server sfsServer in the SFS file system:

SELECT myFile ASSIGN TO 'SFS-/.:/cics/sfs/sfsServer/extFile'

Because the literal explicitly specifies the file system and the system file-name, the file association can be resolved at compile time.

For further details about coding the ASSIGN clause, see the appropriate related reference.

Identifying files using a data-name:

To associate an internal file-name to a system file-name using a data-name, code a SELECT clause and an ASSIGN clause in the following form:

SELECT internalFilename ASSIGN USING dataName

Move the file-system and file-name information to the variable dataName before the file is processed.

The following example shows how you can associate internal file-name myFile with file FebPayroll in the SdU file system:

SELECT myFile ASSIGN USING fileData
. . . 
01 fileData PIC X(50).
. . . 
    MOVE 'SdU-FebPayroll' TO fileData
    OPEN INPUT myFile

The association is resolved unconditionally at run time.

related references  
Precedence of file-system determination  
Runtime environment variables
  
ASSIGN clause (COBOL for AIX Language Reference)