Chapter 7: Data Division

7.1 General Description

The Data Division describes the data that the runtime module is to accept as input, to manipulate, to create, or to produce as output.

The following is the General Format of the sections in the Data Division, and defines the order of presentation in the source element.

General Format

The Object-Storage Section is described in the section Object-Storage Section in the chapter Object COBOL Language Extensions. The Report Section is described in the chapter Report Writer in your Language Reference - Additional Topics. The other sections are described in the following subsections.

7.2 File Section

The file description entry (FD) represents the highest level of organization in the File Section. The FILE SECTION header is followed by a file description entry consisting of a level indicator (FD), a file-name and a series of independent clauses. The clauses in the file description entry specify the size of the logical and physical records, the external name of the file, and the names of the data records which comprise the file. The entry itself is terminated by a period.

An SD file description gives information about the size and the names of the data records associated with the file to be sorted or merged. There are no label procedures which the user can control, and the rules for blocking and internal storage are peculiar to the SORT and MERGE statements.

The elements allowed in a file description and sort-merge file description are defined in the chapter Data Division - File and Data Description

7.2.1 Relationship with Sort-Merge

The sort-merge module provides the capability to sort elements of a table in the Data Division. The files specified in the USING and GIVING phrases of the SORT and MERGE statements must be described implicitly or explicitly in the FILE-CONTROL paragraph as having sequential organization and sequential access mode. No input-output statement can be executed for the file named in the sort-merge file description.

The files specified in the USING and GIVING phrases of the SORT and MERGE statements can be described explicitly in the FILE-CONTROL paragraph as having either indexed or relative organization and can have either sequential or dynamic access mode.

7.2.2 Record Description Structure

A record description consists of a set of data description entries which describe the characteristics of a particular record. Each data description entry consists of a level-number, a data-name if required and a series of independent clauses as required. A record description has a hierarchical structure and, therefore, the clauses used with an entry can vary considerably, depending upon whether or not it is followed by subordinate entries. The structure of a record description is defined in the section Concept Of Levels in the chapter Concepts of the COBOL Language, while the elements allowed in a record description are defined in the chapter Data Division - File and Data Description.

7.3 Working-Storage Section

The Working-Storage Section is composed of the section header, followed by data description entries for noncontiguous data items and/or record description entries. The syntax of data description entries is defined in the chapter Data Division - File and Data Description.

Each Working-Storage Section record-name and noncontiguous item-name should be unique since it cannot be qualified. Subordinate data-names need not be unique if they can be made unique by qualification.

Provided no reference is made to a given data-name or record-name, it need not be unique by qualification.

General Format

7.3.1 Noncontiguous Working-Storage (77-level-description-entry)

Items and constants in the Working-Storage Section which bear no hierarchical relationship to one another need not be grouped into records, provided they do not need to be further subdivided. Instead, they are classified as noncontiguous elementary items and are defined in a separate data description entry which begins with the special level-number, 77. The syntax of data description entries is defined in the chapter Data Division - File and Data Description

The following data clauses are required in each data description entry:

Other data description clauses are optional and can be used to complete the description of the item if necessary.

7.3.2 Working-Storage Records (record-description-entry)

Data elements in the Working-Storage Section which bear a definite hierarchical relationship to one another must be grouped into records according to the rules for formation of record descriptions. All clauses which are used in record descriptions in the File Section can be used in record descriptions in the Working-Storage Section.

7.3.3 Record Description Structure

A record description consists of a set of data description entries which describe the characteristics of a particular record. Each data description entry consists of a level-number

optionally

followed by the data-name or FILLER clause, followed by a series of independent clauses as required. A record description can have a hierarchical structure and therefore the clauses used within an entry can vary considerably, depending upon whether or not it is followed by subordinate entries. The structure of a record description is defined in the section Concept Of Levels in the chapter Concepts of the COBOL Language, while the elements allowed in a record description are defined in the chapter Data Division - File and Data Description.

