RDB/VMS Relational Database Operator STORE — VMS CDD+_4.1A
Inserts a record into an existing relation. Within a single STORE
statement, you can refer to only one relation.
You cannot store records into a view that was defined using the WITH,
CROSS, or REDUCED clause.
Example:
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 = 127098
cont> END_STORE
RDO>
Additional information available:
FormatExamplessegmented string STORE
Format
STORE ───────────┬────────────────────────┬────────>────────────────────┐ └────> handle-options ───┘ │ ┌─────────────────────<───────────────────────────────────<─────────────┘ └─> context-var ──>
I
N ──┬─────────>──────────┬──> relation-name ──────┐ └─> db-handle ──> . ─┘ │ ┌──────────────────────────────────<────────────────────────────────────┘ └──>
U
S
I
N
G ───┬────────────────┬─────> store-items ──────>
E
N
D
S
T
O
R
E └──> on-error ───┘ (The optional GET...RDB$DB_KEY is available only in programs preprocessed by the RDBPRE preprocessor. The optional PRINT...RDB$DB_KEY can be used in RDO only.)
Additional information available:
handle-optionscontext-vardb-handlerelation-namestore-items
on-error
handle-options
handle-options = ──> ( ─┬─>
R
E
Q
U
E
S
T
H
A
N
D
L
E ───> var ───────────────────────────┬─> ) ──> ├─>
T
R
A
N
S
A
C
T
I
O
N
H
A
N
D
L
E ───> var ───────────────────────┤ └─>
R
E
Q
U
E
S
T
H
A
N
D
L
E ─> var , TRANSACTIONHANDLE ─> var ─┘
Additional information available:
REQUEST_HANDLETRANSACTION_HANDLE
REQUEST_HANDLE
A keyword followed by a host language variable. A request handle points to the location of a compiled Rdb/VMS request. If you do not supply a request handle explicitly, Rdb/VMS associates a default request handle with the compiled request. Your must use a request handle when you want to make an identical query to two different databases. In Callable RDO, use !VAL as a marker for host language variables. You can put parentheses around the host language variable name.
TRANSACTION_HANDLE
A keyword followed by a host language variable. A transaction handle identifies each instance of a database attach. If you do not declare the transaction handle explicitly, Rdb/VMS attaches an internal identifier to the transaction. In Callable RDO, use !VAL as a marker for host language variables. You can put parentheses around the host language variable name. Normally, you do not need to use this argument. The ability to declare a transaction handle is provided for compatibility with other database products and future releases of Rdb/VMS.
context-var
A valid context variable.
db-handle
A host language variable used to refer to the database.
relation-name
The name of the relation into which the value is stored.
store-items
store-items = ──┬──┬──> context-var . field-name ───> typebox (=) ───> value-expr ───┬─>─┬───┐ │ └───────────────────────── typebox (;) <──────────────────────────┘ │ │ └─────> context-var . * ──────────> typebox (=) ──> record-descr ────>───┘ │ ┌──────────────────<──────────────────────<──────────────────────────┘ └┬─>──────────────────────────>───────────────────────────────────┬──> ├─>
G
E
T ──> host-var ─> typebox (=) ──> context-var ──> . ──>
R
D
B
$
D
B
K
E
Y ─┤ └─>
P
R
I
N
T ───────────────────> context-var ──> . ──>
R
D
B
$
D
B
K
E
Y ─┘
Additional information available:
GET...RDB$DB_KEYPRINT...RDB$DB_KEY
field-namevalue-exprrecord-descr
field-name
The name of the field in the relation where the value is stored.
value-expr
A valid Rdb/VMS value expression that specifies the value to be stored. For more information, request HELP on Value_expr.
record-descr
A valid data dictionary record descriptor matching all the fields of the relation.
GET...RDB$DB_KEY
In an RDBPRE program (BASIC, COBOL, FORTRAN), you can use 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. Example: &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.)
PRINT...RDB$DB_KEY
In RDO only, you can use PRINT...RDB$DB_KEY to display the database
key of the record about to be stored by the STORE statement.
Example:
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
on-error
The ON ERROR clause, which specifies a host language statement or Rdb/VMS data manipulation statement to be performed if an Rdb/VMS error occurs. For more information, request HELP on ON_ERROR.
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 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
segmented string STORE
A special form of the STORE statement inserts a segment into a
segmented string. Storing a segmented string requires four steps:
1. Create a segmented string with the CREATE_SEGMENTED_STRING
statement. See HELP on CREATE_SEGMENTED_STRING.
2. Store each segment using the syntax shown in the following Format
section. You must use the special Rdb/VMS value expression
RDB$VALUE as the segment name in the USING clause.
3. Store the entire segmented string using the usual syntax for
storing records in relations. Use the segmented string handle,
declared in the CREATE_SEGMENTED_STRING statement, as the value
expression in this USING clause.
4. Close the segmented string.
Additional information available:
Format
STORE ───┐ ┌─────┘ └──> context-var ───>
I
N ────> ss-handle ────┐ ┌────────────────────────────────────────────┘ └──>
U
S
I
N
G ───┬──────────────┬───────┐ └─> on-error ──┘ │ ┌────────────────────────────────────┘ └──┬──> context-var . RDB$VALUE ───> typebox (=) ───> value-expr ──┬──┐ └─────────────────────── typebox (;) <──────────────────────────┘ │ ┌───────────────────────────────────────────────────────────┘ └──>
E
N
D
S
T
O
R
E
Additional information available:
Arguments
context-var A valid context variable.
ss-handle A host language variable or name used to refer to the
segmented string. This handle must match the one
declared in the CREATE_SEGMENTED_STRING statement.
on-error The ON ERROR clause, which specifies host language or
Rdb/VMS data manipulation statements to be performed
if an Rdb/VMS error occurs.
value-expr A valid Rdb/VMS value expression that specifies the
value to be stored.
Example
For a complete example, ask for HELP on CREATE_SEGMENTED_STRING.