3. Embedded SQL for COBOL : COBOL Data Items and Data Types : Variable and Type Declarations : Data Item Declaration Syntax
 
Share this page                  
Data Item Declaration Syntax
This section describes rules and restrictions for declaring COBOL data items in embedded SQL declaration sections. All data items in a declaration section must be declared with the correct syntax. Embedded SQL recognizes only a subset of legal COBOL declarations.
The following template is the complete data item declaration format that embedded SQL accepts:
level-number
              [data-name | FILLER]
              [ REDEFINES data-item]
              [ [IS] GLOBAL]
              [ [IS] EXTERNAL]
              [ PICTURE [IS] pic-string ]
              [ [USAGE [IS]] use-type ]
              [ SIGN clause ]
              [ SYNCHRONIZED clause ]
              [ JUSTIFIED clause ]
              [ BLANK clause ]
              [ VALUE clause ]
              [ OCCURS clause ]
Syntax Notes:
Data declaration clauses can be in any order, with the following two exceptions:
The data-name or FILLER clause, if given, must immediately follow the level number.
The REDEFINES clause, if given, must immediately follow the data‑item or FILLER clause.
The level-number can range from 01 to 49. Level number 77 (for noncontiguous data items) is also valid and the preprocessor regards it as identical to level 01. The embedded SQL preprocessor does not support Level 66 (which identifies RENAMES items) and Level 88 (which associates condition names with values).
Follow the COBOL rules for specifying the organization of data when you assign level numbers to your embedded SQL data items. Like the COBOL compiler, the preprocessor recognizes that a data item belongs to a record or group if its level number is greater than the record or group level number.
The data-name must begin with an alphabetic character, which can be followed by alphanumeric characters, hyphens, and underscores. The word FILLER can appear in place of data-name; however, you cannot explicitly reference a FILLER item in an embedded SQL statement. If the data‑name or FILLER clause is omitted, FILLER is the default.
The preprocessor accepts but does not use the REDEFINES, GLOBAL, EXTERNAL, SIGN, SYNCHRONIZED, JUSTIFIED, BLANK, and VALUE clauses. Consequently, illegal use of these clauses goes undetected at preprocessing time but generates COBOL errors later at compile time. For example, the preprocessor does not check that a GLOBAL clause appears only on an 01 level item, nor that a SIGN clause appears only on a numeric item.
The preprocessor expects a PICTURE clause on the COMP, COMP3, COMP5 (UNIX), and DISPLAY use‑types.
Do not use a PICTURE clause on COMP1 (VMS), COMP2 (VMS), and INDEX use‑types.
Although the preprocessor recognizes all the valid COBOL PICTURE symbols, it only makes use of the type and size information needed for runtime support. It does not, for instance, complain about certain illegal combinations of editing symbols in picture strings. Embedded SQL accepts PIC as an abbreviation for PICTURE. You must specify the picture string on the same line as the keyword PICTURE.
For information on the valid use‑types for the USAGE clause and their interaction with picture strings, see Data Types (see page Data Types) in this chapter.
The preprocessor accepts the OCCURS clause for all data items in the level range 02 through 49. The preprocessor does not use the information in the OCCURS clause, except to note that the item described is an array. If you use an OCCURS clause on level 01, the preprocessor issues an error but generates correct code so that you can compile and link the program.