Library View Topics Framed Contents Revised Topics Previous Topic Next Topic Search Search ResultsPrevious Topic MatchNext Topic Match Notes List Notes Print Download No PDF Handheld DisconnectedHandheld ConnectedHelp

6.2.28 READ Statement



For sequential access, the READ statement makes the next logical record from a file available to the object program. For random access, the READ statement makes a specified record from a direct-access file available to the object program.

When the READ statement is executed, the associated file must be open in INPUT or I-O mode.


    ___ Format 1--Sequential Retrieval _____________________________________ 
   |                                                                        |
   | >>__READ__file-name-1__ _______________ __ ________ _________________> |
   |                        |_NEXT__________|  |_RECORD_|                   |
   |                        |            (1)|                               |
   |                        |_ PREVIOUS ____|                               |
   |                                                                        |
   | >__ ____________________ ____________________________________________> |
   |    |_INTO__identifier-1_|                                              |
   |                                                                        |
   | >__ _____________________________________ ___________________________> |
   |    |_ ____ __END__imperative-statement-1_|                             |
   |      |_AT_|                                                            |
   |                                                                        |
   | >__ __________________________________________ __ __________ _______>< |
   |    |_NOT__ ____ __END__imperative-statement-2_|  |_END-READ_|          |
   |           |_AT_|                                                       |
   |                                                                        |
   | Note:                                                                  |
 X | (1)  PREVIOUS is only supported on AIX, OS/2, and Windows.             |
   |                                                                        |
   |________________________________________________________________________|


    ___ Format 2--Random Retrieval _________________________________________ 
   |                                                                        |
   | >>__READ__file-name-1__ ________ __ ____________________ ____________> |
   |                        |_RECORD_|  |_INTO__identifier-1_|              |
   |                                                                        |
   | >__ __________________________ ______________________________________> |
   |    |_KEY__ ____ __data-name-1_|                                        |
   |           |_IS_|                                                       |
   |                                                                        |
   | >__ __________________________________________ ______________________> |
   |    |_INVALID__ _____ __imperative-statement-3_|                        |
   |               |_KEY_|                                                  |
   |                                                                        |
   | >__ ______________________________________________ __ __________ ___>< |
   |    |_NOT INVALID__ _____ __imperative-statement-4_|  |_END-READ_|      |
   |                   |_KEY_|                                              |
   |                                                                        |
   |________________________________________________________________________|
file-name-1
Must be defined in a Data Division FD entry.

NEXT RECORD
Reads the next record in the logical sequence of records. NEXT is optional when ACCESS MODE IS SEQUENTIAL; it has no effect on READ statement execution.

>_Host_> Under OS/390 and VM, you must specify the NEXT RECORD phrase for files in dynamic access mode, which are retrieved sequentially. <_Host_<


X >_Workstation_> Under AIX, OS/2, and Windows, you must specify either
X the NEXT or PREVIOUS phrase for files in dynamic access mode, which
X are retrieved sequentially. <_Workstation_<


X PREVIOUS RECORD (Workstation Only)

X >_Workstation_> Reads the previous record in the logical sequence of
X records. PREVIOUS applies to indexed and relative files with DYNAMIC
X access mode.


X You must specify either the NEXT or PREVIOUS phrase for files in
X dynamic access mode, which are retrieved sequentially.


X If you specify READ...PREVIOUS and no previous logical record exists,
X the AT END condition occurs and the READ statement is unsuccessful.


X When you specify READ...PREVIOUS, the setting of the file position
X indicator is used to determine which record to make available
X according to the following rules:

INTO Identifier-1
Identifier-1 is the receiving field.

The result of the execution of a READ statement with the INTO phrase is equivalent to the application of the following rules in the order specified:

The INTO phrase can be specified in a READ if:

The record areas associated with file-name-1 and identifier-1 must not be the same storage area.


X Identifier-1 (the record area) can be a DBCS or floating point data
X item.


X Multiple non-alphanumeric records can be specified for file-name-1.
X Identifier-1 need not describe a group item or an elementary
X alphanumeric item. The following rules apply:

  1. X If the file referenced by file-name-1 is described as containing
    X variable-length records, or as a QSAM file with RECORDING MODE 'S'
    X or 'U', a group move will take place.
    
    
  2. X If the file referenced by file-name-1 is described as containing
    X fixed-length records, the movement will take place according to
    X the rules for the MOVE statement, using, as a sending field
    X description, the record that specifies the largest number of
    X character positions. If more than one such record exists, the
    X sending field record selected will be the one among those records
    X that appears first under the description of file-name-1.
    
    


X >_OS/2_> Under OS/2, you can only READ a file with LOCK MODE AUTOMATIC if
X no other file connector holds a lock on the record you are trying to
X access. If the record is locked by another file connector, the READ
X statement is unsuccessful and the file status is set to indicate "record
X locked." For sequential files, the setting of the file position indicator
X is unaffected. <_OS/2_<

Subtopics:



Previous Topic Next Topic Copyright IBM Corp. 1991, 1998

IBM Library Server Copyright 1989, 2005 IBM Corporation. All rights reserved.





Return to library:   z/OS | z/OS.e | TPF | z/VSE | z/VM | IBM Hardware | IBM System z Redbooks
Glossary:   IBM terminology
Publications:   How to order publications
Readers:   Download IBM Library Reader | Download IBM Softcopy Reader | Download Adobe® Acrobat® Reader®
Library management:   Download IBM Softcopy Librarian
Contacts:   Contact z/OS


Adobe, the Adobe logo, Acrobat, the Acrobat logo, and Acrobat Reader are registered trademarks of Adobe Systems incorporated.