• Aucun résultat trouvé

OPEN FILE(OLDMASTER);

Dans le document PL/I System/360 (Page 100-103)

Data Sets

2. OPEN FILE(OLDMASTER);

3. READ FILE (DETAIL) ••• ;

When statement number 1 is executed, the file name MASTER is taken to be the same as the ddname of a DO statement in the current

job step. When statement number 2 is executed, the name OLDMASTE is taken to be the same as the ddname of a DO statement in the current job step. (The first eight characters of a file name form the ddname.

Note, however, that if OLDMASTER is an external name, i t will be shortened by the

~This does not apply to TRANSIENT files;

the association of a TRANSIENT file with a data set is direct and does. not involve job control language (except that ajOD DUMMY statement is given for each TRANSIENT

file). See "Teleprocessing" in Chapter 10,

"Record-Oriented Transmission."

compiler to OLDMTER for use within the program.) If statement number 3 causes implicit ope~ing of the file DETAIL, the name DETAIL 1S taken to be the same as the ddname of a DO statement in the current job step.

In each of the above cases, a

corresponiing DO statement must appear in the job stream; otherwise, the

UNDEFINEDFILE condition would be raised.

The three DO statements would appear, in part, as follows:

1. //MASTER DO oSNAME= •••

2. //OLoMASTE DO DSNAME= •••

3. //DETAIL DO DSNAME=. , ••

If a file is opened explicitly by an OPEN statement that includes a TITLE

option, the ddname is taken from the TITLE option, and the file name is not used outside the program,. The TITLE option appears in an OPEN statement in the following format:

OPEN FiLE (file-name) TITLE (expression).;

The expression in the TITLE option is evaluated and, if necessary, converted to a character string, that is assumed to be the ddname identifying the appropriate data set. If the character string is longer than eight characters" only the first eight characters are used. The following OPEN statement illustrates how the TITLE option might be used:

OPEN FILE(DETAIL) TITLE('DETAIL1');

If this statement were executed, there must be a DO statement in the current job step with DETAILl as its ddname. I t might appear, in part, as follows:

/ /DETAILl DO DSNAME=DETAILA, •••

Thus, the data set DETAILA is associated with the file DETAIL through the ddname DETAIL1.

Although a data set name represents a specific collection of data, the file name can, at different times, represent entirely different data sets. In the above example of the OPEN statement, whatever data set is named in the DSNAME parameter of the DO statement DETAILl is the one that is associated with DETAIL at the time i t is opened.

Use of the TITLE option allows a

programmer to choose dynamically" at open time, one among several data sets to be associated with a particular file name.

Consider the following example:

DECLARE 1 INREC, 2 FIELD 1 ••• ,

2 FILE_IDENT CHARACTER(S), DETAIL FILE INPUT ••• ,

MASTER FILE INPUT ••• ; OPEN FILE(OETAIL);

READ FILE (DETAIL) INTO (INREC);

OPEN FILE (MASTER) TITLE(FILE_IDENT);

Assume that the program containing these statements is used to process several different detail data sets, each of which has a different cO'rresponding master data set. Assume, furt~ler, that the first

record of each detail data set contains, as its last data item, a character string that identifies the appropriate master data set.

The following DO statements might appear in the current job step:

//DETAIL DD DSNAME=, •••

//MASTER1A DD DSNAME=MASTER1A •••

//MASTER1B DD DSNAME=MASTER1B •••

//MASTER1C DD DSNAME=MASTER1C •••

In this case, MASTER1A, MASTER1B, and MASTER1C represent three different master files. The first record of DETAIL would contain as its last item, either

'MASTER1A', 'MASTER1B', or'MASTER1C', which is assigned to the character-string variable FILE IOENT. When the OPEN

statement is executed to open the file MASTER, the current value of FILE IDENT would be taken to be the ddname, and the appropriate data set identified by that ddname would be associated with the file name MASTER.

Another similar use of the TITLE option is illustrated in the following statements:

