# Compaq COBOL

# Reference Manual

Order Number: AA--Q2G0G--TK

# November 2002

This manual provides reference information and syntax for the Compaq COBOL programming language on its three platforms: OpenVMS Alpha, OpenVMS VAX, and Tru64 UNIX Alpha.

Revision/Update Information: This manual supersedes the Compaq COBOL Reference Manual, Version 2.7 and the VAX COBOL Reference Manual, Version 5.4, as well as the online-only Compaq COBOL Reference Manual, Version 2.7 and Version 5.7.

Operating System and Version:
OpenVMS Alpha Version 6.2 or higher;
OpenVMS VAX Version 6.2 or higher;
Tru64 UNIX Version 5.0 or higher

Software Version:
Compaq COBOL for OpenVMS Alpha Version 2.8;
Compaq COBOL for Tru64 UNIX Version 2.8;
Compaq COBOL for OpenVMS VAX Version 5.7

Compaq Computer Corporation
Houston, Texas

© 2002 Compaq Information Technologies Group, L.P.

COMPAQ, the Compaq logo, AlphaServer, OpenVMS, POLYCENTER, Tru64, VAX, and VMS are trademarks of Compaq Information Technologies Group, L.P. in the U.S. and/or other countries.

Motif, UNIX, and X/Open are trademarks of The Open Group in the U.S. and/or other countries.

All other product names mentioned herein may be trademarks of their respective companies.

Confidential computer software. Valid license from Compaq required for possession, use, or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commercial license.

None of Compaq, Hewlett-Packard Company ("HP") or any other direct or indirect subsidiary of HP shall be liable for technical or editorial errors or omissions contained herein. The information in this document is provided "as is" without warranty of any kind and is subject to change without notice. The warranties for Compaq or HP products are set forth in the express limited warranty statements accompanying such products. Nothing herein should be construed as constituting an additional warranty.

ZK6296

This manual is available on CD-ROM.

Contents | Index

# Preface

This book describes the constructs and rules of the Compaq COBOL programming language, which is a Compaq Computer Corporation implementation of COBOL (COmmon Business-Oriented Language) for the OpenVMS and Tru64 UNIX platforms. It includes information about language syntax and semantics, as well as information about adherence and extensions to various COBOL standards.

This documentation set also includes the Compaq COBOL User Manual and, optionally, the Compaq COBOL DBMS Database Programming Manual.

Compaq COBOL is the new name for DEC COBOL, for DIGITAL COBOL, and for VAX COBOL. Compaq COBOL, unmodified, refers to three products:

> Compaq COBOL for OpenVMS Alpha
> Compaq COBOL for Tru64 UNIX
> Compaq COBOL for OpenVMS VAX

Any references to the former names in product documentation or other components should be construed as references to the Compaq COBOL names.

# Intended Audience

This manual is intended for experienced applications programmers who have a thorough understanding of the COBOL language and some familiarity with their operating system. This is not a tutorial manual.

If you are a new COBOL user, you may need to read introductory COBOL textbooks or take COBOL courses.

# Structure of This Document

This manual is organized as follows:

- Chapter 1 presents the elements of the COBOL language, describes two format options for a COBOL program, and explains how the remaining chapters organize and present the COBOL general formats.
- Chapter 2 describes the organization of a COBOL program. It presents the general format for the four COBOL divisions and introduces the concept of contained programs. This chapter shows the relationship between a program name and a source file name.
- Chapter 3 describes the general format and contents of the Identification Division. It explains how to identify a COBOL program and its source listing.
- Chapter 4 describes the general format and contents of the Environment Division. It explains how to describe the program's physical environment.
- Chapter 5 describes the general format and contents of the Data Division. It explains how to describe data the program receives, creates, manipulates, and produces as output.
- Chapter 6 describes the general format and contents of the Procedure Division. It describes COBOL verbs, which process the files and data in the Environment and Data Divisions.
- Chapter 7 describes the general format and use of the intrinsic functions.
- Chapter 8 describes the general format of the COPY and REPLACE statements.
- Appendix A lists the Compaq COBOL reserved words, which are words that cannot be used as system names or user-defined names.
- Appendix B lists the ASCII, EBCDIC, and NATIVE character sets.
- Appendix C lists the exception condition values that can appear in File Status data items.
- Appendix D contains individual presentation rules and tables for each type of report group.
- Appendix E describes RTL routines for accessing the RAB and FAB structures on OpenVMS systems.
- The Glossary contains an alphabetical listing of common Compaq COBOL terms and their definitions.
- The Index indexes and references terms and concepts in this manual.

