RDOHELP72.HLB  —  STORE  Examples
    Example 1

    The following example shows how to store a record in RDO:

    RDO>  START_TRANSACTION READ_WRITE
    RDO> !
    RDO>  STORE D IN DEPARTMENTS USING
    cont>   D.DEPARTMENT_CODE = "RECR";
    cont>   D.DEPARTMENT_NAME = "Recreation";
    cont>   D.MANAGER_ID = "00175";
    cont>   D.BUDGET_PROJECTED = 240000;
    cont>   D.BUDGET_ACTUAL = 128776;
    cont> END_STORE
    RDO> !
    RDO> COMMIT

    This RDO statement explicitly assigns a literal value to each
    field in the DEPARTMENTS relation.

    Example 2

    The following example shows how to store a record in COBOL:

       ACCEPT JOB-CODE.
       DISPLAY "Enter starting date:     " WITH NO ADVANCING.
       ACCEPT START-DATE.
       DISPLAY "Enter ending date:       " WITH NO ADVANCING.
       ACCEPT END-DATE.
       DISPLAY "Enter department code:   " WITH NO ADVANCING.
       ACCEPT DEPT-CODE.
       DISPLAY "Enter supervisor's ID:   " WITH NO ADVANCING.
       ACCEPT SUPER.

    &RDB&  START_TRANSACTION READ_WRITE
    &RDB&    RESERVING JOB_HISTORY,
    &RDB&    FOR PROTECTED WRITE,
    &RDB&    JOBS, EMPLOYEES
    &RDB&    FOR SHARED READ
    &RDB&  STORE J IN JOB_HISTORY USING
    &RDB&   ON ERROR
    &RDB&       ROLLBACK
                DISPLAY "An error has occurred.  Try again."
                GO TO STORE-JOB-HISTORY
    &RDB&     END_ERROR
    &RDB&     J.EMPLOYEE_ID = EMPL-ID;
    &RDB&     J.JOB_CODE = JOB-CODE;
    &RDB&     J.JOB_START = START-DATE;
    &RDB&     J.JOB_END = END-DATE
    &RDB&     J.DEPARTMENT_CODE = DEPT-CODE;
    &RDB&     J.SUPERVISOR_ID = SUPER;
    &RDB&  END_STORE

    &RDB&  COMMIT

    This sequence stores a new record in the JOB_HISTORY relation.
    The COBOL program does the following:

    o  Prompts for the field values.

    o  Starts a read/write transaction. Because you are updating JOB_
       HISTORY, you do not want to conflict with other users who may
       be reading data from this relation. Therefore, you use the
       PROTECTED WRITE reserving option.

       There are also constraints on the database to ensure that
       the employee and the job code being stored actually exist in
       other relations. Because the constraints check these other
       relations, you must reserve those relations also.

    o  Stores the record by assigning the host language variables to
       database field values.

    o  Includes an ON ERROR clause to check for errors and reprompt
       if necessary.

    o  Uses COMMIT to make the update permanent.

 A more extensive example appears under COMMIT.

    Example 3:

    The following RDBPRE program segment uses GET...RDB$DB_KEY to
    retrieve the database key of the record about to be stored by the
    STORE statement into a host language variable.

    &RDB&   STORE E IN EMPLOYEES USING E.EMPLOYEE_ID = 15231;
    &RDB&                              E.LAST_NAME = "Smith";
    &RDB&           GET MY_DB_KEY = E.RDB$DB_KEY;
    &RDB&           END_GET
    &RDB&   END_STORE

    (MY_DB_KEY is a user-defined host language variable.)

    Example 4:

    The following program reads a file and loads it into the
    specified employee's RESUMES record in the PERSONNEL database.

    program STORE_RESUME

    !
    ! STORE RESUME
    ! This program reads a file and loads it into the specified
    ! employee's RESUMES record in the PERSONNEL database
    !
            option type = EXPLICIT
            declare long constant TRUE = -1%, FALSE = 0%
            declare                                                 &
                string                                              &
                    employee_id, resume_file, text_line,            &
                    last_name, first_name,                          &
                long                                                &
                    found, line_count

    &RDB&   INVOKE DATABASE FILENAME "DB$:PERSONNEL31"

            print "** Personnel RESUME Load **"
            when error in
                input "Enter EMPLOYEE_ID"; employee_id
            use
                print "Program terminated"
                continue END_PROGRAM
            end when

    &RDB&   START_TRANSACTION READ_WRITE
    &RDB&   FOR E IN EMPLOYEES WITH E.EMPLOYEE_ID = employee_id
    &RDB&       GET
    &RDB&           last_name = E.LAST_NAME;
    &RDB&           first_name = E.FIRST_NAME;
    &RDB&       END_GET
                found = TRUE
    &RDB&   END_FOR

            if not found then
                print "Error - employee " + employee_id + " not found"
                exit program
            else
                !
                ! Display the employees name
                !
                print "Loading RESUME for employee " +              &
                      TRM$(first_name) + ", " + TRM$(last_name)

                !
                ! Read the name of the resume source file
                !
            GET_NAME:
                when error in
                    input "Enter the resume file name"; resume_file
                    open resume_file for input as file #1,          &
                        organization sequential, recordtype ANY
                use
                    if err = 11% then
                        print "Program terminated"
                        continue END_PROGRAM
                    else
                        print "Error - " + RIGHT(ERT$(err),2%)
                        continue GET_NAME
                    end if
                end when

    &RDB&       CREATE_SEGMENTED_STRING RES

                !
                ! Loop and read each line from the resume, and store
         ! it in the segmented string
                !
                line_count = 0%
                while TRUE  ! indefinite loop
                    when error in
                        linput #1, text_line
                    use
                        continue EOF
                    end when
                    text_line = TRM$(text_line)
                    line_count = line_count + 1%
    &RDB&           STORE R IN RES USING
    &RDB&               R.RDB$VALUE = text_line;
    &RDB&               R.RDB$LENGTH = LEN(text_line)
    &RDB&           END_STORE
                next
        EOF:
                close #1
                print line_count; "lines stored in resume."
    &RDB&       STORE RS IN RESUMES USING
    &RDB&           RS.EMPLOYEE_ID = employee_id;
    &RDB&           RS.RESUME = RES
    &RDB&       END_STORE
    &RDB&       END_SEGMENTED_STRING RES
            end if

    &RDB&   commit
    &RDB&   finish

        END_PROGRAM:

    end program

    Example 5:

    The following RDO example uses the PRINT statement to display
    the database key of the record about to be stored by the STORE
    statement:

    RDO> STORE E IN EMPLOYEES USING
    cont>  E.EMPLOYEE_ID = "15231";
    cont>  E.LAST_NAME = "Smith";
    cont>   PRINT E.RDB$DB_KEY
    cont> END_STORE
                RDB$DB_KEY
                  21:339:0
Close Help