Library /sys$common/syshlp/HELPLIB.HLB  —  RDML72  Statements  FOR Statement
    The FOR statement executes a statement or group of statements
    once for each record in a record stream formed by a record
    selection expression. You can nest FOR statements within other
    FOR statements to establish relationships for outer joins.

    Your program can use either FOR statements or START_STREAM
    statements to establish record streams. You can use both methods
    in one program. However, you cannot use the FETCH statement
    to advance the pointer in a record stream established by a FOR
    statement. The FOR statement automatically advances to the next
    record.

1  –  Examples

    The following programs demonstrate the use of the FOR statement
    to create a record stream. These programs:

    o  Declare a variable dept_code

    o  Prompt for a value for dept_code

    o  Start a READ_ONLY transaction

    o  Create a record stream defined by a record selection
       expression that uses the value of dept_code

    o  Display the department name for each record in that stream

    The C program uses the read_string function to prompt for and
    receive a value for dept_code. For more information on this
    function, see Appendix B of the "RDML Reference Manual".

1.1  –  C Example

    #include <stdio.h>
    DATABASE PERS = FILENAME "PERSONNEL";

    extern void read_string ();
    DECLARE_VARIABLE dept_code SAME AS DEPARTMENTS.DEPARTMENT_CODE;

    main ()
    {
    read_string ("Department Code: ",dept_code, sizeof(dept_code));

    READY PERS;
    START_TRANSACTION READ_ONLY;

    FOR D IN DEPARTMENTS
       WITH D.DEPARTMENT_CODE = dept_code
          printf ("Department name =  %s\n ", D.DEPARTMENT_NAME);
    END_FOR;

    COMMIT;
    FINISH;
    }

1.2  –  Pascal Example

    program for_in_rse (input,output);
    DATABASE PERS = FILENAME 'PERSONNEL';

    var
       DECLARE_VARIABLE dept_code SAME AS DEPARTMENTS.DEPARTMENT_CODE;

    begin
    write  ('Department Code: ');
    readln (dept_code);

    READY PERS;
    START_TRANSACTION READ_ONLY;

    FOR D IN DEPARTMENTS
       WITH D.DEPARTMENT_CODE = dept_code
          writeln ('Department name =  ', D.DEPARTMENT_NAME);
    END_FOR;

    COMMIT;
    FINISH;
    end.

2  –  Format

  (B)0FOR qqqqqqqqqwqq>qqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
               mqq> handle-options qqqj                             x
                                                                    x
  lqqqqqqqqqqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
  x
  mqqq>  rse  qqwq>qqqqqqqqqqqwqqqwqq>  statement  qqwqq> END_FOR
                mq>on-error qqj   mqq<qqqqqqqqqqqqqqqj

  (B)0handle-options =

  q> ( qwqqqqqq>  REQUEST_HANDLE  qqqqq>  var qqqqqqqqwq> ) q>
        tqqqqqq> TRANSACTION_HANDLE qqq>  var qqqqqqqqu
        mqqqqqq> REQUEST_HANDLE q> var q> , qqqqqqqk  x
          lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj  x
          mqqqq> TRANSACTION_HANDLE q> var qqqqqqqqqqqj

2.1  –  Format arguments

    rse                    A record selection expression. A phrase
                           that defines specific conditions that
                           individual records must meet before
                           Oracle Rdb includes them in a record stream.

    on-error               The ON ERROR clause. Specifies host
                           language statement(s) to be performed
                           if an error occurs during the FOR loop.
                           For more information see the entry on ON
                           ERROR.

    statement              Any valid RDML or host language statement
                           to be executed within the FOR loop. Use
                           a semicolon (;) at the end of each RDML,
                           Pascal, or C statement.

    handle-options         A request handle, a transaction handle, or
                           both.

    REQUEST_HANDLE var     The REQUEST_HANDLE keyword followed by a
                           host language variable. A request handle
                           identifies a compiled Oracle Rdb request.
                           If you do not supply a request handle
                           explicitly, RDML associates a unique
                           request handle for the compiled request.

    TRANSACTION_HANDLE     The TRANSACTION_HANDLE keyword followed by
    var                    a host language variable. A transaction
                           handle identifies a transaction. If
                           you do not supply a transaction handle
                           explicitly, RDML uses the default
                           transaction handle.
Close Help