# Compaq COBOL
Reference Manual

Previous | Contents | Index

In this example:

- The relative locations of records (01-level items) in the Working-Storage and Linkage Sections are neither defined nor predictable.
- The structures of ITEM-J (a record) and ITEM-C (a group item within a record) are identical.

Example 2

     WORKING-STORAGE SECTION.
    01    ITEM-A.
        03    ITEM-B            PIC X.
        03    ITEM-C.
            05    ITEM-D OCCURS 3 TIMES.
                07    ITEM-E    PIC X.
                07    ITEM-F    PIC 9999 COMP SYNC.
                07    ITEM-G    PIC X.
        03    ITEM-H            PIC X.

In this example:

- A fill byte is added after each occurrence of ITEM-D to maintain 2-byte boundary alignment of the next occurrence.
- ITEM-D is 5 bytes long. The fill byte following ITEM-D is not included in its length.
- ITEM-C is 18 bytes long. Its length includes the fill bytes associated with its subordinate items.
- The record ITEM-A is 21 bytes long.

Example 3

    WORKING-STORAGE SECTION.
    01    ITEM-A.
        03    ITEM-B            PIC X.
        03    ITEM-C.
            05    ITEM-D OCCURS 3 TIMES.
                07    ITEM-E    PIC X.
                07    ITEM-F    PIC 9999 COMP SYNC.
        03    ITEM-H            PIC X.

In this example:

- ITEM-G is omitted.
- ITEM-D is 4 bytes long. No fill bytes are added, since the next occurrence is already aligned on a 2-byte boundary.
- ITEM-C is 12 bytes long.
- The record ITEM-A is 15 bytes long.

## 5.2.4 Alpha-Only Alignment and Padding

The Compaq Alpha Calling Standards for the Tru64 UNIX and OpenVMS Alpha systems specify Alpha natural data alignment and padding. You invoke this alignment by adding the `alignment padding` compiler option to the compile command line, or by using `pad align` directives in your source code. (Refer to the Compaq COBOL User Manual for additional information on the command.)

The natural Alpha alignments and field sizes that apply to elementary COBOL data fields are shown in Table 5-4.

Table 5-4 Alpha Alignment and Padding
Data Types | Alignment Starting Position | Pictures | Usages
--- | --- | --- | ---
8-bit character string | Byte boundary | A, X, 9, Edited | Display
16-bit integer | Word boundary, multiple of 2 | 9(4) | COMP
32-bit integer | Longword boundary, multiple of 4 | 9(8) | COMP
Single-precision real |  |  | COMP-1
64-bit integer | Quadword boundary, multiple of 8 | 9(16) | COMP
Double-precision real |  |  | COMP-2

These alignments and field sizes apply to elementary data items. However, they are extended to group data items at all level numbers by requiring that the alignment of the group data item conforms to the alignment of the largest natural alignment of any elementary data item that is subordinate to the group-item. Every intermediate group data item in Compaq COBOL is a candidate for natural Alpha alignment and padding. Every higher-level data item is padded to be the smallest multiple of the largest natural alignment of any of its subordinate elementary data items that contains the data structure. The alignment and padding can be determined in all cases by following the tree structure through as many levels as required until the elementary data item with the largest natural alignment is found. All elementary data items are aligned and sized within their data structures according to Table 5-4. <>

# 5.3 DATA DIVISION General Format and Rules

Function

The Data Division describes data the program creates, receives as input, manipulates, and produces as output.

Syntax Rules

1. The Data Division follows the Environment Division.
2. The reserved words DATA DIVISION, followed by a period (.) separator character identify and begin the Data Division.

General Rules

1. The Data Division is subdivided into sections. These sections must be in the following order:

   > FILE SECTION.
   > WORKING-STORAGE SECTION.
   > LINKAGE SECTION.
   > REPORT SECTION.
   > SCREEN SECTION. (Alpha)

File Section

2. The File Section defines the structure of data files. It begins with the File Section header containing the reserved words FILE SECTION, followed by a period (.) separator character.
3. File description entries and sort-merge file description entries follow the File Section header. They can be in any order.
4. The file description entry consists of a level indicator (FD), a file-name, and a series of independent clauses.
5. The FD clause specifies the following:
   - How the file records data
   - The sizes of logical and physical records
   - The names of data records (except for report files)
   - The number of lines on a logical printer page
