RDOHELP72.HLB  —  FETCH
    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

1  –  Format

  (B)0FETCH qqq> stream-name qqwqqqqqq>qqqqqqwqqqk
                           mq> on-error qj   x
  lqqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqj
  mwqqqqqqqqqqqqqqqqqqqqq>qqqqqqqqqqqqqqqqqqqwq>
   tq> AT END qq> statement qqq> END_FETCH qqu
   mq> END_FETCH qqqqqqqqqqqqqq>qqqqqqqqqqqqqj

1.1  –  stream-name

    Names the stream in which you want to advance the stream pointer.
    Oracle Rdb 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
    Oracle Rdb data manipulation statement when you are using streams.

1.2  –  on-error

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

1.3  –  statement

    Any valid host language or Oracle Rdb 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.

2  –  More

    If you have invoked a database, you have the necessary privileges
    to use the FETCH statement.

3  –  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.
Close Help