z/OS TSO/E CLISTs
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Reading a record from a file

z/OS TSO/E CLISTs
SA32-0978-00

To read a record from an open file, use a GETFILE statement. The CLIST creates a variable of the same name as the file name and places the record into it. As long as the file remains open, successive GETFILE statements read successive records from the file. When the end of the file has been reached, &LASTCC contains the error code 400. For information about how to detect and handle end-of-file conditions, see End-of-File processing.

Assume a data set called D58TAN1.CHECKS.DATA contains the following records:
200BLACKBUY
449REFY
450YARRUM
To read the records into three variables, you can code the following:
⋮
  (error routine)
⋮
allocate file(paycheks) da('d58tan1.checks.data') shr reu
OPENFILE PAYCHEKS               /* Defaults to INPUT       */
SET COUNTER=1
DO WHILE &COUNTER ¬> 3
 GETFILE PAYCHEKS               /* Read a record           */
 SET EMPLOYEE&COUNTER=&PAYCHEKS /* Store the record        */
 SET COUNTER=&COUNTER+1         /* Increase counter by one */
END
CLOSFILE PAYCHEKS               /* Close the file          */

If you use GETFILE to read data from the terminal, the data is translated to uppercase, and the terminal user must end the data with a symbol that the CLIST recognizes as an end-of-file.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014