7.3.4 Initial Values

The initial value of any item in the Working-Storage Section except an index data item

or a type definition

can be specified by using the VALUE clause with the data item. The initial value of any index data item or any data item not associated with a VALUE clause is undefined. See the section Initial State of a Program earlier in this chapter.

7.4 Thread-Local-Storage Section

Function

The Thread-Local-Storage Section describes data which is unique to each thread, and is persistent across calls. The VALUE clause can be used to provide initial values for this data. The syntax of data description entries is defined in the chapter Data Division - File and Data Description.

Thread-local-storage can be viewed as thread-specific working-storage. This is useful for resolving contention problems in most reentrant programs. In many cases, a non-file-handling program can be made completely reentrant by simply changing the WORKING-STORAGE section header to a THREAD-LOCAL-STORAGE section header.

General Format

Syntax Rules

  1. The EXTERNAL clause is not allowed.

General Rules

  1. A separate copy of each data item in thread-local-storage is created and set to its initial state for each new thread of execution that enters the program. The data item is only visible to the thread causing its execution. The data item is destroyed when the creating thread's execution terminates, or when a CANCEL statement on the program is executed; otherwise, on subsequent calls to the program within that thread, the data item is in its last used state.

  2. In a single-threaded environment, thread-local-storage behaves exactly as working-storage.

7.5 Local-Storage Section

Function

A separate copy of the Local-Storage Section is created each time the runtime element is activated and exists only during the lifetime of that activation. The Local-Storage Section is provided specifically for use in functions, methods and recursive calls.

The Local-Storage Section is composed of the section header, followed by data description entries for noncontiguous data items and/or record description entries. Each Local-Storage Section record-name and noncontiguous item-name should be unique since it cannot be qualified. Subordinate data-names need not be unique if they can be made unique by qualification. The syntax of data description entries is defined in the chapter Data Division - File and Data Description.

Provided no reference is made to a given data-name or record-name, it need not be unique by qualification.

General Format

Syntax Rules

  1. The EXTERNAL clause is not allowed.

  2. The GLOBAL clause is not allowed.

  3. The syntax CALL ... USING local-data-item is permitted.

  4. The syntax ENTRY ... USING local-data-item is not permitted.

  5. The syntax PROCEDURE DIVISION ... USING local-data-item is not permitted.

  6. The LOCAL-STORAGE SECTION header is not permitted in nested programs.

  7. The presence of a Local-Storage Section in a program implicitly sets the recursive attribute, even if the section does not have any records. For more information, see Common, Initial, and Recursive Attributes in the chapter Language Fundamentals.

General Rules

  1. The DEFAULT-BYTE Compiler directive does not apply to items declared within the Local-Storage Section.

  1. The VALUE clause is treated as documentary.

7.6 Linkage Section

All references to PROCEDURE DIVISION USING in the following discussion also apply to ENTRY USING.

Except as described under the section The SET Statement,

the Linkage Section in a program definition is meaningful if, and only if, the object program is to function under the control of a CALL statement, and the CALL statement in the calling program contains a USING phrase.

The Linkage Section is always meaningful in a function or method.

Formal parameters and returning items described in the linkage section of a source element are referred to both by that source element, when it is activated, and by the activating source element.

Such data can also be described in the File and Working-Storage Sections .

No storage is allocated for data items defined in the Linkage Section. Procedure Division references to these data items are resolved at run time by equating the reference in the activated runtime element to the location used in the activating runtime element. In the case of index-names, no such correspondence is established. Index-names in the activated and activating runtime element always refer to separate indices.

Data items defined in the Linkage Section of a program can be referenced within the Procedure Division of that program only if they are specified as operands of the USING phrase of the PROCEDURE DIVISION header or are subordinate to such operands, and the object program is under the control of a CALL statement which specifies a USING phrase.

