Previous Topic: ParametersNext Topic: Examples


Usage

Naming Elements

When naming schema element types, be sure that the selected names conflict neither with the naming conventions of the programming language(s) that will be used with the CA IDMS Data Manipulation Language (DML) nor with the DML precompilers themselves. As a rule, schema element types should bear names that coincide with the language used most often; use element synonyms to accommodate other languages (see the ELEMENT SYNONYM NAME clause later). In addition to the element naming rules stated above, consider the following points when selecting names (or synonyms) for schema element types:

SQL synonyms

When using SQL to access a non-SQL defined database, each record in the non-SQL schema is accessed as a table. The name of a column of the table is either:

In either case, hyphens within the name are converted to underscores so that it does not have to be enclosed in quotes within SQL statements.

Elements which occur a fixed number of times within the record have a suffix appended to their name to distinguish occurrences. The suffix is composed of occurrence numbers for each level of nested occurs. For example, if element QUARTERLY-QUOTA occurs 4 times, the corresponding column names are:

If QUARTERLY_QUOTA is a sub-element within element ANNUAL- SALES which occurs 3 times, the corresponding column names would be:

Since column names are restricted to 32 characters, it may be necessary to define an SQL synonym for a multiply occurring element so that CA IDMS/DB can append the required suffix.

Function of element level numbers

The function of level numbers 02 through 49 is to create a hierarchy among the element descriptions for a record so that a programmer can, with a single reference, access elements discretely or in groups. The technique is to follow an element description of one level with element description(s) of a higher numbered level. For example, a level 03 element is subordinate to a level 02 element.

Group items and elementary items

A group item contains two or more subordinate elements. A DML reference to a group item gains access to all subordinate items. A subordinate item can, in turn, be a group item, with nesting permitted until level 49 is reached (unless otherwise excepted). An item description that has no subordinate items is called an elementary item.

The following example outlines the element descriptions for the EMPLOYEE record:

02 EMP-ID...                   elementary item
02 EMP-NAME...                 group item
   03 EMP-FNAME...             elementary items subordinate
   03 EMP-LNAME...               to EMP-NAME
02 EMP-SEX...                  elementary item
02 EMP-ADDRESS...              group item
   03 EMP-STREET...            elementary items subordinate
   03 EMP-CITY...                   to EMP-ADDRESS
   03 EMP-STATE...
   03 EMP-ZIP...               group item subordinate to
                                     EMP-ADDRESS
      04 EMP-ZIP-FIRST-5...    elementary items subordinate
      04 EMP-ZIP-LAST-4...           to EMP-ZIP

Minimum element substatements

The minimum element substatement required for the element to be a valid schema component depends on whether the element is a group or elementary item:

PICTURE formats for alphanumeric data

Alphanumeric data is described by the following characters:

PICTURE formats for alphabetic data

Alphabetic data is described by the following characters:

PICTURE formats for DBCS edited data

For DBCS edited data, the PICTURE character string can contain these symbols:

Symbols

Description

G

Each G represents a single DBCS character position (two bytes). When you use this picture, the element USAGE clause must specify DISPLAY-1. Any associated VALUE clause must specify a GRAPHIC literal or the figurative constant SPACES.

B

Each B represents the position used for a space character.

In the following example, the DBCS value represents a string of up to five characters. So and si represent the shift-out and shift-in characters, respectively:

02 zip-code pic g(5)  usage display-1
            value g'sodbcs-valuesi'.

PICTURE formats for fixed decimal data

Fixed decimal data is described by the following characters:

PICTURE formats for external floating point data

External floating point data is described in two parts: the mantissa, which represents the decimal part (fractional part) of the element, and the exponent, which represents the power of 10 to which the base of one (1) must be raised before being multiplied by the mantissa to determine the element's actual value.

Syntax for the floating point picture is shown next:

►►─┬─ + ─┬─ mantissa E ─┬─ + ─┬─ exponent ────────────────────────────────────►◄
   └─ - ─┘              └─ - ─┘

Symbol

Description

+/-

The plus sign or the minus sign indicates whether the mantissa is positive or negative.

mantissa

The numeric part of the mantissa is described by the following characters: 9, which represents one numeric character; (n), following a 9, which represents n repetitions of the numeric character; and V, which represents an assumed decimal point.

