Javascript required
Skip to content Skip to sidebar Skip to footer

What Is Read Statement in Computer Science

READ

READ
Scan

ALL
(operand1)

[MULTI-FETCH-clause] [ RECORDSouthward] [IN] [FILE] view-proper noun
  [Countersign= operand2]
  [Zippo= operand3]
  [WITH REPOSITION]
  [sequence/range-specification]
  [STARTING WITH ISN= operand4]
  [[IN] SHARED HOLD [Way=pick]]
  [SKIP [ RECORDDue south] IN HOLD]
  [WHERE logical-condition]
   argument
END-READ (structured manner only)
LOOP (reporting mode merely)

This document covers the following topics:

  • Office

  • Syntax Description

  • Arrangement Variables Available with READ

  • Examples

For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.

Related Statements: Accept/Reject | AT Suspension | AT Commencement OF DATA | AT Cease OF Information | BACKOUT TRANSACTION | BEFORE BREAK PROCESSING | GET TRANSACTION DATA | DELETE | Cease TRANSACTION | FIND | HISTOGRAM | GET | Get Aforementioned | LIMIT | PASSW | PERFORM BREAK PROCESSING | READLOB | RETRY | STORE | UPDATE | UPDATELOB

Belongs to Role Group: Database Admission and Update


Function

The READ statement is used to read records from a database. The records tin can be retrieved in physical sequence, in Adabas ISN sequence, or in the value sequence of a descriptor (key) field. The READ argument causes a processing loop to be initiated.

Run into likewise the post-obit sections in the Programming Guide:

  • READ Argument

  • Loop Processing

  • Referencing of Database Fields Using (r) Notation

Syntax Description

Operand Definition Table:

Operand Possible Structure Possible Formats Referencing Permitted Dynamic Definition
operand1 C Southward N P I B * yes no
operand2 C S A yes no
operand3 C Southward N yes no
operand4 C Due south N P I B * yeah no

* Format B of operand1 and operand4 may be used with a length of less than or equal to 4.

Syntax Element Description:

Syntax Element Description
operand1

Number of Records to be Read:

The number of records to be read may be limited by specifying operand1 (enclosed in parentheses, immediately after the keyword READ) - either equally a numeric constant (in the range from 0 to 4294967295) or equally the name of a numeric variable.

Example:

READ (5) IN EMPLOYEES ...    MOVE 10 TO CNT(N2) READ (CNT) EMPLOYEES  ...

For this statement, the specified limit has priority over a limit prepare with a LIMIT statement.

If a smaller limit is prepare with the contour or session parameter LT, the LT limit applies.

Notes:

  1. If you wish to read a four-digit number of records, specify it with a leading zero: (0nnnn ); because Natural interprets every 4-digit number enclosed in parentheses as a line-number reference to a statement.
  2. operand1 is evaluated when the READ loop is entered. If the value of operand1 is modified within the READ loop, this does non affect the number of records read.
ALL

ALL Choice:

To emphasize that all records are to be read, you can optionally specify the keyword ALL.

The ALL option is used by default if operand1 and ALL are omitted.

MULTI-FETCH-clause

MULTI-FETCH Clause:

Encounter MULTI-FETCH Clause below.

view-name

View Name:

As view-proper noun , you specify the name of a view, which must have been defined either inside a DEFINE Data statement or exterior the plan in a global or local data area.

In reporting manner, view-name is the proper noun of a DDM if no DEFINE Information LOCAL argument is used.

PASSWORD=operand2

Nothing=operand3

PASSWORD and CIPHER Clauses:

These clauses are applicable only to Adabas or VSAM databases. They cannot be used with Entire Organization Server.

The PASSWORD clause is used to provide a countersign when retrieving data from a file which is password-protected.

The CIPHER clause is used to provide a zero key when retrieving information from a file which is enciphered.

Encounter the statements FIND and PASSW for farther information.

WITH REPOSITION

WITH REPOSITION Option:

This selection is used to make the READ statement sensitive for repositioning events. See WITH REPOSITION Selection.

sequence/range-specification

Sequence/Range Specification:

This option specifies the sequence and/or the range of retrieval. Run across Sequence/Range Specification.

STARTING WITH ISN=operand4

STARTING WITH ISN Clause:

This clause applies simply to Adabas and VSAM databases.

