Compaq COBOL
Reference Manual


Previous Contents Index

In this example:

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:

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:

5.2.4 Alpha Alignment and Padding

The Compaq Alpha Calling Standards for the Tru64 UNIX, OpenVMS Alpha, and Windows NT 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. (See 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.

File Section

  1. 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.
  2. File description entries and sort-merge file description entries follow the File Section header. They can be in any order.
  3. The file description entry consists of a level indicator (FD), a file-name, and a series of independent clauses.
  4. The FD clause specifies the following:
  5. 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.
  6. No record description entries may follow the report file description entry.
  7. The sort-merge file description entry consists of a level indicator (SD), a file-name, and a series of independent clauses.
  8. An SD clause specifies the following:
  9. An SD entry specifies the sizes and names of data records for a sort-merge file referred to by SORT and MERGE statements.
  10. 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

  1. 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.
  2. The Working-Storage Section also describes data items assigned values by the source program.
  3. The Working-Storage Section consists of a section header, followed by record description entries.
  4. The section header consists of the reserved words WORKING-STORAGE SECTION, followed by a period (.) separator character.
  5. 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.
  6. Record description clauses can be used in the File Section, the Working-Storage Section, or the Linkage Section.
  7. 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).
  8. 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

  1. The Linkage Section is used only in a called program.
  2. The Linkage Section describes data available through the calling program; both the calling and called programs can access this data.
  3. To access calling program data items through the Linkage Section, the called program must have a Procedure Division header USING phrase.
  4. 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

  1. The Report Section defines report files. It begins with the Report Section header: the reserved words REPORT SECTION, followed by a period (.) separator character.
  2. Report description entries follow the Report Section header.
  3. The report description entry consists of a level indicator (RD), a report name, and a series of independent clauses.
  4. An RD clause specifies the following:
  5. 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.
  6. 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

  1. 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

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

Function

A file description entry describes the physical structure, identification, record names, and names for sequential, line sequential, 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 Files

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

Format 2---Relative Files

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

Format 3---Indexed Files

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

Format 4---Report Files

  1. file-name can refer only to a report file.
  2. No record description entries may follow the file description entry for a report file.
  3. 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 Files

  1. If the file description entry contains the LINAGE clause and the EXTERNAL clause, the LINAGE-COUNTER special register is an external data item.
  2. 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

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

See 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

See 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

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:
  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:
    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:
  2. Multiple level 01 data description entries subordinate to an FD or SD entry implicitly redefine the same area.


Previous Next Contents Index