At least one 9 is required. No more than one V can appear in the mantissa; if the V is omitted, the assumed decimal point is after the rightmost 9.

E

The character E signifies the beginning of the exponential portion of the picture.

+/-

The plus sign or the minus sign indicates whether the exponent is positive or negative.

exponent

The numeric part of the exponent is described by the following characters: 9, which represents one numeric character; and (n), following a 9, which represents n repetitions of the numeric character.

At least one 9 is required; no more than two 9s (or the equivalent 9(2)) can be coded.

PICTURE formats for numeric edited data

Numeric edited data is described by using the numeric data characters described above, along with the following editing characters:

Z        +      ,
B        CR     -
0        DB     *
$        .

These characters represent edit symbols used in reporting data; quotes are not required. For the individual interpretations of these symbols, refer to the appropriate programming language manual.

Note that if the current decimal point default is DECIMAL-POINT IS COMMA, a period (.) is interpreted as an insertion character and a comma (,) is interpreted as a decimal point.

Data formats described only in elementary items

The actual formats of data can be described only in elementary items. Consequently, the PICTURE, USAGE (except BIT), SYNCHRONIZED, BLANK WHEN ZERO, and SIGN clauses are prohibited in group element descriptions. During programming operations, however, data is accessible not only through its elementary item description, but also through all group items under which it falls. The element EMP-ADDRESS, for example, could be referred to directly in a program.

COBOL condition names

The function of level number 88 is to assign COBOL condition names to specific runtime values of an element. A level 88 element does not occupy storage at runtime: it merely provides a name for a particular value that the preceding element's (level 02 through 49) runtime storage may contain. The name of the level-88 element is known as a condition name. A level-88 ELEMENT substatement must immediately follow either the substatement describing the element for which the level-88 element provides a condition name or another level 88 ELEMENT substatement. The following example illustrates the description of a level-88 element; see the presentation of the VALUE clause for further details:

add record name is expertise
    .
    .
    .
    02 skill-level-0425     picture is xx.
       88 expert-0425       usage is condition-name
                            value is '04'.
       88 proficient-0425   usage is condition-name
                            value is '04'.
       88 competent-0425    usage is condition-name
                            value is '04'.
       88 elementary-0425   usage is condition-name
                            value is '04'.

Usage clause restrictions for PICTURE clause data types

Alphanumeric, alphabetic, external floating point, and numeric edited descriptions must always have a usage of DISPLAY. Fixed decimal element descriptions can have a usage of DISPLAY, COMP, COMP-3, or COMP-4.

The exact runtime characteristics of an element depend not only on the PICTURE specification, but also on other specifications for the element's format, such as USAGE. The following table illustrates several PICTURE specifications in combination with VALUE specifications.

Usage

Picture

Sample Value

Storage Requirements

DISPLAY

X(5)

T0241

5 bytes

 

X(10)

JUNE

10 bytes—Padded on right with blanks

 

9(7)

2376600

7 bytes

 

9(10)

2376600

10 bytes—Padded on left with zeros

 

9(7)V99

2376600.59

9 bytes—Assumed decimal point requires no space

 

9(5)PP

2376600

5 bytes—Assumed zeros require no space

 

+99E-9

.0000059

6 bytes

DISPLAY-1

G(5)

DBCS

character

string

10 bytes

COMP

9(4)

2376

2 bytes

 

9(7)V99

2376600.59

4 bytes

COMP-1

none

2376600.59

4 bytes

COMP-2

none

2376600.59

8 bytes

COMP-3

9(7)

2376600

4 bytes

 

9(7)V99

2376600.59

5 bytes

BIT

X

1

1 byte

 

X(7)

FILLER

 

How the COBOL DML precompiler handles bit elements

When a COBOL program copies a record that contains a bit element, the DML precompiler does the following:

Element storage characteristics due to usage and picture

The following table illustrates how values are stored with different usages.

Usage

Alphanumeric Value

Internal Representation in hexadecimal

DISPLAY

BILL BALL

C2 C9 D3 D3 40 C2 C1 D3 D3

DISPLAY

4857964

F4 F8 F5 F7 F9 F6 F4

COMP

4857964

00 4A 20 6C

COMP-1

4857964

40 4A 20 6C

COMP-2

4857964

40 00 00 00 00 4A 20 6C

COMP-3

4857964

48 57 96 4C