# Associated Documents

The following documents contain additional information directly related to various topics covered in this manual:

Compaq COBOL User Manual

This manual describes how to use features of the Compaq COBOL language to develop programs on the Tru64 UNIX operating system or the OpenVMS operating systems on Alpha and VAX.

Release Notes

Consult the Compaq COBOL release notes for your installed version for late corrections and new features.

On the OpenVMS Alpha or VAX operating system, the release notes are in:

> SYS$HELP:COBOLnnn.RELEASE_NOTES (ASCII text)
> SYS$HELP:COBOLnnn_RELEASE_NOTES.PS
> SYS$HELP:COBOLnnn_RELEASE_NOTES.PDF (Portable Document Format file)

Where nnn is the version and release number.

On the Tru64 UNIX operating system, the release notes are in:

> /usr/lib/cmplrs/cobol/relnotes

Compaq COBOL for Tru64 UNIX Systems Installation Guide

This manual provides instructions for installing Compaq COBOL on the Tru64 UNIX operating system.

Compaq COBOL for OpenVMS Alpha Systems Installation Guide

This manual provides instructions for installing Compaq COBOL on the OpenVMS Alpha operating system.

Compaq COBOL for OpenVMS VAX Systems Installation Guide

This manual provides instructions for installing Compaq COBOL on the OpenVMS VAX operating system.

Compaq COBOL DBMS Database Programming Manual

This manual provides information on using Compaq COBOL for database programming with Oracle CODASYL DBMS on the OpenVMS Alpha or OpenVMS VAX operating system.

The OpenVMS Calling Standard and other manuals in the OpenVMS Documentation Set

This set contains information about using the features of the OpenVMS Alpha and OpenVMS VAX operating systems and their tools.

The Tru64 UNIX Documentation Set

This set contains introductory and detailed information about using the features of the Tru64 UNIX operating system and its tools.

The Alpha Architecture Reference Manual

This manual is available from Digital Press.

# Related Documents

For additional information about OpenVMS products and services, access the following World Wide Web address:

    http://www.compaq.com/

# Conventions Used in This Document

The following table lists the conventions used in this manual:

# References

The following table shows certain references and their respective meanings in this manual:

Reference | Meaning
--- | ---
Alpha | OpenVMS Alpha or Tru64 UNIX Alpha operating system
OpenVMS | OpenVMS Alpha or OpenVMS VAX operating system
Tru64 UNIX | Tru64 UNIX Alpha operating system
VAX | OpenVMS VAX operating system

Tru64 UNIX was formerly known as DEC OSF/1 or as DIGITAL UNIX. Compaq COBOL was formerly known as DIGITAL COBOL or DEC COBOL. Compaq COBOL for OpenVMS VAX was formerly known as VAX COBOL or as DIGITAL VAX COBOL.

# Acknowledgement

COBOL is an industry language and is not the property of any company or group of companies, or of any organization or group of organizations.

No warranty, expressed or implied, is made by any contributor or by the CODASYL COBOL Committee as to the accuracy and functioning of the programming system and language. Moreover, no responsibility is assumed by any contributor, or by the committee, in connection therewith.

The authors and copyright holders of the copyrighted material used herein are as follows: FLOW-MATIC (trademark of Unisys Corporation), Programming for the UNIVAC (R) I and II, Data Automation Systems, copyrighted 1958, 1959, by Unisys Corporation; IBM Commercial Translator Form No. F28-8013, copyrighted 1959 by IBM; FACT, DSI 27A5260-2760, copyrighted 1960 by Minneapolis-Honeywell.

They have specifically authorized the use of this material, in whole or in part, in the COBOL specifications. Such authorization extends to the reproduction and use of COBOL specifications in programming manuals or similar publications.