6. An FD entry, followed by one or more record description entries, defines a sequential, relative, or indexed file. Record description entries must immediately follow the associated FD entry.
7. No record description entries may follow the report file description entry.
8. The sort-merge file description entry consists of a level indicator (SD), a file-name, and a series of independent clauses.
9. An SD clause specifies the following:
   - How the file records data
   - The sizes of logical and physical records
   - The names of data records
10. An SD entry specifies the sizes and names of data records for a sort-merge file referred to by SORT and MERGE statements.
11. An SD entry, followed by one or more record description entries, defines a file. Record description entries must immediately follow the associated SD entry.

Working-Storage Section

12. The Working-Storage Section describes records and subordinate data items. These records are not parts of files; rather, the program develops and processes them internally.
13. The Working-Storage Section also describes data items assigned values by the source program.
14. The Working-Storage Section consists of a section header, followed by record description entries.
15. The section header consists of the reserved words WORKING-STORAGE SECTION, followed by a period (.) separator character.
16. A record description entry groups data items that bear a hierarchical relationship to each other. Unrelated data items in the Working-Storage Section can be described as records that are individual elementary items.
17. Record description clauses can be used in the File Section, the Working-Storage Section, or the Linkage Section.
18. The VALUE IS clause can specify the initial value of any item in the Working-Storage Section except index data items (described by the USAGE IS INDEX clause) and index-names (described by the INDEXED BY phrase of the OCCURS clause).
19. If the VALUE IS clause does not specify an initial value, the default initial value for an item depends on the type of data item:

    Data Item Type | Default Initial Value
    --- | ---
    Numeric | Zero
    Index-name | Occurrence number one
    Index data item | Undefined
    Tables | Undefined
    All others | Spaces

Linkage Section

20. The Linkage Section is used only in a called program.
21. The Linkage Section describes data available through the calling program; both the calling and called programs can access this data.
22. To access calling program data items through the Linkage Section, the called program must have a Procedure Division header USING phrase.
23. The structure of the Linkage Section is the same as that of the Working-Storage Section. It consists of a section header followed by record description entries. The section header consists of the reserved words LINKAGE SECTION followed by a period (.) separator character.

Report Section

24. The Report Section defines report files. It begins with the Report Section header: the reserved words REPORT SECTION, followed by a period (.) separator character.
25. Report description entries follow the Report Section header.
26. The report description entry consists of a level indicator (RD), a report name, and a series of independent clauses.
27. An RD clause specifies the following:
    - Identifying characters to be prefixed to each print line in a report
    - The physical structure and organization of a report
    - The name of the report
28. An RD entry, followed by one or more report group description entries, defines a report. Report group description entries must immediately follow the associated report description entry.
29. A report group description entry defines a report group. It specifies the characteristics of a report group and the individual items within a report group.

Screen Section (Alpha)

30. The Screen Section describes a video form and specifies the attributes, behavior, size, and location of each screen item within the video form. The Screen Section is for use with ACCEPT and DISPLAY statements. <>

Additional References

- Section 5.3.53 clause
- Section 6.8.4 statement in Chapter 6
- User-defined words in Section 1.2.1,COBOL Words
- Section 5.3.42 clause
- Refer to the chapter describing alignment in the Compaq COBOL User Manual.

## 5.3.1 FD (File Description) Sequential, Line Sequential (Alpha), Relative, Indexed, and Report File Descriptions

Function

A file description entry describes the physical structure, identification, record names, and names for sequential, line sequential (Alpha), relative, indexed, and report files. It also specifies the internal or external attributes of a file connector and the local or global attributes of a file-name.

*Clauses marked with an asterisk (*) can be in either the SELECT clause of the Environment Division or the file description entry of the Data Division. They cannot be in both places for the same file.

Syntax Rules

Formats 1, 2, 3, and 4---All Files

1. The level indicator FD identifies the start of a file description entry. It must precede file-name.
2. The clauses following file-name can appear in any order.
3. A period (.) separator character must terminate a file description entry.
4. On OpenVMS, the file name written to disk (see the ASSIGN clause in Chapter 4) has the file type .DAT added if no other file type is specified in the corresponding file specification. <>

Format 1---Sequential or Line Sequential (Alpha) Files

5. file-name can refer only to a sequential file.
6. One or more record description entries must follow the file description entry.

Format 2---Relative Files