The structure of the Linkage Section is the same as that previously described for the Working-Storage Section, beginning with a section header, followed by data description entries for noncontiguous data items and/or record description entries. The syntax of data description entries is defined in the chapter Data Division - File and Data Description.

Each Linkage Section record-name and noncontiguous item-name must be unique within the source element if it is referenced in the Procedure Division. Of those items defined in the Linkage Section only data-name-1, data-name-2, ... in the USING phrase of the PROCEDURE DIVISION header, data items that redefine or rename these items, data items subordinate to any of these data-names, and condition-names and/or index- names associated with any such data-names and/or subordinate data items can be referenced in the Procedure Division.

The description of the parameters and the returning items that appear in a linkage section must follow the rules specified in Conformance for parameters and returning items.

7.6.1 Noncontiguous Linkage Storage

Items in the Linkage Section that bear no hierarchic relationship to one another need not be grouped into records and are classified and defined as noncontiguous elementary items. Each of these data items is defined in a separate data description entry which begins with the special level-number 77.

The following data clauses are required in each data description entry:

Other data description clauses are optional and can be used to complete the description of the item if necessary.

7.6.2 Linkage Records

Data elements in the Linkage Section which bear a definite hierarchic relationship to one another must be grouped into records according to the rules for formation of record descriptions. Any clause which is used in an input or output record description can be used in a Linkage Section.

7.6.3 Initial Values

The VALUE clause must not be specified in the Linkage Section except in condition-name entries (level 88).

The VALUE clause is allowed, and is treated as documentary.

7.7 Screen Section

The Screen Section provides screen handling facilities for use with ACCEPT and DISPLAY statements. It allows the following:

The Screen Section contains a description of each field on the screen which is accessed in a Format 4 ACCEPT or Format 2 DISPLAY operation. Such a field is called a screen item. Many screen items describe only the layout of fields within a field on the screen and are never referenced explicitly.

The Screen Section contains syntax which enables the operator to:

This syntax is defined in the chapter Data Division - Screen Section.

Data entry is made to numeric and numeric edited screen fields in two ways; fixed format mode and free format mode. Refer to your COBOL system documentation about user interfaces for further details.

Fixed format mode is the default manner in which data entry is made to numeric and numeric edited screen fields. This mode formats and echoes the entered data and also moves the cursor in accordance with the requirements of the field's picture specification, as each keystroke is received. Characters other than digits, "+", "–" , and the decimal point character, are rejected; insertion characters in edited fields are skipped over as the cursor moves backwards and forwards; any sign indicator is modified in accordance with its normal specification; floating symbols move left and right in the field, and insertion symbols appear and disappear as digits are inserted or deleted. When the cursor reaches the last character position in a field, any further character entered replaces the last character.

Free format mode is an alternative manner in which data entry can be made to numeric and numeric edited screen fields. The default mode is fixed format mode (see above entry). Free format mode allows data to be keyed into a PIC X field of appropriate length, and only when the operator leaves the field is the data reformatted to comply with the picture specification. Once the operator moves the cursor from the field, your COBOL system disregards all characters other than digits and the sign and decimal point symbols. It then extracts, stores, or reformats the numeric value in accordance with the normal COBOL rules for a MOVE to an item with the same picture as the screen item or working-storage item. The numeric value is then usually echoed to the screen. See your COBOL system documentation about user interfaces for details on configuration options available to you.

Function

The Screen Section provides screen handling facilities for use with Format 4 ACCEPT and Format 2 DISPLAY statements.

General Format

Syntax Rules

  1. The Screen Section must be the last section in the Data Division.

  2. Screen-description-entries contain screen description clauses. Data description clauses allowed in the Screen Section are restricted to those shown in the General Format.

General Rule

The Screen Section contains a description of each field on the screen which is accessed in a Format 4 ACCEPT or Format 2 DISPLAY operation. Such a field is called a screen item. Many screen items describe only the layout of fields within a field on the screen and are never referenced explicitly.


Copyright © 2001 Micro Focus International Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.