# How to Order Additional Documentation

Visit the following World Wide Web address for information about how to order additional documentation:

    http://www.openvms.compaq.com/doc/

# Reader's Comments

Compaq welcomes your comments on this manual. Please send comments to either of the following addresses:

Internet | openvmsdoc@hp.com
Mail | Compaq Computer Corporation OSSG Documentation Group, ZKO3-4/U08 110 Spit Brook Rd. Nashua, NH 03062-2698

# Chapter 1
Overview of the COBOL Language

This chapter provides information about the structure and language of COBOL source programs. It describes the elements of the COBOL language, reference formats, and language organization.

The COBOL language consists of the following components:

- Programs
- Divisions
- Sections
- Paragraphs
- Sentences
- Statements
- Clauses
- Entries
- Words
- Characters

A separately compiled COBOL program is a program that, together with its contained programs (if present), is compiled separately from all other programs. Each COBOL program is divided into four parts, called divisions: the Identification Division, Environment Division, Data Division, and Procedure Division. Divisions can contain sections, which in turn can contain paragraphs. Paragraphs can contain sentences, clauses, statements, or entries.

The building blocks of these language components include the COBOL character set, character-strings, separators, punctuation, and literals.

A COBOL program is a string of characters that is syntactically correct according to the COBOL language rules.

# 1.1 The COBOL Character Set

The COBOL character set, shown in Table 1-1, is used to form character-strings and separators.

The only components of a COBOL program that can contain characters outside this set are nonnumeric literals, comment-entries, and comment lines. Appendix B specifies the more inclusive computer character sets these elements can use.

Table 1-1 The COBOL Character Set
Character | Meaning
--- | ---
0, 1, ..., 9 | digit
A, B, ..., Z | letter
a, b, ..., z | lowercase letter (equivalent to letter)
+ | plus sign
- | minus sign (hyphen)
* | asterisk
/ | slash (stroke, virgule)
\ | backslash
= | equal sign
$ | currency sign
> | greater than symbol
< | less than symbol
: | colon
_ | underline (underscore)
| space
`[Tab]` | horizontal tab
( | left parenthesis
) | right parenthesis
, | comma (decimal point)
; | semicolon
. | period (decimal point, full stop)
" | quotation mark (double quotation mark)
' | apostrophe (single quotation mark)
{ | left brace
} | right brace
[ | left bracket
] | right bracket
« | double left-angle brackets
» | double right-angle brackets

Except in nonnumeric literals, the compiler treats lowercase letters as if they were uppercase. Therefore, a program can contain COBOL words without regard to case.1 For example, the compiler recognizes the COBOL words in each of the following pairs as identical:

    WORKING-STORAGE      Working-Storage
    Input                input
    file-a               FILE-A
    INSPECT              InSpect

Note #### 1 On Tru64 UNIX the case sensitivity of the system affects COBOL's case insensitivity in a few situations. See the Section 3.1.1 paragraph in Chapter 3, and the section on Section 6.8.4 in Chapter 6. Also refer to the Compaq COBOL User Manual for a description of the -names lowercase, -names uppercase, and -names as_is flags.

# 1.2 Character Strings

A character-string is a character or a sequence of contiguous characters that form a COBOL word, a literal, a PICTURE character-string, or a comment-entry. Separators delimit character-strings. The following sections describe these topics in detail.

## 1.2.1 COBOL Words

A COBOL word is a character-string of not more than 31 characters that forms one of the following:

- A user-defined word
- A system-name
- A reserved word
- A function-name

A user-defined word or system-name cannot be a reserved word. However, a program can use the same COBOL word as both a user-defined word and a system-name. The compiler determines the word's class from its context.

### 1.2.1.1 User-Defined Words

A user-defined word is a COBOL word that you must supply to satisfy the format of a clause or statement. This word consists of characters selected from the set A to Z, 0 to 9, the currency sign ($), underline (_), and hyphen (-). Throughout this manual, and except where specific rules apply, the hyphen (-) and the underline (_) are treated as the same character in a user-defined word. The underline (_), however, can begin or end a user-defined word, and the hyphen (-) cannot. By convention, names containing a currency sign ($) are reserved for Compaq.

