Concepts of the COBOL LanguageNext

Chapter 1: Introduction to the COBOL Language

1.1 The COBOL Language

COBOL (COmmon Business Oriented Language) is the programming language most widely and extensively used in commercial and administrative data processing.

This COBOL implementation is a superset of the ANSI and ISO COBOL standard as specified in ANSI X3.23-1974 (ISO 1989-1978), and of the current ANSI and ISO COBOL standard as specified in ANSI X3.23-1985 (IS 1989:1985), ANSI X3.23a-1989 (IS 1989:1985/AM1), and ANSI X3.23b-1993 (IS 1989:1985/AM2). Language extensions include:

Combinations of these extensions are permissible in program source. In addition a "flagging" option to identify the various language extensions in COBOL source programs ensures that programs can be verified as being valid for any given one of the language specifications.

The ANSI COBOL 1974 and 1985 modules that are fully implemented are:

This COBOL system meets the certification requirements for the above modules of The COBOL Compiler Validation System (CCVS) of the U.S. Department of Commerce, National Institute of Standards and Technology.

A number of additional enhancements to the COBOL language are present:

1.2 Source Format

Source code can be in

free format or

fixed format.

1.2.1 Fixed Format

In fixed format, the COBOL source format divides each COBOL source record into 72 columns. These columns are used in the following way:

Columns 1 - 6 Sequence number
Column 7 Indicator area
Column 8 - 11 Area A
Columns 12 - 72 Area B

A COBOL source record can extend up to 80 columns in length. The contents of columns 73 to 80 are ignored by the COBOL system.

1.2.2 Sequence Number

A sequence number of six digits can be used to identify each source program line.

If the first character position of the sequence number field contains an asterisk, or any nonprinting control character (less than the character SPACE in the ASCII collating sequence), then the line is treated as comment and is not output to the listing file or device. This facility allows an output listing file to be used as a source file to a subsequent compilation.

This support is sensitive to the MFCOMMENT Compiler directive.

The sequence number can contain any character in the computer's character set.

1.2.3 Indicator Area

An asterisk (*) in the indicator area marks the line as documentary comment only. Such a comment line can appear anywhere in the program after the IDENTIFICATION DIVISION header. Any characters from the ASCII character set can be included in area A and area B of the line.

A comment line can appear before the IDENTIFICATION DIVISION header.

A slash (/) in the indicator area acts as a comment line above but causes the page to eject before printing the comment.

A "D" or "d" in the indicator area represents a debugging line. Areas A and B can contain any valid COBOL sentence.

A "–" in the indicator area represents a continuation of the previous line without spaces or the continuation of a nonnumeric literal (see the chapter Concepts of a COBOL Program).

A "$" in the indicator area indicates a special line for setting directives or conditional compilation.

1.2.4 Areas A and B

Section names and paragraph names begin in area A and are followed by a period and a space. Level indicators FD, SD, CD and RD begin in area A and are followed in area B

or area A

by the appropriate description. Level numbers 01 and 77 begin in area A and are followed in area B

or area A

by the data description. Level numbers 02 through 49, 66 and 88 begin in area B.

Level number 78 can begin in area A or area B.

No rules regarding area A and area B are enforced except in relation to comment-entries in the Identification Division.

The concept of area A and area B is removed when free format source code is used. See the next section in this chapter for additional information on free format source code.

More than one sentence is permitted in each source record.

Figure 1-1 shows the source format of a typical program.

000010 identification division. 
000020 program-id. stock-file-set-up. 
000030 author. micro focus ltd. 
000040 environment division. 
000050 configuration section. 
000060 source-computer. mds-800. 
000070 object-computer. mds-800. 
000075 special-names. console is crt. 
000080 input-output section. 
000090 file-control. 
000100  select stock-file assign "stock.it" 
000110  organization indexed 
000120  access dynamic 
000130  record key stock-code. 
000140 data division. 
000150 file section. 
000160 fd   stock-file record 32. 
000170 01   stock-item. 
000180  02  stock-code       pic x(4). 
000190  02  product-desc     pic x(24). 
000200  02  unit-size        pic 9(4). 
000210 working-storage section. 
000220 01   screen-headings. 
000230  02  ask-code pic x(21) value "stock code    <    >".
000240  02  filler   pic x(59). 
000250  02  ask-desc pic x(16) value "description   <".
000260  02  si-desc  pic x(25) value "                 >".
000270  02  filler   pic x(39). 
000280  02  ask-size pic x(21) value "unit size <    >".
000290 01   enter-it redefines screen-headings. 
000300  02      filler       pic x(12). 
000310  02  crt-stock-code   pic x(4).
000320  02      filler       pic x(80). 
000330  02  crt-prod-desc    pic x(24). 
000340  02      filler       pic x(51). 
000350  02  crt-unit-size    pic 9(4). 
000360  02  filler           pic x. 
000370 procedure division. 
000380 sr1. 
000390  display space. 
000400  open i-o stock-file. 
000410  display screen-headings. 
000420 normal-input. 
000430  move space to enter-it. 
000440  display enter-it. 
000450 correct-error.
000460  accept enter-it. 
000470  if crt-stock-code = space go to end-it. 
000480  if crt-unit-size not numeric go to correct-error. 
000490  move crt-prod-desc to product-desc. 
000500  move crt-unit-size to unit-size. 
000510  move crt-stock-code to stock-code. 
000520  write stock-item invalid key go to correct-error. 
000530  go to normal-input. 000540 end-it. 
000550  close stock-file. 
000560  display space. 
000570  display "end of program". 
000580  stop run.
<---->|<--><--------------------------------------------------------->
  |   | |     |
  |   | |     +-- Columns 12-72 - Area B
  |   | +-- Columns 8-11 - Area A
  |   +-- Column 7 - Indicator Area
  +-- Columns 1-6 - Sequence Numbers

Figure 1-1: Sample program Listing Showing Source Format

1.2.5 Free Format

Free format COBOL is selected using the SOURCEFORMAT"FREE" directive.

The first six characters are considered part of the normal source line and may contain COBOL source code. Column 1 takes the role of the indicator area as follows:

* comment line
/ comment line starting on a new page in the listing file
D or d followed by space, debugging line
$ special line (for example, directive, conditional compilation)
any other character normal source line

There are no continuation lines. Continuation of alphanumeric literals is achieved through concatenation (for example, "A" & "B").

There is no distinction between area A and area B.

There is no fixed right margin, though for practical purposes this implementation restricts the maximum length of a source line to 250 single-byte or 125 double-byte characters.

Comment-entries are only allowed on the same line as the paragraph header and must not continue onto another line.


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

Concepts of the COBOL LanguageNext