DCL IDENT(3) CHAR(l) INIT (. A " , H', , C ' ) : DO I

=

1 TO 3:

OPEN FILE(MASTER)

TITLE (' MASTERl'

II

1DENT (I»;

CLOSE FILE(MASTER);

END;

In this example, IDENT is declared as a character-string array with three elements having as values the specific character strings 'A', 'B', and

'ct.

When MASTER is opened during the first iteration of the DO-group, the character constant 'MASTER1' is concatenated with the value of the first element of IDENT, and the associated ddname is taken to be MASTERlA. After processing, the file is closed, dissociating the file

name and the ddname.. During th~ second iteration of the group, MASTER is opened again. This time, how~ver, the value of the second element of IDEN'£ is taken, and MASTER is associated with the ddname MASTER1B.. Similarily, during the final iteration of the group, MASTER is

associated with the ddname MASTERlc.

Note: The character set of the job control language does not contain the break

character (_). Consequently, this

character cannot appear in ddnames. Care should thus be taken to avoid using break characters among the first eight characters of file names, unless the file is to be opened with a TITLE option with a valid ddname as its expression. The alphabetic extender characters $" Ii), and #, hCMever, are valid for ddnames, and can begin a DDNAME.

The CLOSE statement

The basic form of the CLOSE statement is:

CLOSE FILE (file-name)

[,FILE (file-name)] ••• :

Executing a CLOSE statement dissociates the specified file from the data set with which i t became associated when the file was opened. The CLOSE statement also

dissociates from the file all attributes established for i t by the implicit or explicit opening process. If desired, new attributes may be specified for the file name in a subsequent OPEN statement.

However, all attributes explicitly given to the file name in a DECLARE statement remain in effect.

As with the OPEN statement, closing more than one file with a single CLOSE statement can save execution time, but i t may require the use of more storage than would

otherwise be needed.

Note: Closing an already closed file or opening an already opened file has no effect apart from increasing the execution time of the program.

STANDARD FILES

Two standard files are provided that can be used by any PL/1 program. One is the

standard input file SYSIN, and the other is the standard output file SYSPRINT. These files need not be declared or opened

explicitly; a standard set of attributes is applied automatically. For SYS1N, the

attributes are STREAM INPUT, and for SYSPRINT they are STREAM OUTPUT PRINT.

Both file names, SYSIN and SYSPRINT, are assumed to have the EXTERNAL attribute, even though SYSPRINT contains more than seven characters.

The file names need not be explicitly stated in GET and PUT statements when these files are to be used. GET and PUT

statements that do not name a file are equivalent to:

GEl' "C'TT"C" ICVCTlI.T\ .L ... ~ ,....,~U.LJ. .. , • • • ,

PUT FILE(SYSPRINT) •• ~;

Any other references to SYSIN and SYSPRINT (such as in ON statements or in

record-oriented statements) must be stated explicitly.

The identifiers SYSIN and SYSPRINT are not reserved for the specific purposes described above. They can be used for other purposes than identifying standard files. Other attributes can be applied to them, either explicitly or contextually, but the PRINT attribute is applied automatically to SYSPRINT when i t is

declared as a file name with the STREAM and OUTPUT attributes, unless the INTERNAL attribute is declared for i t .

Note: - Special care must be taken when SYSIN or SYSPRINT is declared as anything other than a STREAM file.. The F Compiler causes, in effect, the identifier SYSIN to be inserted into each GET statement in which no file name is explicitly stated and the identifier SYSPRINT to be inserted into each PUT statement in which no file name is eAp licitly stated. Consequently.

following would be in error:

the

DECLARE. (SYSIN. SYSPRINT) FIXED DECIMAL (4,,2);

GET LIST (A,B,C);

PUT LIST (D~E,F);

The identifier SYSIN would be inserted into the GET statement" and SYSPRINT in the PUT statement. In this case, however, they would not refer to the standard files, but to the fixed-point variables declared in the block .•

Dans le document PL/I System/360 (Page 100-103)