Microsoft KB Archive/48634

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

General Outline of the COBOL Language

PSS ID Number: Q48634 Article last modified on 11-16-1992

1.07 1.12 2.00 2.10 2.20 3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: This article summarizes the structure of an ANSI ’74 COBOL program. It outlines the essential features of the COBOL language. This article is not a tutorial on the language or a detailed explanation. This article gives a general overview of the COBOL language. This information applies to Microsoft COBOL Versions 1.07, 1.12, 2.00, 2.10, 2.20, 3.00, and 3.00a for MS-DOS and COBOL 3.00 and 3.00a for MS OS/2.

More Information:

Outline of a COBOL Program

The following DIVISIONs and SECTIONs make up a COBOL program: +————————————————————-+ | IDENTIFICATION DIVISION | | The program, author, date written, and date compiled | | are stated here. | |————————————————————-| | ENVIRONMENT DIVISION | | The computing systems to be used and the files to be | | processed are specified here. | |————————————————————-| | DATA DIVISION | | The following SECTIONs are specified here: | | | | FILE SECTION | | The input and output files, and their records, are | | described here. | | WORKING-STORAGE SECTION | | General data items are defined here. | | SCREEN SECTION | | Terminal screens are defined here. | | LINKAGE SECTION | | Data that is referenced by calling and called | | programs is described here. | |————————————————————-| | PROCEDURE DIVISION. | | The working code (executed at run time) goes here. | +————————————————————-+

What Is COBOL?

COBOL is an English-like batch-oriented language used for business applications. It was standardized to run on mainframe computers and to be portable between different systems. COBOL is an acronym for COmmon Business Oriented Language. COBOL was invented in 1959 by Dr. Grace Hopper, a mathematician who is now a retired Rear Admiral for the U.S. Navy. COBOL’s English-like nature is designed to make the language self-documenting. A well-written COBOL program needs a minimal amount of commenting.

Hierarchy of a COBOL Program

The COBOL language is ordered with the following conceptual hierarchy, from general to specific: General – DIVISIONs | – SECTIONs | – Paragraphs | – Sentences | – Clauses v – Words and verbs Specific – Data items

Code Format

The requirement for certain COBOL statements to be in certain columns is a carry-over from the days of Hollerith computer cards. COBOL code must be aligned by column as follows: +—————————————————+ | Term | Column | Usage | |———+———+——————————-| | none | 1 - 6 | Line numbers. | |———+———+——————————-| | none | 7 | * For remark. | | | | - For line continuation to | | | | resume non-numeric literal.| |———+———+——————————-| | Area A | 8 | Division headers. | | | | Section headers. | | | | Paragraph names. | | | | FD, SD, RD entries. | | | | 01 and 77 entries. | |———+———+——————————-| | Area B | 12 | 02 - 49, and 88 entries. | | | | Sentences. | +—————————————————+ Note: Microsoft COBOL Versions 2.x follow these column alignments strictly. Microsoft COBOL Versions 3.x are slightly more flexible about Area A violations.

Elements of the COBOL Language

  1. Reserved Words
  2. Figurative Constants For example: SPACES, ZERO, HIGH-VALUES, LOW-VALUES
  3. Data Items
    1. Elementary Data Items
      1. Elementary data items are described with PICTURE clauses. PIC Clause Description ———- ———– PIC A Alphabetic only PIC X Alphanumeric PIC 9 Numeric only PIC 9V9 Numeric with implied decimal PIC S9 Numeric trailing sign PIC ZZ999.99 Numeric edited, which supports the following formatting characters: Z Blank if zero $ Floating dollar sign * Asterisk fill for protection on checks, etc. - Floating minus , Fixed comma for formatting Example of numeric edited: PIC $Z,Z99.99-
      2. Elementary data items can be COMPUTATIONAL numeric fields, which store numbers in an internal format (which may vary between different compiler brands). For example, COMP-3, which is packed decimal, is a common format supported by most compilers.
    2. Group Items (also known as Records) Group items are considered alphanumeric when accessed by their group name.
    3. Level Numbers Level numbers are used to define which data items are subordinate to others: Level Usage —– —– 01 - 49 Group and elementary data items 77 Independent data items – no subordinates allowed 88 Named conditionals – Booleans
  4. Data Names and Procedure Names These names have a maximum of 30 characters but must have at least one alphabetic character.
  5. The four DIVISIONS of a COBOL Program
    1. IDENTIFICATION DIVISION. PROGRAM-ID. program name. [AUTHOR.] [DATE-WRITTEN.] [DATE-COMPILED.]
    2. ENVIRONMENT DIVISION. [CONFIGURATION SECTION.] [SOURCE-COMPUTER.] [OBJECT-COMPUTER.] [SPECIAL-NAMES.] INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT clauses.
    3. DATA DIVISION. FILE SECTION. FD. WORKING-STORAGE SECTION. Data items or variables are defined here.
    4. PROCEDURE DIVISION. Code to be executed at run time is defined here.

File Types Supported by COBOL

  1. Sequential
  2. Line sequential
  3. Relative
  4. ISAM

Other Notes of Interest Regarding the COBOL Language

  1. COBOL supports an array data type called a “table.”
  2. PERFORM and IF are the most common control structures.
  3. There is no assignment of one variable to another. You must MOVE one data item to another.
  4. COBOL supports a variant record by using the REDEFINES clause.
  5. Math is cumbersome in COBOL. For example, the following are equivalent statements: MULTIPLY total-sales BY percentage-rate GIVING commission-amt. COMPUTE commission-amt= total-sales * percentage-rate.

Copyright Microsoft Corporation 1992.