Access to Adabas

This clause can be used in conjunction with a READ statement in physical or in logical (ascending/descending) sequence. The value supplied ( operand4 ) represents an Adabas ISN (Internal Sequence Number) and is used to specify a definite record where to showtime the READ loop.

  • Logical Sequence
    Fifty-fifty if documented with an equal character (=), the READ statement does not return only those records with exactly the kickoff value in the corresponding descriptor field, but starts a logical browse in ascending or descending order, beginning with the start value supplied. If some records accept the aforementioned contents in the descriptor field, they will be returned in an ISN-sorted sequence.

    The STARTING WITH ISN clause is some kind of a "second level" selection criterion that applies just if the commencement value matches the descriptor value for the first record. All records with a descriptor value that is the aforementioned as the start value and an ISN that is "less equal"("greater equal" for a descending READ) than the start ISN are ignored by Adabas. The first record returned in the READ loop is either

    • the first record with descriptor = start value and an ISN "greater" ("less" for a descending READ) than the first ISN,

    • or if such a tape does non be, the showtime tape with a descriptor "greater" ("less" for a descending READ) than the start value.

  • Concrete Sequence
    The records are returned in the order in which they are physically stored. If a STARTING WITH ISN clause is specified, Adabas ignores all records until the tape with the ISN that is the same as the start ISN is reached. The first record returned is the next record following the ISN=start ISN record.

Access to VSAM

This clause tin only exist used in physical sequence. The value supplied ( operand4 ) represents a VSAM RBA (relative byte address of ESDS) or RRN (relative tape number of RRDS), which is to be used as a start value for the read operation.

Examples

This clause may be used for repositioning inside a READ loop whose processing has been interrupted, to easily decide the adjacent record with which processing is to proceed. This is particularly useful if the next tape cannot be identified uniquely by any of its descriptor values. It can also be useful in a distributed client/server awarding where the reading of the records is performed by a server program while further processing of the records is performed past a client program, and the records are not processed all in 1 go, only in batches.

For an instance, come across the program REASISND beneath.

[[IN] SHARED HOLD [Way=option]]

SHARED Hold Clause:

Note:
This clause tin can exist used just for admission to Adabas.

This clause can exist used to place records existence read in a "shared hold" state. A tape tin exist put in shared hold by many users at the same time. As long every bit a record is in a shared concord state, information technology is protected from existence updated, because it cannot be set into an exclusive hold past parallel users. This ensures data consistency for the tape data, as no one can update the record while it is being processed.

Specially if the same tape is fetched with multiple statements to read different MU/PE occurrences (Get SAME statement) or to browse over a LOB field in a piecemeal technique (READLOB statement), the shared agree land tin guarantee data stability over this transaction without blocking the record for other users.

Although such a hold state is an efficient way to protect read sequences, information technology is a basic and important matter when to release the record again from this "soft lock". Since this question depends on individual application aspects, different options tin be selected with the MODE subclause.

MODE Pick

Agree Menses

Explanation

C But at the moment of reading the tape. Ensures only that the record version being read has been committed by the last user who updated the record. This pick does not really set a lock in agree land, merely checks just that the tape is non in sectional hold by another user at fourth dimension of read.
Q Until the side by side tape in a sequence is read. Releases the tape from shared hold when
  • the next tape is read in the loop sequence or

  • the loop is terminated or

  • an END TRANSACTION or BACKOUT TRANSACTION is executed.

S Until the logical transaction is terminated. Releases the tape from shared hold when a logical transaction is terminated with an END TRANSACTION or BACKOUT TRANSACTION statement.
MODE=Q and Way=Southward ensure that the record being read cannot be updated concurrently by other users until it has been released from hold once again.

If the Mode subclause is not specified, MODE=C is the default.

Run into also Instance 8 - SHARED HOLD Clause below.

SKIP RECORDS IN Hold

SKIP RECORDS Clause:

Notes:

  1. This clause can exist used only for access to Adabas.
  2. The SKIP Tape IN HOLD functionality simply works when the Natural profile parameter WH is fix to OFF.

Whenever a record is going to be read with concord, a Natural error NAT3145 (Adabas response code 145) might happen if the record is in hold by another user at this time. This occurs if a shared hold is requested and the record is in exclusive concord or if an sectional concur is requested and the record is in either sectional or shared concur.

