COBOL Data Level 49 and CA Datacom SQL programs

Document ID : KB000024272
Last Modified Date : 20/09/2018
Show Technical Document Details
Question:

In a COBOL program, the level numbers 01 through 49 are used with each data item to establish a hierarchical relationship. In several places in the CA Datacom/DB SQL User Guide, there are data definitions using two Level 49 fields as the only fields within a group. Why are those level numbers used – are they special?

Answer:
COBOL uses level numbers 01 through 49 to define a data structure into a hierarchy of constituent parts - the higher the level number, the lower the item is in the hierarchy. The numbers themselves do not typically have any special significance, but the relationship of the level numbers to each other identifies the levels within the hierarchy.

However, when coding data areas for use with SQL, Level Number 49 has a special significance. 49 is used to declare elementary item identifiers of variable length - typically VARCHAR, LONG VARCHAR, VARGRAPHIC, and LONG VARGRAPHIC variables. When Level 49 is used, the group contains a 2 byte Length field followed by the actual field name (defined as PIC X(##) with ## being the maximum length). The field data will vary in its length and when data is placed into the field, only the number of characters defined in the length item is returned, with no pad characters. This has the potential to cause a problem since the previous information stored in this field is not automatically cleared and the previous value was longer than the current value. When the data is retrieved, both the length and data item are populated. A length of 0 indicates that the column is not populated.
Here is a sample use of the Level 49:
----+---10----+---20----+---30----+---40----+---50----+
       01  Column-name.
           49  Column-name-len    PIC S9(04)  BINARY.
           49  Column-name-data   PIC  X(273).

Here is an explanation of this layout:
## Column-name is the name of the SQL column
Column-name-len is a 1-4 integer field that holds the length of the data in Column-name.
Column-name-data holds the actual data, and the PIC clause indicates the largest variable value that can be assigned to this variable.
Additional Information:
For more information on using VARCHAR, LONG VARCHAR, VARGRAPHIC and LONG VARGRAPHIC fields in COBOL programs, please refer to the following documentation:
CA Datacom/DB SQL version 15.1: CA Datacom/DB SQL version 15.0:
As always, please contact CA Technologies support for CA Datacom if you have further questions.