3. Embedded SQL for COBOL : COBOL Data Items and Data Types : Variable Usage : Elementary Items from a Record
 
Share this page                  
Elementary Items from a Record
The syntax embedded SQL uses to refer to an elementary item record is the same as in COBOL:
:elementary-item-name IN | OF{ groupname IN | OF} recordname
Alternatively, you can use the following "dot" notation, in which the elementary item is specified from the outer level inwards:
:recordname{.groupname}.elementary-item-name
Syntax Notes:
The referenced item must be a scalar value (numeric, alphanumeric, or alphabetic). There can be any combination of tables and records, but the last referenced item must be a scalar value. Thus, the following references are all legal:
  * Element of a record
    :SAL IN EMPLOYEE
    :SAL OF EMPLOYEE
    :EMPLOYEE.SAL
  * Element of a record as an item of a table
    :NAME IN PERSON(3)
    :PERSON(3).NAME
  * Deeply nested element
    :ELEMENTARY-ITEM OF GROUP3 OF GROUP2 OF REC
    :REC.GROUP2.GROUP3.ELEMENTARY-ITEM
The qualification of an elementary item in a record can be elliptical; that is, you do not need to specify all the names in the hierarchy in order to reference the item. You must not, however, use an ambiguous reference that does not clearly qualify an item. For example, assume the following declaration:
01 PERSON.
   02 NAME PIC X(30).
   02 AGE PIC S9(4) USAGE COMP.
   02 ADDR PIC X(50).
If the variable NAME was referenced in your program, the preprocessor would assume the reference was to the elementary item NAME IN PERSON. However, if also there existed the declaration:
01 CHILD.
    02 NAME PIC X(30).
    02 PARENT PIC X(30).
the reference to NAME would be ambiguous because it could refer to either NAME IN PERSON or NAME IN CHILD.
Subscripts, if present, must qualify the data item declared with the OCCURS clause.
The following example uses the record EMPREC in the employee.dcl file generated by DCLGEN to put values into the empform form:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.

* See above for description.
    EXEC SQL INCLUDE 'employee.dcl' END-EXEC.

EXEC SQL END DECLARE SECTION END-EXEC.

EXEC FRS PUTFORM empform
(eno = :ENO IN EMPREC, ename = :ENAME IN EMPREC,
 age = :AGE IN EMPREC, job = :JOB IN EMPREC,
 sal = :SAL IN EMPREC, dept = :DEPT IN EMPREC)
END-EXEC.
You could also write the putform statement without the EMPREC qualifications, assuming there are no ambiguous references to the item names:
EXEC FRS PUTFORM empform
     (eno = :ENO, ename = :ENAME, age = :AGE,
     job = :JOB, sal = :SAL, dept = :DEPT)
     END-EXEC.