Although fault NAT3145 is surely the correct reaction to clinch a "clean data processing", sometimes it might be useful if a tape in hold could exist skipped. If it is alright that such a record volition not be candy and the loop processing should go along, the SKIP RECORDS clause should be used.

If the SKIP RECORDS clause is applied, Natural first tries to read the record with hold.

If the record is already in concur and the Natural mistake NAT3145 would occur,

  • no error processing is initiated;

  • the tape (currently in concur by another user) is instantly re-fetched without concur, but not processed in terms of the programme logic;

  • the record which comes next after the skipped record is read with agree and the processing continues.

Encounter also Example 9 - SKIP RECORDS Clause.

WHERE logical-condition

WHERE Clause:

The WHERE clause may be used to specify an additional selection criterion ( logical-condition ) which is evaluated after a value has been read and before any processing is performed on the value (including the AT Interruption evaluation).

The syntax for a logical-status is described in the section Logical Condition Criteria in the Programming Guide.

If a LIMIT statement or a processing limit is specified in a READ statement containing a WHERE clause, records which are rejected as a consequence of the WHERE clause are not counted against the limit.

END-READ

End of READ Statement:

In structured way, the Natural reserved keyword End-READ must be used to terminate the READ statement.

In reporting mode, the Natural argument LOOP is used to terminate the READ argument.

LOOP

MULTI-FETCH Clause

Notation:
This clause tin only be used for Adabas or DB2 databases.

MULTI-FETCH

ON
OFF
[OF] multi-fetch-gene

For more information, see the section MULTI-FETCH Clause (Adabas) in the Programming Guide or Multiple Row Processing (SQL) in the Natural for DB2 part of the Database Management System Interfaces documentation.

WITH REPOSITION Option

Note:
This option can merely be applied if the underlying database is Adabas, VSAM or DL/I.

With a WITH REPOSITION option, yous tin make a READ argument sensitive for repositioning events. This allows you to reposition to another start value within an active READ loop. Processing of the READ statement and then continues with the new start value.

A repositioning outcome is triggered past one of 2 ways when y'all utilize a READ statement with the WITH REPOSITION option:

  1. When an ESCAPE TOP REPOSITION statement is executed. At execution of an ESCAPE Tiptop REPOSITION statement, Natural makes an instant branch to the loop begin and performs a restart; that is, the database repositions to a new record in the file co-ordinate to the current content of the search value variable. At the same time, the loop-counter *COUNTER is reset to nothing.

  2. When a READ loop tries to fetch the next record from the database and the value of the system variable *COUNTER is 0.

    Note:
    If *COUNTER is set to 0 within the active READ loop, processing of the current record is continued; no instant branch to the loop brainstorm is performed.

Functional Considerations

  • If the READ statement has a loop-limit (due east.g. READ (ten) EMPLOYEES WITH REPOSITION ..) and a restart upshot was triggered, the loop gets another 10 new records, no matter how many records where already processed until the repositioning takes identify.

  • If an ESCAPE Top REPOSITION statement is executed, simply the innermost loop is not capable of repositioning (since the WITH REPOSITION keyword is not set in the READ statement or the posted loop statement is anything else just a READ), a corresponding runtime fault is issued.

  • Since the ESCAPE Top statement does not let a reference, you can only initiate a reposition event if the innermost processing loop is a READ ..WITH REPOSITION statement.

  • A reposition upshot does non trigger the execution of the AT START OF DATA section, nor does it trigger the re-evaluation of the loop-limit operand (if information technology is a variable).

  • If the search value was not altered, the loop repositions to the same record like at initial loop beginning.

Sequence/Range Specification

Iii syntax options are available to specify the sequence and/or the range of retrieval.

Syntax Option 1:

[IN] [ Physical ]

ASCCatastrophe
DESCCatastrophe
VARIABLE operand5
DYNAMIC operand5

[SEQUENCE]

Syntax Option ii:

=
EQ
EQUAL TO
[STARTING]FROM

BY
WITH

ISN operand6

THRU
ENDING AT

operand7

Syntax Selection three:

[IN] [LOGICAL]

ASCENDING
DESCCatastrophe
VARIABLEoperand5
DYNAMIC operand5

[SEQUENCE]