7. file-name can refer only to a relative file.
8. If a START statement refers to file-name, the file description must include the RELATIVE KEY phrase within the ACCESS MODE clause.
9. One or more record description entries must follow the file description entry.

Format 3---Indexed Files

10. file-name can refer only to an indexed file.
11. On Tru64 UNIX, for information on file-names for indexed files, see the ASSIGN clause in Chapter 4.<>
12. alt-key cannot have the same leftmost character position as that of rec-key or any other alt-key for the same file.
13. One or more record description entries must follow the file description entry.

Format 4---Report Files

14. file-name can refer only to a report file.
15. No record description entries may follow the file description entry for a report file.
16. Only the CLOSE statement and the OPEN statement with the OUTPUT or EXTEND phrase may reference this file description entry.

General Rules

Formats 1, 2, 3, and 4---All Files

1. A file description entry associates file-name with a file connector.
2. On OpenVMS, if the file description entry contains the EXTERNAL clause, the RMS special registers RMS-STS, RMS-STV, and RMS-FILENAME are external registers.
3. If the file description entry contains the GLOBAL clause, the RMS special registers RMS-STS, RMS-STV, and RMS-FILENAME are global registers. <>

Format 1---Sequential and Line Sequential (Alpha) Files

4. If the file description entry contains the LINAGE clause and the EXTERNAL clause, the LINAGE-COUNTER special register is an external data item.
5. If the file description entry contains the LINAGE clause and the GLOBAL clause, the special register LINAGE-COUNTER is a global name.

Format 3---Indexed Files

6. If the file description entry contains the EXTERNAL clause, the segmented key seg-key has the external attribute.
7. If the file description entry contains the GLOBAL clause, the segmented key seg-key is a global name.

Refer to the Compaq COBOL User Manual for examples of the file description entry formats.

## 5.3.2 SD (Sort-Merge File Description)

Function

A sort-merge file description entry describes a sort or merge file's physical structure, identification, and record names.

Syntax Rules

1. The level indicator SD identifies the start of a sort-merge file description. It must precede file-name.
2. The clauses following file-name can appear in any order.
3. A period (.) separator character must terminate a sort-merge file description entry.
4. One or more record description entries must follow the sort-merge file description entry.

General Rule

No input-output statements can refer to a file-name in a sort-merge file description.

Examples

Refer to the Compaq COBOL User Manual for examples of the sort-merge file description entry.

## 5.3.3 RD (Report Description)

Function

The Report Description names a report, specifies any identifying characters to be prefixed to each print line in the report, and describes the physical structure and organization of that report. It also determines whether a report-name is a local name or global name.

Syntax Rules

1. report-name must appear in one and only one REPORT clause.
2. The clauses following report-name may appear in any order. report-name is the highest permissible qualifier that can be specified for LINE-COUNTER, PAGE-COUNTER, and all data-names in the Report Section.

General Rules

1. If the Report Description entry contains the GLOBAL clause, report-name and the special registers LINE-COUNTER and PAGE-COUNTER are global names.
2. The reserved word PAGE-COUNTER references a special register that the compiler creates for each report in the Report Section.
3. In the Report Section, a reference to PAGE-COUNTER can appear only in a SOURCE clause. In the Procedure Division, PAGE-COUNTER can be used anywhere an integer data item can appear.
4. If more than one PAGE-COUNTER exists in a program, PAGE-COUNTER must be qualified by a report-name wherever it is referenced in the Procedure Division.
   In the Report Section, an unqualified reference to PAGE-COUNTER is qualified implicitly by the name of the report containing the reference. Whenever the PAGE-COUNTER of a different report is referenced, PAGE-COUNTER must be explicitly qualified by the other report's report-name.
5. The INITIATE statement causes the Report Writer Control System to set the PAGE-COUNTER of the referenced report to one.
6. PAGE-COUNTER is automatically incremented by one each time the Report Writer Control System executes a page advance.
7. Procedure Division statements may alter the contents of PAGE-COUNTER.
8. The reserved word LINE-COUNTER references a special register that the compiler creates for each report in the Report Section.
9. In the Report Section, a reference to LINE-COUNTER can appear only in a SOURCE clause. In the Procedure Division, LINE-COUNTER can be used anywhere a data item with an integer value can appear. However, only the Report Writer Control System can change the contents of LINE-COUNTER.
10. If there is more than one LINE-COUNTER in a program, Procedure Division references to LINE-COUNTER must be qualified by a report-name.
    In the Report Section, an unqualified reference to LINE-COUNTER is qualified implicitly by the name of the report containing the reference. Whenever the LINE-COUNTER of a different report is referenced, LINE-COUNTER must be explicitly qualified by the other report's report-name.