Table 1-2 provides brief descriptions of the COBOL user-defined words.

Table 1-2 COBOL User-Defined Words
User-Defined Word | Purpose
--- | ---
Alphabet-Name | Assigns a name to a character set, collating sequence, or both. Alphabet-names must be defined in the SPECIAL-NAMES paragraph. (See Section 4.1.3 in Chapter 4, Environment Division.)
Class-Name | Relates a name to a specified set of characters listed in that clause. (See Section 4.1.3 in Chapter 4, Environment Division.)
Condition-Name | Assigns a name to a value, set of values, or range of values in the complete set of values that a data item can have. Data items with one or more associated condition-names are called conditional variables. Data Division entries define condition-names. Names assigned in the SPECIAL-NAMES paragraph to the "on" or "off" status of switches are also condition-names.
Data-Name | Names a data item described in a data description entry. When specified in a general format, data-name cannot be reference modified, subscripted, indexed, or qualified unless specifically allowed by the rules for that format.
File-Name | Names a file connector. A file connector is a storage area that contains information about a file and is the link between: A file-name and a physical file A file-name and its associated storage area File description entries and sort-merge file description entries describe file connectors.
Index-Name | Names an index associated with a specific table.
Level-Number | Is a one- or two-digit number that describes a data item's special properties or its position in the structure of a record. (See Sections 5.1.1 and 5.1.2.)
Library-Name | Names a COBOL library used in a source program compilation. (See the Section 8.1.1 statement in Chapter 8.)
Mnemonic-Name | Associates a name with a system-name, such as CONSOLE, SYSERR, ARGUMENT-NUMBER, ENVIRONMENT-NAME, C01, OR SWITCH-8. (See Section 4.1.3 in Chapter 4.)
Paragraph-Name | Names a Procedure Division paragraph. (See Section 2.1.3.) Paragraph-names are equivalent only if they are identical; that is, if they are composed of the same sequence and number of digits and/or characters. For example:
START-UP | START-UP | Equivalent
START-UP | STARTUP | Different
Start-up | START-UP | Equivalent
001-START-UP | 01-START-UP | Different
017 | 017 | Equivalent
017 | 17 | Different
Program-Name | Identifies a COBOL source program. (See the Section 3.1.1 paragraph in Chapter 3, and the section on Section 6.8.4 in Chapter 6, for a description of case-sensitivity on the Tru64 UNIX operating system. Also refer to the Compaq COBOL User Manual for a description of the `-names lowercase` , `-names uppercase` , and `-names as_is` flags.)
Record-Name | Names a data item described with level-number 01 or 77.
Report-Name | Names a report produced by the Report Writer Control System (RWCS). (See the Section 5.3.42 clause in Chapter 5.)
Screen-Name (Alpha) | Names a screen item defined in the SCREEN SECTION of a program. (See the Section 5.3.6 section of Chapter 5.)<>
Section-Name | Names a Procedure Division section. Section-names are equivalent only if they are identical; that is, when they are composed of the same sequence and number of digits and/or characters. (See Section 2.1.2.)
Segmented-Key-Name | Identifies a segmented key, which is a concatenation of one or more (up to eight) data items (segments) within a record associated with an indexed file. A segmented key is a form of primary or alternate key. It offers flexibility in defining record description entries for indexed files. (Refer to the section on segmented keys in the Compaq COBOL User Manual.)
Segment-Number | Is a 1- or 2-digit number that classifies a Procedure Division section for segmentation. In Compaq COBOL programs, segment-numbers specify independent and fixed segments. (See Section 6.7.)
Symbolic-Character | Identifies a user-defined figurative constant.
Text-Name | Identifies library text in a COBOL library. (See the Section 8.1.1 statement in Chapter 8.)

Within a given program, but excluding any contained program, the user-defined words are grouped into the following disjoint sets:

> alphabet-names
> class-names
> condition-names, data-names, and record-names
> file-names
> index-names
> library-names
> mnemonic-names
> paragraph-names
> program-names
> report-names
> screen-names
> section-names
> segmented-key-names
> symbolic-characters
> text-names

Next | Contents | Index