By
WITH

descriptor

=
EQ
EQUAL TO
[STARTING]FROM

operand6

THRU
Catastrophe AT

operand7

=
EQ
EQUAL TO
[STARTING]FROM

operand6 TO operand7

<
LT
LESS THAN
>
GT
GREATER THAN
<=
LE
LESS EQUAL
>=
GE
GREATER EQUAL

operand6

Notes:

  1. The syntax options [2] and [3] are non available with Entire Organization Server.
  2. If the comparators of Diagram iii are used, the options ENDING AT, THRU and TO may non exist used. These comparators are also valid for the HISTOGRAM statement.

Operand Definition Tabular array:

Operand Possible Structure Possible Formats Referencing Permitted Dynamic Definition
operand5 Due south A yes no
operand6 C S A North P I F B * D T L yes no
operand7 C S A N P I F B * D T 50 yes no

* Format B of operand6 and operand7 may be used only with a length of less than or equal to 4.

Syntax Element Description:

Syntax Element Clarification
READ IN Physical SEQUENCE

Read in Physical Sequence:

This option is used to read records in the order in which they are physically stored in a database.

Note:
For VSAM databases: READ Physical tin can simply be applied to ESDS and RRDS.

PHYSICAL is the default sequence.

READ By ISN

Read past ISN:

This option is used to read records in the order of Adabas ISNs (internal sequence numbers) or VSAM RBAs (relative byte addresses of ESDS) or RRNs (relative record numbers of RRDS) respectively. (Instead of using the keyword By, you lot may specify the keyword WITH, which would take the same effect).

READ BY ISN can merely be used for Adabas and VSAM databases; for VSAM databases, it is only valid for ESDS and RRDS.

Annotation:
For XML databases: READ Past ISN is used to read XML objects according to the order of Tamino object IDs.

READ IN LOGICAL SEQUENCE

Read in Logical Sequence:

This option is used to read records in the society of the values of a descriptor (key) field.

If you specify a descriptor, the records will be read in the value sequence of the descriptor. A descriptor, subdescriptor, superdescriptor or hyperdescriptor may exist used for sequence control. A phonetic descriptor, a descriptor within a periodic group, or a superdescriptor which contains a periodic-group field cannot be used.

If y'all do non specify a descriptor, the default descriptor as specified in the DDM (field Default Sequence) will exist used.

Notes:

  1. For DL/I databases: The descriptor used must be either the sequence field of a root segment, or a secondary index field. If a secondary alphabetize field is specified, it must also be specified in the PROCSEQ parameter of a PCB. Natural uses this PCB and the corresponding hierarchical structure to process the database. Every bit HDAM databases use a randomizing routine to locate root segments, no sensible results will be returned when using READ LOGICAL for HDAM databases; therefore yous should apply READ PHYSICAL for HDAM databases.
  2. For VSAM databases: LOGICAL is only valid for KSDS with main and alternating keys defined and for ESDS with alternating keys divers.

If the descriptor used for sequence control is defined with null-value suppression (Adabas merely), any record which contains a cipher value for the descriptor will not be read.

If the descriptor is a multiple-value field (Adabas simply), the same tape volition be read multiple times depending on the number of values nowadays.

Notation:
READ IN LOGICAL SEQUENCE is as well discussed in the Programming Guide; see Statements for Database Access, READ Statement.

ASCENDING | DESCENDING | VARIABLE | DYNAMIC SEQUENCE

Ascending/Descending Order:

This clause only applies to Adabas, XML databases, VSAM and SQL databases. In a READ PHYSICAL argument, it tin only be applied to VSAM and DB2 databases.

With this clause, you can determine whether the records are to exist read in ascending sequence or in descending sequence.

  • The default sequence is ascending (which may, just need not, be explicitly specified past using the keyword ASCENDING).

  • If the records are to exist read in descending sequence, yous specify the keyword DESCENDING.

  • If, instead of determining it in advance, you desire to take the option of determining at runtime whether the records are to be read in ascending or descending sequence, y'all either specify the keyword VARIABLE or DYNAMIC, followed past a variable ( operand5 ). operand5 has to be of format/length A1 and tin can contain the value A (for "ascending") or D (for "descending").

    • If keyword VARIABLE is used, the reading direction (value of operand5 ) is evaluated at get-go of the READ processing loop and remains the same until the loop is terminated, regardless if the operand5 field is contradistinct in the READ loop or not.

    • If keyword DYNAMIC is used, the reading management (value of operand5 ) is evaluated earlier every tape fetch in the READ processing loop and may be changed from record to tape. This allows to change the scroll sequence from ascending to descending (and vice versa) at any place in the READ loop.