11. The INITIATE statement causes the Report Writer Control System to set the LINE-COUNTER of the referenced report to zero. The Report Writer Control System also automatically resets LINE-COUNTER to zero each time it executes a page advance.
12. The execution of SUPPRESS statements and the processing of nonprintable report groups do not change the value of LINE-COUNTER.
13. At the time each print line is presented, the value of LINE-COUNTER represents the line number on which the print line is presented. After the presentation of the report group, the value of LINE-COUNTER is governed by the Report Writer Presentation Rules and Tables.

Additional References

- Section 5.3.32 clause
- Section 5.3.42 clause
- Section 5.3.1
- Appendix D, Report Writer Presentation Rules and Tables

Example

The following is an example of a global Report Description entry:

    FILE SECTION.
    FD   WEEKLY-REPORTS...
         REPORTS ARE PAYROLL-REPORT
                     PAYROLL-IRS.
    REPORT SECTION.

    RD   PAYROLL-REPORT
         IS GLOBAL
         CODE "AA"
         CONTROL GRAND-TOT
                 SITE-TOT
                 DEPT-TOT
                 GROUP-TOT
         PAGE LIMITS ARE 60 LINES
                 HEADING       2
                 FIRST DETAIL  9
                 LAST DETAIL  55
                 FOOTING      58.

    RD  PAYROLL-IRS
        CODE "BB"...

The previous example uses the CODE clause to flag PAYROLL-REPORT records from other records (see PAYROLL-IRS) included in the same file (WEEKLY-REPORTS). The entry defines four control totals. GRAND-TOT is the most major control total; it will be printed only at the end of the report. SITE-TOT, DEPT-TOT, and GROUP-TOT are major, intermediate, and minor control totals, respectively. These totals are printed whenever the Report Writer Control System (RWCS) processes a control break. The entry also defines a report page with 60 lines. On each page the RWCS is to print PAYROLL-REPORT headings beginning on line 2, detail lines from lines 9 to 55, and footings beginning on line 58.

## 5.3.4 Data Description

Function

A data description entry specifies the characteristics of a data item.

Syntax Rules

1. level-number in Format 1 can be any number from 01 to 49, or 77.
2. Data description clauses can appear in any order, with two exceptions:
   - The optional data-name or FILLER clause must immediately follow level-number.
   - The optional REDEFINES clause must immediately follow the optional data-name or FILLER clause.
3. The EXTERNAL clause can appear in a level 01 or 77 data description entry in the Working-Storage Section.
4. The GLOBAL clause can appear in a level 01 or 77 data description entry in the Working-Storage Section, or in a level 01 data description entry in the File Section.
5. The EXTERNAL and REDEFINES clauses cannot be in the same data description entry.
6. data-name must appear in any Format 1 entry that contains the EXTERNAL clause or GLOBAL clause, or in the record descriptions of a file description entry that contains the EXTERNAL or GLOBAL clause.
7. There must be a PICTURE clause for all elementary items except the following:
   - An index data item
   - A COMP-1 or COMP-2 data item
   - The subject of a RENAMES clause
   - A POINTER data item
   In these cases, there must be no PICTURE clause.
8. The words THRU and THROUGH are equivalent.
9. The SYNCHRONIZED, PICTURE, JUSTIFIED, and BLANK WHEN ZERO clauses can appear only in Data Description entries for elementary items.

General Rules

1. Each condition-name requires a separate Format 3 entry. The level 88 entry associates one or more values, or ranges of values, with condition-name.
   All condition-name entries for an associated data item (the conditional variable) must immediately follow that item's data description entry.
   Any condition-name associated with a global conditional variable is global.
   A condition-name can be associated with a data item at any level except:
   - Another condition-name
   - A level 66 item
   - A group that contains items with JUSTIFIED, SYNCHRONIZED, or USAGE (other than USAGE IS DISPLAY) clauses
   - An index data item
2. Multiple level 01 data description entries subordinate to an FD or SD entry implicitly redefine the same area.

Previous | Next | Contents | Index