A data set accessed using stream-oriented data transmission need not have been created by stream-oriented data transmission, but it must have CONSECUTIVE organization, and all the data in it must be in character or graphic form. You can open the associated file for input, and read the records the data set contains; or you can open the file for output, and extend the data set by adding records at the end.
To access a data set, you must use one of the following to identify it:
The following paragraphs describe the essential information you must include in the DD statement, and discuss some of the optional information you can supply. The discussions do not apply to data sets in the input stream.
When your application accesses an existing STREAM file, PL/I must obtain a record-length value for that file. The value can come from one of the following sources:
If you are using an existing OUTPUT file, or if you supply a RECSIZE value, PL/I determines the record-length value as described in Creating a data set with stream I/O.
PL/I uses a default record-length value for an INPUT file when:
When using stream-oriented data transmission to access a data set, you do not need to know the record format of the data set (except when you must specify a block size); each GET statement transfers a discrete number of characters or graphics to your program from the data stream.
If you do give record-format information, it must be compatible with the actual structure of the data set. For example, if a data set is created with F-format records, a record size of 600 bytes, and a block size of 3600 bytes, you can access the records as if they are U-format with a maximum block size of 3600 bytes; but if you specify a block size of 3500 bytes, your data will be truncated.
The program in Figure 26 reads the data set created by the program in Figure 24 and uses the file SYSPRINT to list the data it contains. (For details on SYSPRINT, see Using SYSIN and SYSPRINT files.) Each set of data is read, by the GET statement, into two variables: FREC, which always contains 45 characters; and VREC, which always contains 35 characters. At each execution of the GET statement, VREC consists of the number of characters generated by the expression 7*NUM, together with sufficient blanks to bring the total number of characters to 35. The DISP parameter of the DD statement could read simply DISP=OLD; if DELETE is omitted, an existing data set will not be deleted.
//EX7#5 JOB
//STEP1 EXEC IBMZCBG
//PLI.SYSIN DD *
PEOPLE: PROC OPTIONS(MAIN);
DCL WORK FILE STREAM INPUT,
1 REC,
2 FREC,
3 NAME CHAR(19),
3 NUM CHAR(1),
3 SERNO CHAR(7),
3 PROF CHAR(18),
2 VREC CHAR(35),
IN CHAR(80) DEF REC,
EOF BIT(1) INIT('0'B);
ON ENDFILE(WORK) EOF='1'B;
OPEN FILE(WORK);
GET FILE(WORK) EDIT(IN,VREC)(A(45),A(7*NUM));
DO WHILE (¬EOF);
PUT FILE(SYSPRINT) SKIP EDIT(IN)(A);
GET FILE(WORK) EDIT(IN,VREC)(A(45),A(7*NUM));
END;
CLOSE FILE(WORK);
END PEOPLE;
/*
//GO.WORK DD DSN=HPU8.PEOPLE,DISP=(OLD,DELETE)