STARTING FROM ... ENDING AT/TO

STARTING FROM/Ending AT Clauses:

The STARTING FROM and Ending AT clauses are used to limit reading to a fix of records based on a user-specified range of values.

The STARTING FROM clause (= or EQ or EQUAL TO or [STARTING] FROM) determines the starting value for the read operation. If a starting value is specified, reading will begin with the value specified. If the starting value does not exist in the file, the next higher (or lower for a DESCENDING read) value volition be used. If no higher (or lower for DESCENDING) value exists, the loop will non exist entered.

In order to limit the records to an end-value, you may specify an ENDING AT clause with the terms THRU, Ending AT or TO, that imply an inclusive range. Whenever the read descriptor field exceeds the cease-value specified, an automatic loop termination is performed. Although the bones functionality of the TO, THRU and Ending AT keywords looks quite similar, internally they differ in how they work.

THRU/Ending AT

THRU/ENDING AT Pick:

If THRU or Ending AT is used, only the start-value is supplied to the database, but the end-value cheque is performed by the Natural runtime system, after the record is returned by the database. If the read direction is ASCENDING, you have to supply the lower value every bit the offset-value and the higher-value as the end-value, since the offset-value represents the value (and record) returned first in the READ loop. However, if you invoke a backwards read (DESCENDING), the higher value has to announced in the first-value and the lower-value in the end-value.

Internally, to determine the terminate of the range to exist read, Natural reads one record beyond the end-value. If you take left the READ loop because the end-value has been reached, exist enlightened that this last record is in fact non the last tape within the demanded range, only the first tape beyond that range (except if the file does non contain a further record after the last result record).

The THRU and ENDING AT clauses can exist used for all databases which back up the READ or HISTOGRAM statements.

TO

TO Option:

If the keyword TO is used, both the start-value and the cease-value are sent to the database, and Natural does not perform checks for value ranges. If the end-value is exceeded, the database reacts the same as when "terminate-of-file" is reached, and the database loop is exited. Since the complete range checking is done by the database, the lower-value (of the range) is always supplied in the kickoff-value and the higher-value filled into the end-value, regardless if you are browsing in ASCENDING or DESCENDING social club.

Notes on Functional Differences between THRU/Catastrophe AT and TO

The post-obit list describes the functional differences betwixt the usage of the THRU/ENDING AT and TO options.

THRU/ENDING AT TO
When the READ loop terminates because the finish-value has been reached, the view contains the commencement record "out-of-range". When the READ loop terminates because the end-value has been reached, the view contains the last tape of the specified range.
If a finish-value variable is modified during the READ loop, the new value volition exist used for end-value check on next record being read. The end-value variable will only be evaluated at READ loop offset. All further modifications during the READ loop have no effect.
An incorrect range (for example, READ .. = 'B' THRU 'A') does not cause a database error, but just returns no tape. An incorrect range results in a database mistake (for example, Adabas RC=61), because a value range must not be supplied in descending club.
If a READ .. DESCENDING is used with start- and end-value, the offset value is used to position in the file, whereas the end-value is used by Natural to bank check for "end-of-range". Therefore the start-value is college than (or equal to) the end-value. Since both values are passed to the database, they have to appear in ascending order. In other words, the start-value is lower than (or equal to) the finish-value, no affair if you are reading in ascending or descending society.
In order to check for range overflow, the descriptor value has to appear in the underlying database view; that is, information technology must be returned in the tape buffer. The descriptor is non required in the record fields returned.
The end-value check for an Adabas multi-value field (MU-field) or a sub-/super-/hyper-descriptor is not possible and leads to syntax mistake NAT0160 at program compilation. You may specify an end-value for MU-fields and sub-/super-/hyper-descriptors.
Can be used for all databases. Can be used for all databases.

Note:
The result of READ/HISTOGRAM THRU/ENDING AT might differ from the effect of READ/HISTOGRAM TO if Natural and the accessed database reside on different platforms with different collating sequences.

