Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

Format

Example

stream-name

on-error

statement

RDB/VMS Relational Database Operator FETCH — VMS RDB_3.1A

 Advances the pointer for a record stream to the next record of a
 relation.  Once you have established and opened a stream with the
 START_STREAM statement, use the FETCH statement to establish the
 first record in a relation as the current record.  After that, each
 FETCH statement makes the next record in the stream the current one.
 The FETCH statement only advances the pointer in a record stream.
 You must use other data manipulation statements to manipulate each
 record.  For instance, you might use FETCH to advance the pointer and
 the GET statement to assign values from that record to host language
 variables.

 Example:

      RDO> START_STREAM EMPS USING JH IN JOB_HISTORY WITH
      cont> JH.EMPLOYEE_ID = "00164" SORTED BY JH.JOB_START
      RDO> FETCH EMPS
      RDO> PRINT JH.EMPLOYEE_ID, JH.JOB_CODE, JH.JOB_START

Additional information available:

FormatExample

Format

 FETCH ────────────────────────> stream-name ────────┬─────────────┬────┐
                                                     └─> on-error ─┘    │
                                                                        │
 ┌──────────────────────────<───────────────────────────────────────────┘
 └────────┬────────────────────> ────────────────────┬───────────>
          ├──> 
A

T

E

N

D
──> statement ───> 
E

N

D

F

E

T

C

H
──┤ └──> 
E

N

D

F

E

T

C

H
──────────────>─────────────┘

Additional information available:

stream-nameon-errorstatement

stream-name

 Names the stream in which you want to advance the stream pointer.
 Rdb/VMS moves the pointer to the next record that it can return.

 Because the FETCH statement defines the current record in a record
 stream, you must use a FETCH statement before any other Rdb/VMS data
 manipulation statement when you are using streams.

on-error

 The ON ERROR clause.  This clause specifies the action to be taken if
 an Rdb/VMS error occurs during the FETCH operation.  For more
 information, request HELP on ON_ERROR.

statement

 Any valid host language or Rdb/VMS statement.  The program executes
 the statement specified in the AT END clause when no records remain
 to be processed in the record stream.  If you use the AT END clause,
 you must also include END_FETCH.

Example

 Advance a stream pointer in an open stream in a COBOL program:

 CONTROL-PAR.
       PERFORM INIT THRU INIT-END.
       PERFORM LOOP UNTIL DONE = "Y".
       PERFORM GET-OUT.
       STOP RUN.

 INIT.

 &RDB& START_TRANSACTION READ_WRITE
 &RDB&  START_STREAM WORKERS USING C IN CURRENT_INFO.

 INIT-END.

       EXIT.

 LOOP.

 &RDB&  FETCH WORKERS
 &RDB&       ON ERROR
              GO TO STREAM_ERROR
 &RDB&     END_ERROR
 &RDB&     AT END
                MOVE "Y" TO DONE
                GO TO GET-OUT
 &RDB&    END_FETCH
 &RDB&      GET
 &RDB&      LAST = C.LAST;
 &RDB&      DEPARTMENT = C.DEPARTMENT;
 &RDB&      SALARY = C.SALARY
 &RDB&   END_GET
     DISPLAY LAST, DEPARTMENT, SALARY.

 STREAM_ERROR.

       DISPLAY "Error in START_STREAM".
       STOP RUN.

 GET-OUT.

 &RDB& END_STREAM WORKERS
 &RDB& COMMIT
 &RDB& FINISH.

 This program fragment does the following:

  o  Starts a stream and gives it the name WORKERS.  The RSE specifies
     a set of records, in this case the whole CURRENT_INFO view.

  o  Uses COBOL statements to set up a loop and give the ending
     condition for the loop.

  o  Uses FETCH and GET to retrieve one record on each pass through
     the loop and place three fields from that record into host
     language variables.

  o  Uses AT END and ON ERROR to handle end-of-stream and error
     conditions.

  o  Uses the COBOL DISPLAY statement to display the variables each
     time through the loop.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026