RDB/VMS Relational Database Operator GET — VMS RDB_4.2
Assigns values from data records in a record stream to host language
variables in a program using the RDBPRE preprocessor (for BASIC,
COBOL, and FORTRAN). You cannot use GET in RDO. Example:
&RDB& FOR E IN EMPLOYEES
&RDB& GET
&RDB& LAST-NAME = E.LAST_NAME;
&RDB& FIRST-NAME = E.FIRST_NAME;
&RDB& MIDDLE-INITIAL = E.MIDDLE_INITIAL
&RDB& END_GET
&RDB& END_FOR
Additional information available:
More
If you have invoked a database, you have the necessary privileges to
use the GET statement.
In RDBPRE programs, you can use the GET statement in three ways:
o When you establish a record stream with the FOR or START_STREAM
statement, you use the GET statement to assign values from the
current record in the stream to variables in your program. In
the case of START_STREAM, you also need FETCH to indicate the
current record in the stream.
o You can use GET alone, without a FOR or FETCH statement, to
retrieve the result of a statistical function. The record stream
is formed by the record selection expression within the
statistical expression.
o Or you can use GET...RDB$DB_KEY in a STORE...END_STORE block to
retrieve the database key of the record just stored. 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.)
You cannot use the concatenation operation in a GET statement.
NOTE
Use the GET statement only in RDBPRE programs. RDO
uses the PRINT statement to display values on the
terminal.
Format
GET ─┬─────────>─────────┬────┬────────>──────┬───┐ └─> handle-options ─┘ └─> on-error ──┘ │ ┌──────────────────────────<──────────────────────┘ └─┬─> get-item ──┬──>
E
N
D
G
E
T ──> └───── typebox (;) <──────┘
Additional information available:
Morehandle-optionson-errorget-item
More
If you list a field for which the value is null, and there is a MISSING_VALUE clause for that field, Rdb/VMS supplies the missing value. If there is no MISSING_VALUE clause, and nulls are allowed, then Rdb/VMS supplies zeros for numeric fields, blanks for text fields, and the VMS base date and time (17-NOV-1858 00:00:00.00) for date fields.
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 transaction. 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.
on-error
ON ERROR ─┬─> statement ─┬─>
E
N
D
E
R
R
O
R └────────<─────┘ on-error The ON ERROR clause. This clause specifies the action to be taken if an Rdb/VMS error occurs during the GET operation. Request HELP for ON_ERROR for more information.
get-item
get-item =
──────┬─> host-variable = value-expr ────────────────┬───>
├─> host-variable = statistical-expr ──────────┤
└─> record-descr = context-var . * ───────────┘
Includes an assignment statement specifying a host language variable
and a database value. The value is assigned to the host language
variable from the Rdb/VMS value expression or statistical expression.
Additional information available:
host-variablestatistical-exprvalue-expr
host-variable
A valid variable name declared in the host language program. Ask for HELP on Value_expr for more information.
statistical-expr
A statistical expression. A statistical expression calculates values based on a value expression for every record in a record stream. Ask for HELP on Value_expr for more information.
value-expr
A valid Rdb/VMS value expression. Ask for HELP on Value_expr for more information.
Examples
Example 1
The following COBOL example retrieves values from named fields in a
relation:
&RDB& START_TRANSACTION READ_WRITE
&RDB& FOR E IN EMPLOYEES
&RDB& GET
&RDB& LAST-NAME = E.LAST_NAME;
&RDB& FIRST-NAME = E.FIRST_NAME;
&RDB& MIDDLE-INITIAL = E.MIDDLE_INITIAL
&RDB& END_GET
&RDB& END_FOR
&RDB& COMMIT
This code fragment retrieves field values from each record in the
EMPLOYEES relation. It assumes that the program has declared the
three host language variables, LAST-NAME, FIRST-NAME, and
MIDDLE-INITIAL, with the appropriate data types.
Example 2
The following set of statements performs a join of two relations and
uses GET to retrieve a value from each:
&RDB& START_TRANSACTION READ_WRITE
&RDB& FOR JH IN JOB_HISTORY CROSS D IN DEPARTMENTS
&RDB& OVER DEPARTMENT_CODE
&RDB& WITH JH.JOB_END MISSING
&RDB& GET
&RDB& ID_NUMBER = JH.EMPLOYEE_ID;
&RDB& DEPT-NAME = D.DEPARTMENT_NAME
&RDB& END_GET
&RDB& END_FOR
&RDB& COMMIT
Example 3
The following BASIC code fragment retrieves the result of a
statistical function:
INPUT "State: ", STATE
&RDB& START_TRANSACTION READ_ONLY
&RDB& GET
&RDB& NUMBER-EMPLOYEES = COUNT OF E IN EMPLOYEES
&RDB& WITH E.STATE = STATE
&RDB& END_GET
PRINT "Number of employees in "; &
STATE; " is "; NUMBER-EMPLOYEES
&RDB& COMMIT
This statement retrieves the number of employees who live in the
specified state and assigns that number to the variable
NUMBER-EMPLOYEES.
Example 4:
The following RDBPRE program segment uses GET...RDB$DB_KEY within a
STORE...END_STORE block to retrieve into a host language variable the
database key of the record about to be stored by the STORE statement.
&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.)