Organization Variables Bachelor with READ

The Natural system variables *ISN and *COUNTER are available with the READ statement.

The format/length of these arrangement variables is P10. This format/length cannot be changed.

The usage of the organisation variables is illustrated beneath.

System Variable Explanation
*ISN

The system variable *ISN contains the Adabas ISN of the record currently being processed.

Notes:

  1. For VSAM databases, *ISN contains either the RRN (for RRDS) or the RBA (for ESDS) of the current record.
  2. For Tamino, *ISN contains the XML object ID.
  3. For DL/I and SQL databases and with Unabridged System Server, *ISN is non bachelor.
*COUNTER The system variable *COUNTER contains the number of times the processing loop has been entered.

Examples

  • Instance ane - READ Statement

  • Case 2 - READ WITH REPOSITION

  • Example 3 - Combining READ and FIND Statements

  • Example 4 - DESCENDING Option

  • Case 5 - VARIABLE Option

  • Example vi - DYNAMIC Selection

  • Example 7 - STARTING WITH ISN Clause

  • Example 8 - SHARED HOLD Clause

  • Case nine - SKIP RECORDS Clause

Example 1 - READ Argument

** Example 'REAEX1S': READ (structured mode)                             ************************************************************************ DEFINE DATA LOCAL                                                        ane EMPLOY-VIEW VIEW OF EMPLOYEES                                            2 PERSONNEL-ID                                                           2 NAME                                                                 1 VEHIC-VIEW VIEW OF VEHICLES                                              2 PERSONNEL-ID                                                           ii MAKE                                                                 Finish-DEFINE                                                               *                                                                        LIMIT 3                                                                  *                                                                        WRITE 'READ IN PHYSICAL SEQUENCE'          READ Use-VIEW IN PHYSICAL SEQUENCE          Brandish NOTITLE PERSONNEL-ID Proper noun *ISN *COUNTER          END-READ          *                                                                        WRITE / 'READ IN ISN SEQUENCE'          READ Utilise-VIEW BY ISN STARTING FROM ane ENDING AT 3          DISPLAY         PERSONNEL-ID NAME *ISN *COUNTER          Terminate-READ          *                                                   WRITE / 'READ IN Proper name SEQUENCE'          READ EMPLOY-VIEW BY NAME          DISPLAY         PERSONNEL-ID NAME *ISN *COUNTER          END-READ          *                                                   WRITE / 'READ IN NAME SEQUENCE STARTING FROM ''M'''          READ EMPLOY-VIEW Past NAME STARTING FROM 'K'          DISPLAY         PERSONNEL-ID Name *ISN *COUNTER          END-READ          *                                                   Stop

Output of Program REAEX1S:

PERSONNEL         NAME            ISN         CNT         ID                                                  --------- -------------------- ----------- -----------                                                        READ IN PHYSICAL SEQUENCE                              50005800  ADAM                           1           1 50005600  MORENO                         2           2 50005500  BLOND                          3           iii                                                        READ IN ISN SEQUENCE                                   50005800  ADAM                           1           1 50005600  MORENO                         2           2 50005500  BLOND                          3           three                                                        READ IN NAME SEQUENCE                                  60008339  ABELLAN                      478           1 30000231  ACHIESON                     878           2 50005800  ADAM                           one           iii                                                        READ IN Name SEQUENCE STARTING FROM 'M'                30008125  MACDONALD                    923           i 20028700  MACKARNESS                   765           two 40000045  MADSEN                       508           3

Equivalent reporting-manner instance: REAEX1R.

Example two - READ WITH REPOSITION

Ascertain Data LOCAL 1 MYVIEW VIEW OF ...   2 NAME 1 #STARTVAL (A20) INIT <'A'> 1 #ATTR     (C) Terminate-Define ... Fix KEY PF3 ...          READ MYVIEW WITH REPOSITION Past NAME = #STARTVAL          INPUT (IP=OFF Advertizing=O) 'Name:' Proper noun /     'Enter new offset value for repositioning:' #STARTVAL (AD=MT CV=#ATTR) /     'Press PF3 to stop'   IF *PF-KEY = 'PF3'     So STOP   Terminate-IF   IF #ATTR MODIFIED     And so          ESCAPE TOP REPOSITION          END-IF          END-READ          ...
Ascertain Information LOCAL 1 MYVIEW VIEW OF ...   2 NAME 1 #STARTVAL (A20) INIT <'A'> 1 #ATTR     (C) END-DEFINE ... SET KEY PF3 ...          READ MYVIEW WITH REPOSITION BY Name = #STARTVAL          INPUT (IP=OFF AD=O) 'Proper noun:' NAME /     'Enter new start value for repositioning:' #STARTVAL (AD=MT CV=#ATTR) /     'Press PF3 to stop'   IF *PF-Cardinal = 'PF3'     THEN STOP   Finish-IF   IF #ATTR MODIFIED     Then          RESET *COUNTER          END-IF          End-READ          ...

Example three - Combining READ and FIND Statements

The following programme reads records from the EMPLOYEES file in logical sequential gild based on the values of the descriptor Proper noun. A FIND statement is then issued to the VEHICLES file using the personnel number from the EMPLOYEES file as search criterion. The resulting report shows the proper name (read from the EMPLOYEES file) of each person read and the model of automobile (read from the VEHICLES file) owned by this person. Multiple lines with the same name are produced if the person owns more than one motorcar.

** Example 'REAEX2': READ and Find combination                           ************************************************************************ Ascertain Information LOCAL                                                        one Use-VIEW VIEW OF EMPLOYEES                                            2 PERSONNEL-ID                                                           2 Beginning-NAME                                                             2 Name                                                                   2 Urban center                                                                 one VEH-VIEW VIEW OF VEHICLES                                                2 PERSONNEL-ID                                                           2 Brand                                                                 Terminate-DEFINE                                                               *                                                                        LIMIT 10                                                                 *          RD. READ EMPLOY-VIEW BY NAME STARTING FROM 'JONES'          SUSPEND IDENTICAL SUPPRESS          FD. Detect VEH-VIEW WITH PERSONNEL-ID = PERSONNEL-ID (RD.)          IF NO RECORDS Establish                                                        ENTER                                        Terminate-NOREC                                      DISPLAY NOTITLE (ES=OFF IS=ON ZP=ON AL=15)             PERSONNEL-ID (RD.)                             Outset-NAME (RD.)                               MAKE (FD.) (IS=OFF)          END-FIND          END-READ          END

Output of Program REAEX2:

PERSONNEL      FIRST-NAME         MAKE             ID                                        --------------- --------------- ---------------                                                 20007500        VIRGINIA        CHRYSLER        20008400        MARSHA          CHRYSLER                                        CHRYSLER        20021100        ROBERT          General MOTORS  20000800        LILLY           FORD                                            MG              20001100        EDWARD          General MOTORS  20002000        MARTHA          GENERAL MOTORS  20003400        LAUREL          GENERAL MOTORS  30034045        KEVIN           DATSUN          30034233        GREGORY         FORD            11400319        MANFRED

Example iv - DESCENDING Choice

** Instance 'READSCND': READ (with DESCENDING SEQUENCE)                   ************************************************************************ Define Information LOCAL                                                        one EMPL VIEW OF EMPLOYEES                                                   2 Proper name                                                                   2 FIRST-NAME                                                             2 Birth                                                                Finish-Ascertain                                                               *          READ (10) EMPL IN DESCENDING SEQUENCE BY Proper name FROM 'ZZZ'          Display *ISN Proper noun FIRST-Name Nativity (EM=YYYY-MM-DD)          END-READ          END

Example 5 - VARIABLE Option

** Example 'REAVSEQ':  READ  (with VARIABLE SEQUENCE)                    ************************************************************************ DEFINE Data LOCAL                                                        1 EMPL VIEW OF EMPLOYEES                                                   2 NAME                                                                   2 FIRST-Name                                                             ii BIRTH                                                                *                                                                        1 #DIR        (A1)                                                       i #STARTVALUE (A20)                                                      END-DEFINE                                                               *                                                                        SET KEY PF7 PF8                                                          *                                                                        INPUT 'Select READ direction'                                               // 'Printing' 08T 'PF7' (I)                  21T 'to read backward'          /         08T 'PF8' (I) 'or' 'ENTER' (I) 21T 'to read forward'       *                                                                        IF *PF-KEY = 'PF7'                                                         MOVE 'D'   TO #DIR                                   Motion 'ZZZ' TO #STARTVALUE                          ELSE                                                   MOVE 'A' TO #DIR                                     MOVE 'A' TO #STARTVALUE                            END-IF                                               *          READ (10) EMPL IN VARIABLE #DIR SEQUENCE                BY NAME FROM #STARTVALUE          Brandish *ISN Name FIRST-Proper noun BIRTH (EM=YYYY-MM-DD)          Cease-READ          END

Example half-dozen - DYNAMIC Selection

Ascertain DATA LOCAL 1 #Direction (A1) INIT <'A'>   /* 'A' = ASCENDING ane #EMPVIEW VIEW OF EMPLOYEES 2 Proper noun ... END-DEFINE ...          READ #EMPVIEW IN DYNAMIC #Management SEQUENCE BY NAME = 'SMITH'          INPUT (Advertisement=O) NAME        / 'Press PF7 to scroll in DESCENDING sequence'        / 'Printing PF8 to curlicue in ASCENDING  sequence'    ..    IF *PF-KEY = 'PF7' THEN MOVE 'D' TO #Direction Terminate-IF    IF *PF-Fundamental = 'PF8' THEN MOVE 'A' TO #Direction END-IF          Stop-READ          ...

Instance 7 - STARTING WITH ISN Clause

** Case 'REASISND': READ  (with STARTING WITH ISN)                    ************************************************************************ Ascertain DATA LOCAL                                                        1 EMPL VIEW OF EMPLOYEES                                                   two Name                                                                   two Kickoff-Proper name                                                             two Nativity                                                                *                                                                        1 #DIR      (A1)                                                         i #STARTVAL (A20)                                                        ane #STARTISN (N8)                                                         END-Ascertain                                                               *                                                                        Gear up KEY PF3 PF7 PF8                                                      *                                                                        Motion 'ADKINSON' TO #STARTVAL                                             *          READ (9) EMPL By Proper noun = #STARTVAL          WRITE *ISN NAME FIRST-Proper name Nascence (EM=YYYY-MM-DD) *COUNTER                IF *COUNTER = five And so                                           MOVE NAME TO #STARTVAL                                       MOVE *ISN TO #STARTISN                                     END-IF          Stop-READ          *                                                            #DIR := 'A'                                                  *                                                            Repeat                      READ EMPL IN VARIABLE #DIR  Past Proper noun = #STARTVAL                        STARTING WITH ISN = #STARTISN                    MOVE Name TO #STARTVAL                                       Movement *ISN TO #STARTISN                                       INPUT NO ERASE  (IP=OFF Advertizing=O)                                     15/01 *ISN  NAME  Commencement-NAME  Nascence (EM=YYYY-MM-DD)            //  'Direction:' #DIR                                        //  'Press PF3 to finish'                                      /   '      PF7 to go step dorsum'                              /   '      PF8 to become step frontward'                           /   '      ENTER to go on in that management'     /*                                                         IF *PF-KEY = 'PF7' AND #DIR = 'A'                            Motility 'D' TO #DIR                                           ESCAPE BOTTOM                                            END-IF                                                     IF *PF-Key = 'PF8' AND #DIR = 'D'                            Move 'A' TO #DIR                                           ESCAPE BOTTOM                                            END-IF                                                     IF *PF-KEY = 'PF3'                                           STOP                                                     Stop-IF          END-READ          /*                                                         IF *COUNTER(0290) = 0                                        Cease                                                     END-IF                                                   Terminate-REPEAT                                                 END

Example 8 - SHARED HOLD Clause

          READ EMPL-VIEW WITH NAME = ...               IN SHARED Concord Way=Q          /* Record in shared agree until side by side tape is read.    ...      GET EMPL-VIEW  *ISN      /* The record remains unchanged!    ...          Terminate-READ        

Example 9 - SKIP RECORDS Clause

          READ EMPL-VIEW WITH Name = ...          /* Records found are put in hold while reading.          SKIP RECORDS IN HOLD          /* Records already held past other users are skipped   ...                           /* to prevent error NAT3145.   UPDATE   END TRANSACTION          END-READ        

masonyourall.blogspot.com

Source: https://documentation.softwareag.com/natural/nat824mf/sm/read.htm