BIT

B'11110000'

F0

POINTER

4857964

00 4A 20 6C

OCCURS DEPENDING ON creates variable-length records

The OCCURS DEPENDING ON clause makes a record variable in length. If the MINIMUM ROOT LENGTH and/or MINIMUM FRAGMENT LENGTH clauses are not included in the record description, the defaults (CONTROL LENGTH and four bytes) are assigned. The total space required in main storage for a variable-length record is:

main storage space = F + (V * M)

    where F = the length of the record's fixed
              portion
          V = the length of one occurrence of
              the record's variable portion
          M = the maximum number of times the control element
              can occur

For example, the total main storage required for the ABRIDGED-DENTAL-CLAIM record described next under "Examples" is 20 + 15 + 2 + 9 + 2 + ((2 + 2 + 2 + 2) * 10) = 128 bytes. The actual size of a specific occurrence of the record (data portion) as stored in the database, however, is as follows:

database storage space = F + (V * C)

    where F = the length of the record's fixed
              portion
          V = the length of one occurrence of
              the record's variable portion
          C = the value of the control element
              in the specific record occurrence.

A value of 2 for DC-NUMBER-OF-PROCEDURES, for example, indicates two DC-DENTIST elements and a record length of 20 + 15 + 2 + 9 + 2 + ((2 + 2 + 2 + 2) * 2) = 64 bytes.

SQL Considerations

If you intend to use SQL to access the data described by a non-SQL schema record, consider the following when designing your record elements:

Picture and Usage

Data Type

PIC X(n) usage DISPLAY

CHAR(n)

PIC A(n) usage DISPLAY

CHAR(n)

Numeric edited1

CHAR(l), l=byte length

External floating point2

CHAR(l), l=byte length

PIC G(n) usage DISPLAY

GRAPHIC(n)

PIC S9(t)V9(s) usage DISPLAY

NUMERIC(t+s,s)

PIC SP..9(p) usage DISPLAY3

NUMERIC(p,p)

PIC S9(p)P.. usage DISPLAY3

NUMERIC(p,0)

PIC 9(t)V9(s) usage DISPLAY

UNSIGNED NUMERIC(t+s,s)

PIC P..9(p) usage DISPLAY3

UNSIGNED NUMERIC(p,p)

PIC 9(p)P.. usage DISPLAY3

UNSIGNED NUMERIC(p,0)

PIC S9(t)V9(s) usage COMP-3

DECIMAL(t+s,s)

PIC SP..9(p) usage COMP-33

DECIMAL(p,p)

PIC S9(p)P.. usage COMP-33

DECIMAL(p,0)

PIC 9(t)V9(s) usage COMP-3

UNSIGNED DECIMAL(t+s,s)

PIC P..9(p) usage COMP-33

UNSIGNED DECIMAL(p,p)

PIC 9(p)P.. usage COMP-33

UNSIGNED DECIMAL(p,0)

PIC S9(n), n<5 usage COMP4

SMALLINT

PIC S9(n), 4<n<10 usage COMP4

INTEGER

PIC S9(n), 9<n usage COMP4

LONGINT

PIC 9(n) usage COMP4

BINARY(l), l=byte length

PIC X(n) usage BIT

BINARY(l), l=byte length

USAGE POINTER

BINARY(4)

USAGE COMP-1

REAL

USAGE COMP-2

DOUBLE PRECISION

1. Numeric edited includes any element whose usage is DISPLAY and:

2. External floating point includes any element whose usage is DISPLAY and whose picture is: +/- mantissa E +/- exponent

3. The scaling character "P" in a picture clause is ignored in value representations of associated columns. This has the effect of representing values of such columns as a power of 10 greater than or smaller than their actual value. For example, if an element is described as PIC S9(5)PPP, a value of 123000 will be represented in SQL as 123. If an element is described as PIC SPPP9(5), a value of .000123 will be represented in SQL as .123.

4. Computational elements also include those whose USAGE is BINARY and COMP-4. If the picture of a computational item includes an implied decimal point, it is ignored in determining the data type of the column. This has the effect of representing values of such columns as a power of 10 greater than their actual values. For example, if an element is described as PIC S9(5)V99 USAGE COMP, a value of 123.56 will be represented in SQL as 12345.

Elements whose usage is BIT are not represented by columns except as noted: