A Guide to COBOL Programming [1 ed.] 0471582433, 9780471582434


116 81 12MB

English Pages 196 Year 1969

Report DMCA / Copyright

DOWNLOAD PDF FILE

Recommend Papers

A Guide to COBOL Programming [1 ed.]
 0471582433, 9780471582434

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

A

GUIDE TO

COBOL PROGRAMMING

DANIEL

D.

McCRACKEN

Mccracken associates,

inc.

a guide

to

COBOL programming JOHN WILEY & SONS,

INC.,

NEW YORK



LONDON

Copyright

©

1963 by John Wiley & Sons,

This book must not be reproduced

All Rights Reserved.

thereof

or in

Inc.

any part any form

without the written permission of the publisher.

Library of Congress Catalog Card

Number: 63-16019

Printed in the United States of America

PREFACE

This book

is

written for the person

who wants

to get a rapid grasp of the application of

puters to the problems of business. is

com-

COBOL

one of the most widely used languages for

several chapters will allow the reader to try

COBOL

All of the essential

The book

is

matters are

therefore consider-

ably more than a simple text on * It

presents

ma-

end of the book.

The book

*

is

organized so that each reader

can easily select the material of value to him.

explained fully within the framework of applications.

COBOL

at applying the

answers to about half are given at the

terial;

such work and an excellent vehicle for the

study of computer applications.

own hand

his

COBOL.

much background information

The person who wants only a quick picture of programming in general, having no background

can study Chapters

in computers,

which include a

to 4,

realistic

1

case study;

Chapters 5 to 8 develop the rest of the

on the data-processing needs and methods of

COBOL

business in an introductory chapter and in

application; Chapter 9 discusses object pro-

case studies.

gram

* It

presents as

much background on com-

puter characteristics as

stand

is

needed to under-

COBOL.

*

There are three extended case studies, which, besides illustrating COBOL methods

and showing typical applications of computers in business, describe the method of attack in applying a computer to a business problem. The reader thus gets an over-all view of the complete "task of going from a

material and illustrate a full-scale

efficiency; the case

and outlines the complete process of going from a problem statement to a successful long-term operation. The person who already knows programming and is interested only in a quick explanation of

COBOL

difficulty in

text

that

material

COBOL.

in a reference

and *

have

relates

specifically

to

In general, the sequence of topics

of application system design.

efficiency is

will

1

picking out the half of the

trast to the order in

The important

can skip Chapters

and 2 and skim the case studies; he no

problem statement to a running program, including many of the fundamental principles *

study in Chapter 10

describes another application area

has been chosen to facilitate learning, in con-

which they are presented

manual.

subject of object program

In addition to the obvious usefulness of this

emphasized throughout the text

book

in a separate chapter.

Most chapters contain

extensive sets of

review questions to allow the reader to test

knowledge of what he has just studied; answers to all questions are given immedi-

for self-study of

COBOL

data processing in general,

and businesshoped that

it is

because of the organization, review questions,

and exercises

it

will find application in sev-

his

ately following the questions.

gains

many

grammed

of

text.

the

eral types of formal courses.

The book thus

advantages of a pro-

Other exercises at the end of

1.

in

It

can be used as the text for a course

COBOL

programming, preferably with a if a computer is available.

term problem

VI

PREFACE 2.

It

can be used as the text for a three-

semester hour course in business-data processing

and programming.

(Such a course

is

rapidly becoming recognized as an essential

part of the training of any graduate in com-

merce, accounting, business administration, etc.) 3.

Students in industrial courses in

programming

will find it useful as

COBOL

an elabo-

ration of the presentation in the reference

manuals and as a guide to the ways

in

which

COBOL

and computers can be applied

in the

solution of realistic problems. It is

a pleasure to acknowledge the

many

and varied contributions Fred Gruenberger of the RAND Corporation; Bill Donally of IBM; Dean Earnest of Burroughs; Dick McCoy of the University of Wisconsin; Stan Naftaly of Space Technology Laboratories; Jack Jones of the United States Air Force; and Steve Wright of Applied Data Research. of

the

following

people:

Daniel D. McCracken Ossining,

New York

March 1963

ACKNOWLEDGMENT

The

following acknowledgment

is

reprinted

from the COBOL manual published by the Government Printing Office. This publication is based on the COBOL System developed in 1959 by a committee composed of government users and computer manufacturers.

The organizations

participating

in

the

original

development were: Air Materiel

Command, United

States Air Force

Bureau of Standards, Department of Commerce David Taylor Model Basin, Bureau of Ships, United States

Navy

Data Processing Division, Minneapolis-Honeywell Regulator Company Burroughs Corporation International Business Machines Corporation Radio Corporation of America Sylvania Electric Products, Inc. Univac Division of Sperry-Rand Corporation

Electronic

In addition to the organizations listed above, the following other organizations participated in

the work of the Maintenance Allstate Insurance

Group

Company

Bendix Corporation, Computer Division Control Data Corporation DuPont Corporation General Electric Company General Motors Corporation Lockheed Aircraft Corporation National Cash Register Company Philco Corporation Standard Oil Company (New Jersey) United States Steel Corporation This COBOL-61 manual is the result of contributions made by all of the abovementioned

No

warranty, expressed or imcontributor or by the committee as to the accuracy and functioning of

organizations. plied,

is

made by any

programming system and language. Moreis assumed by any contributor, or by the committee, in connection therewith. It is reasonable to assume that a number of improvements and additions will be made to COBOL. Every effort will be made to insure that the improvements and corrections will be made in the

over, no responsibility

an orderly fashion, with due recognition of existing users' investments in programming. However, this protection can be positively assured only by individual implementors. Procedures have been established for the maintenance of COBOL. Inquiries concerning the procedures and the methods for proposing changes should be directed to the Executive Committee of the Conference on Data Systems Languages. The authors and copyright holders of the copyrighted material used herein, FLOW-MATIC (Trademark of Sperry-Rand Corporation), Profor the UNIVAC® I and II, Data Automation Systems 1958, 1959, Sperry-Rand Corporation; IBM Commercial Translator, Form No. F 28-8013, copyrighted 1959 by IBM; FACT, DSI 27A5260-2760, copyrighted 1960 by Minneapolis-Honeywell, have specifically authorized the use of this material, in whole or in part, in the COBOL specification. Such authorization extends to the reproduction and use of COBOL specifications in programming manuals or similar

gramming

©

publications.

Any

organization interested in reproducing the

COBOL

report and initial specifications in whole

or in part, using ideas taken from this report or utilizing this report as the basis for

an instruction

manual or any other purpose is free to do However, all such organizations are requested

so.

to

reproduce this section as part of the introduction Those using a short passage, to the document. as in a book review, are requested to mention

"COBOL"

in

acknowledgment

of the source, but

need not quote this entire section.

VII

CONTENTS

Data Processing and

Electronic

COBOL

4

Case Study 4.1

1

1.1

Introduction,

1.2

The Data-Processing

1

4.2

Activities of 4.3

Data-Processing Operations, 5

1.4

Data

Sales Statistics

61

The Business Situation, 61 The Data-Processing Situation, 61

Business, 2 1.3

1:

4.4

Characteristics and Organi-

The Summary by Product, 65 The Summary by District and Salesman, 69

zation, 7 1.5 1.6

What What

Procedure?, 9

Is a Is

COBOL?,

5

14

Computer and Punched Card Equipment 16 2.1 The Parts of a Computer, 16 2.2 Representation and Storage of Information, 20

The

DATA DIVISION

73

5.1

Introduction, 73

5.2

The

5.3

Level Structure, 79

5.4

Record Description Entries, 80

5.5

Editing Clauses, 86

File Description, 74

PICTURE

5.6

The

5.7

Condition

Clause, 88

Name

2.3

Instructions and Programming, 22

5.8

Value Entries, 96 The Working-Storage Section, 97

2.4

Magnetic Drums, Disks, and

5.9

The Constant

Tapes, 23 2.5

Exercises, 99

Punched Card and Peripheral Equipment, 28

The PROCEDURE DIVISION 3.1

The Parts

of a

6

COBOL

Basic

The

ENVIRONMENT and

IDENTIFICA-

TION DIVISIONS 103 6.1 The ENVIRONMENT DIVISION, 103 The IDENTIFICATION DIVI6.2 SION, 106

33 Source

Program, 33 3.2

Section, 98

PROCEDURE DIVISION

Elements, 34 3.3

MOVE, ADD, SUBTRACT, MULTIPLY, and DIVIDE

The

Verbs, 38 3.4

The

GO

STOP 3.5

TO,

PERFORM,

7

Case Study

107

The Business Situation, 107 The Data-Processing Require-

7.3

The

ments, 107

The IF Statement and Related Matters, 45

3.6

Input and Output, 49

7.4

3.7

Programming Examples, 54

7.5

Exercises, 57

Inventory Control

7.2

7.1

and

Verbs, 44

2:

ENVIRONMENT

and

IDENTIFICATION DIVISIONS, 112 The DATA DIVISION, 112 The PROCEDURE DIVISION, 117 IX

CONTENTS 8

Fea-

9.5

Balancing Input/Output and Processing Time, 152

MOVE CORRESPONDING

9.6

An

PROCEDURE DIVISION

Additional tures 8.1

126

The

Efficiency Checklist, 152

Option, 126

8.3

Subscripts, 132

10.1

The PERFORM Verb, 136 The EXAMINE Verb, 143 The USE, DEFINE, and IN-

10.2

8.6

8.7

CLUDE

Verbs, 145

Exercises, 147

9

3:

154

8.4 8.5

Object Program Efficiency

149

9.1

Introduction, 149

9.2 9.3

Input and Output Speed, 150 Item Layout in Fixed- Word Ma-

9.4

COMPUTATIONAL

chines, 151

DISPLAY,

10

The Business Situation, 154 The System Design, 155

10.5

Programming, 165 Program Checkout, 166 Master File Creation, 169

10.6

Startup, 169

10.7 10.8

Documentation, 170 Program Maintenance, 171

10.9

Conclusion, 172

10.3 10.4

Appendix:

Answers 151

Payroll— System Design

Case Study to Startup

The COMPUTE Verb, 127 More Complex Conditionals, 129

8.2

Reserved Words

to Selected Exercises

versus

Index

COBOL

181

175

173

1

.

ELECTRONIC DATA PROCESSING

AND COBOL

time, save

Introduction

1.1

money, produce more accurate or

more complete Electronic computers are widely used to assist

in

solving the problems

and business,

engineering,

in

of

science,

applications

results,

etc.),

how

this

ap-

plication ties in with other computer jobs,

where the data originates, how and by whom the results are to be used, and how any exconditions

be

handled.

ranging from a relatively simple inventory-

ceptional

control system for a small wholesaler to the

This

complex calculations of launching a satellite. Their use is based on the ability to operate at great speed, to produce accurate results, to store large quantities of information, and to carry out long and complex sequences of operations without human intervention. In this book we shall investigate what are

can be wasted later if it is not done properly. In this book we can only suggest

called commercial, or business, data-process-

point out additional factors.

As we shall see, such work and challenging, even though

ing applications. interesting

is

the calculations are not usually so difficult as those in designing a nuclear reactor or

predicting in a matter of seconds whether a satellite orbit will

of the

Because

be satisfactory.

volume of data often involved, com-

mercial data processing presents lenges in organizing the

work

many

chal-

so that the

needed results are produced on schedule with a

minimum

of cost

and

in guaranteeing that

the results are correct.

Solving a problem with a computer requires

a number of steps, which

may

be

outlined as follows.

Problem

To

identification

and goal

begin any computer project,

definition. it

is

nec-

essary to have a clear idea of the nature of the company's business, why a computer is

being used on a particular application (save

is

a

sizable

are

to

undertaking and

much

effort

some this

of the considerations that enter into

phase of computer work; the following outlines the data-processing needs

section

an illustrative manufacturing company, and the case studies in Chapters 4, 7, and 10

of

System design. There are, as a rule, to approach a particular com-

many ways

puter application.

Decisions must be

made

on the timing of data arrival and of computer

processing;

data

formats

(arrange-

ments) must be planned to save time and to tie in properly with other applications;

must be made for recovery from machine or operator errors; plans must be laid for getting the whole system started effectively; and various checking techniques must be applied to prove the accuracy of processing to name only a few provision possible



of the aspects of this subject.

A

complete

treatment would easily fill a longer book than this one; here, we shall try to point out some of the most important aspects of

system design

Computer

in the case studies.

programming.

Computers

basically execute only very simple "instruc1

COBOL PROGRAMMING

2

many

usually

tions," such as

used

determine whether two numbers are equal.

every week or every month.

add two numbers, read a card, or To do preparacomputer requires the work with useful a tion of a program of these instructions; a complete commercial application requires at least hundreds of instructions, more commonly thousands. Different types of computers, in general, have different sets of basic instructions, and even when different machines do the same things, such as adding two numbers, they usually have different formats for the coded instructions.

This means

that a program for one machine will not run on

a machine of a different type, which leads to the high costs of preparing completely

when

new programs

a user gets a faster or bigger computer.

COBOL, which

stands

for

COmmon

Business

Oriented Language, was designed to solve or at least to ease a

number

of problems.

It simplifies

program of thousands of computer instructions by allowing us to write the procedure that the computer is to follow in terms similar to ordinary English, which is then translated preparation

the

a

of

into the computer's basic instructions.*

It lessens

the cost of changing machines, because a program

written in

COBOL

can be translated into the in-

any computer, perhaps after some relatively small changes in the program to reflect the differences between

structions of almost

making

COBOL

the two computers.

In this book we shall give a complete explanation

most of the features of the COBOL language and explain as much about the computer as the COBOL programmer needs to know in order to do an effective job.

times,

many

a few minutes to

problem, the volume

such

periodically,

may

This step

as

take

hours, depending on the

of data, and the speed of the

computer.

may

be drawn from this computer First, the does not solve discussion. problems; it only follows carefully defined comSecond, a computer does putational procedures. not in any way relieve the user of the responsibility of planning the work carefully; in fact, the computer demands much more careful planning which is often valuable in itself. The computer is faster and more accurate than a human, but it cannot decide how to proceed or what to do with the results. Third, a computer does not in any way reduce the need for a full and detailed understanding of the problem area or of the business procedures in conclusions

Several



Finally,

it.

ming

step

it

should be realized that the program-

—the

primary subject of

this

only one part of the complete process;

it

book

may



is

not

even take a majority of the time. is not meant to minimize the importance programming nor to suggest that it can be done haphazardly. Programming can be a sizable task and is frequently fascinating in its own right. We

This

of

simply wish to suggest at the beginning that pro-

gramming be viewed

in the perspective of the full

range of activities.

of

Program checkout. to

make mistakes

in

There are so

many

chances

programming that most pro-

grams do not work when

first

tried.

COBOL

greatly alleviates this problem, because the program is written in English-language form and is

somewhat easier to check before trying but systematic methods are nevertheless required

therefore it,

and locate any errors and to ensure that the program actually will produce correct results.

to detect

We

consider this topic more fully in the case study

Chapter

in

1

.2

Business

We

puters and

shall see later that this translation is

computer

itself,

how they can be

COBOL.

filled

done by the

under the control of a compiler program.

with com-

Let us begin by exploring

some

of the data-processing activities of a

sized

manufacturing company.

medium-

Figure 1.1 shows in schematic form some of the flow paths of information

and materials in a company that manufactures a line of products, some of which are sold from stock and some of which are built specially to the customer's order.

10.

Production. Finally, after all these previous phases have been completed successfully, the program can be combined with data for the computer to process. In a typical situation the program is

We

are concerned with business data-processing

requirements and

gram

*

The Data-Processing Activities of

outlines only the

This dia-

major paths, omitting a vari-

ety of other activities, as we shall see later. What are some of the major flows of data through these channels? First consider

what happens when a customer company stocks, ready to

orders a product that the ship.

The customer's

order goes to Sales, which

ELECTRONIC DATA PROCESSING

Information,

Government

Banks

Employees

money

AND COBOL

Materials,

products

ACCOUNTING Taxes

Payroll

Accounts Payable

General

Cost

Accounts Receivable

Stockroom

Figure 1.1.

Some

of the

information paths of a manufacturing company.

it to Accounting, Production Conand the Stockroom. Accounting uses the information as advance notice for billing and for

same information has to be transmitted, but there is no major reduction possible in the number of functions of the business that must be undertaken

Production control is preaccounts receivable. pared to update inventory records. The Stock-

in

room makes up the order and sends it to Shipping, accompanied by a packing slip (prepared by Sales)

product that

which

because the item

sends notices of trol,

Sales

a

the

sent to

is

notification

customer. that

Shipping sends

order

the

was indeed

such a transaction.

Now

let

us follow the paths of an orde^ for a

not stocked but must be manu-

is

factured specially to the customer's order, either is

sold

worth stocking or because

too infrequently to be it

requires a special de-

shipped, noting any shortages, and forwards the

sign.

same information

tomer's order to Production Control, possibly after

to

update sales

ordering of

prepares a

to Accounting.

statistics

and

Sales

is

then able

back Accounting

to handle the

any out-of-stock items. the customer, and the customer

bill for

returns a check.

This time Sales must send data on the cus-

from Engineering (not shown). Production Control computes the raw materials to be taken from stock and schedules the manufacturing operations needed to produce the item. Propgetting a design

The reader may already have thought of several places where the amount of data transmitted could

to the

be reduced, but basically

uct.

all of

the information sent

company really is necIn talking about how a computer can be essary. used in such an operation we are concerned with eliminating as much duplication of data as possible and with cutting down the number of times the

to the various parts of the

erly timed orders go out to the

Manufacturing operation to build the prod-

When

it is

where the chain This

Stockroom and then

is

of course.

completed, of action

is

it is

sent to Shipping,

as before.

a highly simplified sequence of operations,

We

assume, for instance, that

all

raw

materials and subassemblies required for the special order are in stock,

that a price can be quoted

COBOL PROGRAMMING

4 to

by the salesman, and that the high that special payment provisions

the customer

price

is

not so

Next let us see what happens when must be ordered from suppliers. This process can be initiated either by the requirements of a special product or by a signal from the inventory-control process that some raw materials or finished goods have fallen below their reorder points, meaning that more should be ordered. The initiation of the chain of events in buying supplies can thus come materials

from Sales or from the Stockroom; either

either

way,

it

funnels through the Inventory-Control sec-

Word

tion of Production Control.

ing regarding

what

is

goes to Purchas-

needed and when.

Purchas-

roll

However,

it is

Accounting makes note of the order

in its accounts

payable operation and

pared to pay the is

bill

when

it

is

arrives.

forewarned what to expect and when

also pre-

Receiving it is

sup-

posed to come; when the materials arrive, Receiving inspects plier's

them and sends

packing

slip,

to Purchasing the sup-

the original notice from Pur-

The materials go either directly into the Manufacturing shop or into the Stockroom. The supplier submits his bill chasing, and the inspection report.

and Accounting sends a check. Since there seems to be a temptation sometimes to assume that business thrives on paperwork for its own sake, let us emphasize once again that all of these

operations are necessary, although they

are not always done in exactly this way.

There

clearly has to be a careful control of inventory;

the penalty for not having control

high cost of too

and

lost

sales.

much

is either the stock or the cost of lost time

Purchasing

is

clearly

essential:

the choice of vendors and the negotiation of pay-

ment terms is a highly specialized function that must be done by experts. Accounting functions are required both by good business practice and by law: bills have to be paid, records of commitments must be maintained, and costs of inventory have to be computed according to methods permitted by government tax regulations. There are several other major information flow paths here, even in this simplified model of a business.

A

great deal of data

is

generated by the

manufacturing process. Data on production times and materials must be funneled into Accounting for figuring costs of special orders, for preparing earnings statements, and for general management con-

a

of special concern in the actual

man-

a variety of incentive

puter payroll system accepts inputs from facturing,

a

statements,

it

variety

relations

prepares checks, earnings

of

and payments

reports,

Manu-

from the employees themselves, and from

various other sources;

Banking

Receiving.

volume to compute pay. all employees, and paymajor computer application.

true for

work that each employee may perform and on payment plans. The com-

of

sent to Accounting and

is

re-

ufacturing operations, where frequently there are complex payment formulas based on various kinds

deductions.

time, notification

is

usually

is

is

considerable

This naturally

ing selects a vendor and places the order; at the

same

costs go into

these operations, and, of course, labor data

quired in

are required.

Labor

shop operations.

trol of the

deduction reports,

of funds

produce

tax

accumulated from considerable

data-

Checks issued by the company

processing work.

employees, suppliers, stockholders, and others

to

must be reconciled with check registers when the checks are returned from the bank. Checks from customers and other miscellaneous sources must be deposited and properly accounted for. Government regulations require much data processing. The accounting for taxes must be supported by many reports covering income, expenses, inventory valuation, credit losses, and capital gains. Withholding tax and Social Security reports must be prepared for every employee. stockholders

And

must be

this is

not

all,

Dividends to

reported.

by any means.

omitted from this discussion,

among

the information flow paths for branch

We

have

other things, offices,

ship-

ments returned from customers or to suppliers, advertising, market research and forecasting, credit investigation and approval, engineering of special or new products, inspection and quality control, maintenance of plant and equipment, capital expenditures, employee cash-advance and expense accounts, accounting for various employee benefits such as discount sales, complete relations with stockholders and bondholders, and a wide variety of management and government reporting such as budgeting and budget variance, balance sheets, profit-and-loss statements,

We may

as

more

what business reby observing that the manu-

close this first look at

quires of the computer

facturing

and auditing.

company

discussed here has been chosen

or less typical of business data processing,

but

it is by no means the only kind of organization that uses computers for such purposes. Here is

a partial

list

of other areas in

which computers

ELECTRONIC DATA PROCESSING are heavily used: electric utilities, transportation,

manu-

insurance, retail sales, control of industrial

facturing processes, banking, government, and education.

In addition to these areas of application of

what we have

called business data processing, there

a vast range of use in scientific and engineering

is

work.

Although

it is

of great importance

we

covered in this book, since

it is

not

are concentrating on

business data processing.

AND COBOL

readers and operate either by sensing magnetized particles in the ink or

by

optical methods.

Sometimes the information, now in machineis immediately entered into the computer for processing. In other cases, where accuracy is a major concern, the input records are verified by repeating the operations of preparing the computer input from the source documents but using a special machine that only checks for errors in sensible form,

the input.

This,

course,

of

increases

the data-

preparation costs, but in some applications the detection

Data-Processing Operations

1.3

and correction

the cost

We

can begin to get a better insight into what

business data processing entails and

puter can assist in

it

by trying

how

a com-

to identify the basic

This can be done conveniently by con-

operations.

tinuing our investigation of the typical business

organization particular at

Section

in

some

1.2

and by looking

in

of the aspects of inventory-con-

trol activity.

Collection of data

is

necessary before

it

can be

In the inventory-control situation this

processed.

would mean gathering the requests for materials and subassemblies from Manufacturing, the orders from Sales to issue finished goods to Shipping, and acknowledgments from Purchasing that a purchase recommendation has been acted upon.

In

many

situations the gathering of data involves the physical

movement

of

paper forms; in some cases

can be set up for transmission electrically. collection

pear.

is

not nearly so routine as

it

it

Data

might ap-

Procedures must be employed to ensure the

accuracy of the data as recorded on the paper forms, and pains

must be taken

to prevent its loss;

data must be scheduled to reach the computing

when needed, and any that is unavoidably must be handled in some acceptable manner. In most cases the data cannot be "read" by the

center late

computer in the form in which it appears in the source documents (paper forms). It must next be recorded in some machine-sensible form. "Machine-

means a form that can be used as input to a computer. Probably the most common method Alternais to punch cards containing the data. tively, a strip of paper tape can be punched. Sometimes the source information is recorded in magsensible"

netized areas on magnetic tape. special devices are used to

of errors

is

so important that

is justified.

Just what

done next depends, of course, on the nature of the job and how it has been organized; one possibility is that calculations are performed.

is

In the inventory-control example calcula-

would require the following, among other If a shipment has been received from a supplier, the quantity of the shipment must be added to the quantity on hand for that item. If materials have been issued to Manufacturing, the quantity issued must be subtracted from the quantion

things.

tity

on hand.

If the

system keeps track of average In most busicomputations are not

usage, a division will be required. ness

data

processing

usually complicated;

the

complexity arises more be-

cause of some of the following operations.

Decisions can be

made by

a

computer

if

the

"logic" of the decision can be stated in terms of

For instance, when from the inventory-control system, a decision as to whether there is enough on hand to fill the request must be made. It is likewise necessary to determine whether more of an item should be ordered; this, too, can be done by comparing the reorder point (the point at which more should be ordered) with the sum of the quantity on hand and the quantity already on order. Similarly, a computer can determine whether two numbers are equal, which of two names comes earlier in the alphabet, whether a man has worked more than 40 hours in a week, or whether a salary change raises the man's salary more than 50%. By combining simple tests of this sort, a computer can make rather complex computer can Manufacturing requests

things a

do.

materials

decisions.*

At various

stages during the processing, data

is

In a few instances

make

specially printed

source documents directly readable

by the com-

puter; these devices are usually called character

* But it still cannot do many things a human can do, such as detecting an unusual condition for which it had not been "instructed" to test, or seeing at a glance that a

customer

is

in a

bad mood.

COBOL PROGRAMMING

6

of hours

most applications, such as from month to month. This is from week to the function of file storage, which is most commonly done with decks of punched cards or, in the computer situation, with magnetic tapes. One of the most important functions in working with a file-storage medium like magnetic tape, in

for validity:

which the records must be inspected in sequence

which unfortunately means two rather difIn one meaning source data is ferent things. validity and accuracy before it is procfor checked For instance, if a part number ought to essed. be completely numeric (contain nothing but digits), it is simple to check that no letters or punctuation

edited,

symbols appear

worked there

is

in

in the input.

The number

any one day can be tested

a clear-cut error

if

the input shows more

than 24 hours and a strong indication of inaccuracy What the computer sysif it shows more than 16. tem does when it detects an error or an unusual condition depends, naturally, on how the system has been designed to operate: the bad data might be rejected and ignored until re-entered in correct

form; the data might be accepted and used but a warning notice printed; or any of many other possible actions might be taken. In the second meaning of editing, data or results are rearranged for printing, with spaces and

periods of time, in

week

or

(sequential-file processing)

records

transaction

the

computer

system going.

Data must frequently be rearranged, which often necessary to alter the

one item in the system

an input card

receipt

transaction record

number

part

—but

in the

it

may

master

not be for the

file:

there

may

first

have

been no issues or receipts for that particular part number. We must therefore search through the

it

first

we

find the one that does

When

transaction record.

has been processed, we read the next transaction

which could be for the same part number as the first, for the next part number in the master

record,

or for a part

file,

we

number somewhere

later in the

—so we search the master again until correspondence. The basic concept of data processing — one to which we return many times— that there can never

master

file

file

find

se-

may

list

is

way

organized.

a man's payroll

In the

also

shall

first

be a transaction record that requires us to go back-

the data for

For instance,

number

first,

followed by his name; the printed output might if his name were printed first. perhaps surprisingly, that rearranging

be more readable It turns out,

requests,

have already been sorted into the same ascending sequence on part numbers as the master file. Now we read the first

quential-file

has two rather different meanings. it is

(issue

assume that

notices, inventory recounts, etc.)

correspond to the

of getting a

Consider the in-

We

ventory-control example again.

master-file records until

work

the process of locat-

particular transaction-file record.

For instance, a number that appears within the computer as 00057834 might need to be printed as $578.34; the Social Security number 535221583 might need to be printed as 535-22-1583; the letters JBSMITH might need to be printed as J. B. SMITH. Planning for output editing can be a sizable portion of the

is

ing the master-file record that corresponds to a

punctuation inserted and perhaps with leading zeros deleted.

,

data in this sense

is

a rather large part of electronic

is

ward

in the

ing both

this is guaranteed by havsame ascending sequence. We some of the ramifications of this

master

files in

file:

the

shall investigate

matter in the case studies in later chapters.

The

last

data-processing

Some

preparing reports. implies:

operation

reports are

is

that

of

what the word

stock status, sales statistics, checks out-

data processing.

standing, accounts receivable, or insurance policies

In the second meaning of rearrangement, individual data items are left unchanged, but collections

that

of items called records are rearranged.

results

it is

into

ascending sequence

case studies involve this

ment, which It

For instance,

often necessary to get a group of transactions

is

on part number. The type of data rearrange-

usually called sorting.

Data must be stored for varying lengths must be stored at least for the interval

between reading computer until it

of time. of time

it

from an input device of the

is

actually processed; this

is

of the functions of the internal storage of the

puter.

It

must

also be

stored for

much

one

com-

longer

it

However, we are using the any printed that a data-processing system produces, thus includes checks to employees and sup-

pliers,

earnings statements to employees, packing

have lapsed.

term "report"

and

in a general sense for

customers, back-order notices, or anything else that a computer system might produce. In a sense, the production of reports is the goal of slips, bills to

all

data processing: the system has not served any

useful purpose until

some person is able to act because of the computer's output. In fulfilling this function, the data-processing system does all of the other things

we have

listed:

the output must

AND COBOL

ELECTRONIC DATA PROCESSING

be rearranged and edited;

frequently presents

it

the results of calculations and decisions; bines input data with stored

file

com-

it

Our task in setting up a data-processing system of

all

the information needed for the preparation of re(including source data and master-file in-

ports

formation)

organizing

,

matching input with

(rearranging and editing)

it

information, performing the

file

necessary calculations and decisions, and doing all in

such a

way

that as

effort as possible

is

little

it

human and computer

In order to discuss data processing intelligently,

know a particular, how

in

to

more about the data and,

little it

manent

in a

In this con-

organized.

is

ALPHANUMERIC*

called

A

or data to be

printed.

information or output re-

(master-file)

Here, we use the one term for

sults.

wherever necessary qualify data,

all

by saying source

it

sorted data,

data,

master-file

kinds, and

edited data,

data item

is

composed

of one or

more char-

an account number, an employee's home address, a quantity on hand, the amount of an insurance policy, a total of all hours worked in a deck of time cards. Data

Examples

acters.

of data items:

items are likewise described as

NUMERIC, AL-

system to be of any length, but in most cases the length chosen cannot be changed during processing.

an account number cannot arbitrarily fluctuate between four and nine characters as procis,

On the other hand, it is quite common to move data from one

essing proceeds. possible





even

spaces in the process.

data item has been changed: there are two data items here of different length.)

We

have spoken so far of two characteristics of items: length and CLASS (NUMERIC,

data

ALPHABETIC,

ALPHANUMERIC). In COBOL DATA DIVISION we

or

Chapter 5 on the

shall find that several other characteristics

etc.

The most elementary poses now, digit,

is

unit of data, for our pur-

a character, which

may

be a numeric

a letter of the alphabet, or any of the special

characters that

may

computer, such as (period),

be allowed on a particular dollar

a

comma, parentheses,

will turn out that

we need

sign,

or

decimal

number

point

sign.

It

to regard a blank (also

called a space) as a "character" too: it

may seem

nonsensical to call "nothing" a "character," but

when

comes to storing data or printing reports the computer must have a way of representing the "character" that results from reading a blank it

column on a card or that will result nothing in a given position on a report.* contains only the digits *

ALPHABETIC; data that may and/or alphabetic characters is

Thus the number 000087295 might become bbbb87295bbb during such a movement. (This does not mean that the length of any

master-file data,

reference

called

computer system: source data, per-

slightly different

is

data that

data item to another, adding or deleting zeros or

from the common usage where refers more to input indata of the term, formation, as distinguished from semipermanent

This

NUMERIC;

any information that

text data refers to almost

can exist

is

contain numeric

That

we need

called

PHABETIC, or ALPHANUMERIC. Data items may be assigned in the design of a data-processing

used.

Data Characteristics and Organization

1.4

is

contains only letters of the alphabet and the space

character

information.

can be characterized as that of gathering

plus or minus sign)

The

"character"

do you "write"

it

space

when

in printing

Data that

through 9 (and perhaps a creates

other

problems:

how

presenting examples in a text?

.The usual answer is to use some symbol to represent it, with the understanding that this other symbol would obviously not be printed. Thus, to indicate the number 123 preceded by three spaces, we might let "b" stand for "blank" (or space) and write bbbl23.

be described for effective computer processing.

now, we that

may

must For

note one other feature of data items

we need: each must have a name

so that

we

can conveniently refer to the data contained in it without actually knowing what data is there at any

moment

given

shall call the

"data" of a

is

Following

name

COBOL

terminology,

of a data item a data

included here to distinguish the

we

name;

name

data item from a number of other things that

can be named in

Most

COBOL.

students have at least some difficulty in

remembering always to make the crucial distinction between a data item and a data name. A data item

is

a piece of actual information that

A

data name

is

proc-

by which a data item is referred to. A common analogy is to compare a data name with a house number and a data essed.

*

Words shown

is

a symbol

in capitals have precise meaning in a program and are called reserved words. In most cases we shall not need the precise definitions until later, but the reader should become accustomed to the fact that these words have special meaning.

COBOL

COBOL PROGRAMMING

8

who currently live number. The distinction

house

Location to which check

necessary

Year-To-Date sick leave Year-To-Date sick pay

item with the people

in the

having that

is

because,

(the data item)

name)

we

;

will

Street to 456

who

in

currently live in the house

terms of their address

say "move the contents of 123

Maple Drive," by which we

that whoever occupies

moment

123

should be moved.

comparison one more step,

we want come

to

we want

following the analogy,

still

refer to the people

to

will

(data

Main mean

Main Street at If we may stretch

this

is

this

the

necessary because

whoever happens to town, without knowing who they are. In

to be able to "process"

we want

up general dataprocessing procedures that will handle any data, within reasonable limits, without knowing at the time we write the procedures what the data is. A record is composed of data items. For instance, other words,

to

set

an inventory-control master-file record would ordinarily contain at least the following data items:

Part number Quantity on hand Quantity on order Quantity reserved

for

future

use

on specific

projects

Reorder

point,

below which

more should be

is

sent

There obviously could be many others. A typical master-payroll record might contain in the neighborhood of 300 characters; in some systems the

number

is

closer to a thousand.

Records are also assigned names for the same reasons that data items are. A file consists of records. This is a formally correct definition, but it leaves out a

about the

way most

number

of points

are organized and used

files

We

that are quite important to us.

should

first

add the qualification that almost any particular file in practice is composed of records directed toward some one purpose. They all consist of the information from time cards, they all contain information about insurance policies, or they all contain records from which paychecks will later be printed, and so on. Second, with almost no exceptions each record in a file contains a key or control field by which it can be identified for processing. For instance, the part number in an inventory-control master record is used to determine whether this is the record corresponding to a given transaction record

ordered

Quantity to order when an order A condensed verbal description

is

the

placed

file

is

bers of the records.

Third, a

Depending on the nature

of the

company and the

products stocked, such a record might contain other data items.

An employee

normally in sequence on the part num-

many

master-payroll record would or-

dinarily contain at least the following data items.

often contains special records at the

file

The one

beginning and the end. is

called the

at the beginning

BEGINNING-FILE-LABEL;

it

con-

tains identifying information about the data rec-

The one

ords.

at the end

FILE-LABEL

record;

is

it

called the

may

ENDING-

contain

several

Employee number

things, such as control totals that are used to check

Name

the accuracy of processing.

Address

trol totals at length in later chapters.

Department

Pay

Finally,

many

record.

Age

tion of a

Years with company Pension plan contribution

whether the

Accumulated pension plan contributions

distinguished

Number Amount

or

file,

but

file

is

it

usually crucial to

is

know

names and are further between input and output files.

A it

may contain only a few dozen may contain millions; there are

file

examples of both extremes. the case studies that

Amount

would be

Timeclock location

in each

in sequence.

Year-To-Date withholding tax of union dues

some key

not an essential part of the defini-

is

Files also are assigned

of dependents

contributed so far this year to Social (Year-To-Date SS)

This

shall discuss con-

are assumed to be in ascend-

files

ing or descending sequence on

rate

Sex

Security

We

thousands.

we

in the range

A

typical

records, realistic

file size

for

shall be investigating later

of thousands

to

tens

of

ELECTRONIC DATA PROCESSING

What

1.5

file, each record of which model number. This file is also in ascending sequence on model number. Figures 1.2, 1.3, and 1.4 show samples of the information in the card deck, the master file, and the report.

be obtained from a master

a Procedure?

Is

AND COBOL

also contains a

So far we have discussed the data-processing needs of business, the nature of data-processing

and the characteristics of data. Now we must investigate a little more closely what is involved in specifying the processing to be done and how it is to be handled. This, of course, is a major concern throughout the book. Our task, in essence, is to learn how to operations,

integrate the needs of the business, the characteristics of

the data, and the powers and limitations of

the computer with a set of operations that will pro-

vide the business with useful and timely informa-

The procedure

tion.

any means, but

it is

not the whole story, by the part that ties all the others is

It will therefore be valuable to get a

together.

glimpse of what a procedure

is

like before getting

too deeply into the details of the topics before us.

The concept can ample.

much

We

best be introduced with an ex-

Consider the following hypothetical and simplified

pricing

application.

are given a deck of cards, each one specifying

We are to produce a report, with each card, showing the following in-

customer's name. line for

formation

:

the customer's name, the model number,

a short description, the quantity ordered, the price

and the total allowed on all orders

of a quantity of one (the unit price) price.

A

discount of

2%

is

,

The card deck is already in sequence on the model number, and there is never more than one card for each. The unit price and the description of each will over $100.

MODEL-NUMBER

1.4

is

required to produce the report in Figure

from the transaction cards

the master

file

in Figure 1.3?

has been matched with file

record, there

the quantity price)

;

corresponding master-

its

some calculation (multiplying

is

by the unit

a decision

in Figure 1.2 and Once a transaction

(is

price to

get the total

the total more than $100 and

2%

and perhaps more calculation (figuring the discount and There is data movesubtracting it from the total) in combining in the report the necessary inment formation from the transactions and the master file. Probably the most important part of this extherefore eligible for the

discount?)

;

.

ample, however,

is

not these things but rather the

process of matching a transaction record with the right master record.

This

may

not be readily ap-

we not just start with the first transscan down the master file until we find the

parent: can

a model number, the quantity ordered, and the

one

What

action,

the next transaction? one,

is

that

we can do approximately

5

00239

10

04903

1

05002

20

12640

8

12641

100 Figure

1.2.

Sample data

that, but only

in terms of things a computer can "understand."

The important point

we must write a genwork correctly for any data of this general type; and by the time the computer does the work we will be out of the picture. is

that

eral procedure

that will

In other words,

we

some way

(to

will prepare a procedure

and

be investigated in detail later) give

to the computer.

The computer

will

ABC CO.

ACME MANUFACTURING AJAX SUPPLIES XYZ CORP.

STANDARD PRODUCTS NATIONAL COMPANY for pricing example.

in it

then follow

CUSTOMER

QUANTITY

00168

and pick up and it is a basic The answer,

right record, do the necessary work,

10

COBOL PROGRAMMING

DESCRIPTION

UNIT-PRICE

MODEL-NUMBER 00135

18.50

CHAIR

00136

16.00

CHAIR

00155

14.35

CHAIR

00168

17.90

CHAIR

00199

12.00

CHAIR

00239

14.10

TYPING STAND

02466

180.00

04903

85.00

CONF. TABLE

05002

27.50

2-DRAWER FILE CAB.

05003

35.80

3-DRAWER FILE CAB.

05004

43.00

4-DRAW€R FILE CAB.

12640

2.50

DESK SET

12641

1.85

DESK SET

12642

2.25

DESK SET

13099

8.95

DESK LAMP

14638

1.20

BLOTTER PAD

Figure

1.3.

Sample master

EXEC. DESK

file

for

pricing

example.

5

17.90

89.50

10

14.10

138.18

1

85.00

85.00

20

27.50

539.00

DESK SET

8

2.50

20.00

DESK SET

100

1.85

181.30

ABC CO.

00168

CHAIR

ACME MANUFACTURING

00239

TYPING STAND

AJAX SUPPLIFRS

04903

CONF. TABLE

XYZ CORP.

05002

2-DRAWER FILE CAB.

STANDARD PRODUCTS

12640

NATIONAL COMPANY

12641 Figure 1.4.

Output of pricing procedure of Figure

1.6.

AND COBOL

11

what the procedure

is.

ELECTRONIC DATA PROCESSING

own

our procedure in processing the data, with no inter-

is

vention on our part possible during the execution

This can best be done with a block diagram, also called a flow chart or flow diagram. Figure 1.5 ex-

This

of the procedure.

and

first

crucial lesson

about data processing: everything

to be learned

must be

the

is

A

second lesson is that a computer cannot exerjudgment unless it has been provided with explicit directions for making a decision. Our present example illustrates this principle in three ways, two of which would probably not occur to someone

who has not

One has already

dealt with computers.

been mentioned: the test for eligibility for a discount. The second is in matching a transaction with its master. When we tell the computer to "scan down the master

until the right one

file

is

we must go into a great deal more detail regarding how this is to be done than we would reached,"

with any

human

This

clerk.

is

simply one of the

characteristics of working with a machine:

it

will

carry out instructions at great speed with extremely

few errors, but the instructions must be very explicit.

How The

could

essence of the

the matching operation?

method

this.

is

We

read a

transaction card, then a master record, and ask

whether the model number on the transaction card is the same as the model number on the master record;

if it is,

we go ahead with the processing of If not, we read another master

the transaction.

record and ask the same question again,

After processing one transaction,

etc., etc.

we read another

and repeat the whole process. This goes on until the entire transaction deck has been processed.

What

told

how

to

Now

comes the third directions: the computer must be

need for explicit

then?

know when

it is

finished!

No

Even that

enough; we should

last

tell

statement

how

it

is

not precise

recognize the

to

end of the transaction deck and then what to do to

wrap up the processing

to do at the end.

We

in case there are things

shall see shortly that these

explicit directions are easily stated.

So far we have described the task and considered the general approach to a computer procedure for carrying out the desired processing. We have not yet produced a procedure that the computer could follow



in fact,

we even

scription of exactly

that

what

we can understand.

cluded only for completeness at this stage; required by

lack a perfectly clear deis

to be done,

The next

and when,

step, therefore,

it

is

COBOL

and has to do with preparing the files for operation. Reading then from left to right, we come to an oval box that merely estab-

name

lishes a

so that

to the following

ing across,

we

box

we

will later be able to refer

in order to return to

Read-

it.

see that the next box calls for the

reading of a transaction record, which in our case

Next comes a

a card.

is

number on

decision:

dummy

this card a

signals the end of the deck?

the bottom,

we

see that

of

all

If it

the steps to follow

when

WRAPUP *

the model

is

9's,

is,

"GO TO WRAPUP."

diagram says

which

the block

Looking at

is

the

name

of

the job has been completed.

model number was not 99999, we go on to read a master record; this step is also given a name. If the

comes the basic decision that

in effect lo-

cates the master record corresponding to a transis the model number in the transaction the same as the model number in the master? Actually, we ask here if they are not equal and go back to MASTER-READING if they are not. Thus we will continually read master records until we find the one with the same model number as that of the transaction just read. When the model numbers finally match, we go on to the actual processing. The quantity from the transaction is multiplied by the unit price from the master to get the total price of the order. Next comes the decision on dis-

action:

count; clerk

would ever have a problem here, but the computer must be told in precise terms when the job has been completed.

more

Now

we go about

ideas of

clearly what we have been discussing. diagram The block begins with a box that is in-

presses

specified in advance.

cise

to clarify our

if

the total price

is

greater than $100.00,

"PERFORM DISCOUNT CALCULATION." PERFORM is a COBOL action that

the box says

*

Anyone who thinks

it

is

easy to define precise typo-

graphical conventions should try writing a

word

in capitals

COBOL—but

it.

We

said earlier that

would mean that

it

had precise

be necessary to show names of things (data item, records, paragraphs) in a COBOL program in capitals, too. These names were invented by the author, just as they would in real life be invented by the programmer, and have no special meaning in COBOL. Thus in the statement GO TO WRAPUP "GO TO" has special meaning in any COBOL program, but "WRAPUP" is a paragraph name having meaning only by its use in this program. Confused? Well, that's the way things are. You will face the same problem in reading COBOL programs in any

meaning

case.

in

The

COBOL

best advice

words.

A

it will

is

to get familiar with the special

complete

list

appears in the Appendix.

COBOL PROGRAMMING

12

IF

OPEN INPUT TRANSACTION-FILE,

/transactional

MASTER-FILE,

\iREADING.

READ TRANSACTION RECORD.

r

MODEL-NUMBER



IN

TRANSACTION IS EQUAL TO 99999, GO TO WRAPUP.

OUTPUT REPORT-FILL

Mj

(

MASTER READING.

&

IF

IS IN

V

MODa-NUMBER

READ MASTER RECORD.

IN

MULTIPLY QUANTITY IN TRANSACTION BY UNIT-

TRANSACTION

NOT EQUAL TO MODEL-NUMBER MASTER, GO TO MASTER-READING

©-

MOVE NAME IN TRANSACTION TO NAME IN REPORT.

0-

MOVE QUANTITY IN TRANSACTION TO QUANTITY IN REPORT.



PRICE

TOTAL-PRICE

CALCULATION.

TRANSACTION TO MODa-

MOVE DESCRIPTION IN MASTER TO DESCRIPTION

NUMBER

IN

IN

IN

REPORT.

MOVE UNIT-PRICE

o ®

IS

100.00,

PERFORM DISCOUNT-

GIVING TOTAL-PRICE.

MOVE MODa-NUMBER

( DISCOUNT-CALCULATION.

IF

GREATER THAN

MASTER,

IN

IN

REPORT.

WRITE REPORT. GO TO TRANSACTION-READING.

MASTER TO UNIT-PRICE IN REPORT.

MULTIPLY TOTAL-PRICE

V

SUBTRACT DISCOUNT

BY 0.02, GIVING DISCOUNT.

FROM

CLOSE TRANSACTION-FILE,

TOTAL-PRICE.

RETURN

STOP.

MASTER-FILE, REPORT-FiLE.

Figure 1.5.

means

jump out

to

do whatever

is

of the sequence of operations,

specified,

PERFORM.

lowing

Block diagram of a pricing procedure.

and return

to the step fol-

The discount

calculation

is

COBOL

and computer requirements; the primary action in our example would be to rewind the magnetic tape reel that contains the master file.

seen to be a simple matter of multiplying the total price by 0.02 (2%) and subtracting this discount

grammed

from the total

transaction for any model number, because

Now

price.

come some boxes that

call for the

that will appear in the report to be

where they are ords

names

here, as before, are

to specify

rec-

The data qualified, which means meant when the same locations.

which record is in two or more records.

name appears

NAME

moved from

and master

in the transaction

report record

the

to

data items

For instance,

stands for a data item in the transaction

record, but

it

also stands for a data item in the re-

To distinguish between the two we IN TRANSACTION and NAME IN REPORT. The only exception is TOTAL-PRICE, port record.

say

NAME

which appears only

in

the report and therefore

need not be qualified.

When

all

moved, we

of the report data

items have been

write a report line on the printer and

return to read another transaction.

The

WRAPUP

routine

is

again a matter of

It

is

quite essential to the

procedure as dia-

here that there be no

more than one if

there

were we would never find the proper master record each time we read a transaction we also read a master, which would get us into trouble if there were two or more transactions for the same model.

Having read the first of the group of transactions and found the correct master for it, we would read the second of the group and then another master; the next master would, of course, be for some other model number. This is not an unsolvable problem, of course, but taking it into account would complicate the procedure unduly for our present purposes.

All that is required now is to put the procedure onto cards, paper tape, or magnetic tape. As a preliminary to doing so, we may rewrite the procedure in a form that shows how it would appear, for instance, this

if punched on cards. Figure 1.6 is same procedure, printed from a deck of cards;

ELECTRONIC DATA PROCESSING

each line corresponds to one card.

About the only new

feature here

sentences and paragraphs.

sentence

is

We

is

the use of

see that a

COBOL

written with a period and reads aimost

A

normal English sentence. always given a paragraph name.

like a

paragraph

is

In the three sentences beginning with IF, there is

no action specified

met;

plete the action specified

and simply skip over next sentence

computer

if

is

to

the condition

this action

the condition

if

not

in case the condition is

in such a sentence the

is

The STOP

Figure 3.1 in

Chapter 3 shows how this procedure would be written on a coding form.

is

com-

met

and go on to the not met.

RUN

directs the

AND COBOL

13

computer to stop

executing the procedure.

We note that the first line of the figure says PRODIVISION. We shall see that a complete COBOL program (set of directions to the

CEDURE

computer) consists of four divisions: the

IDEN-

DIVISION, ENVIRONMENT DIVISION, DATA DIVISION, and PROCEDURE DIVISION. In addition to the PROCEDURE DIVISION, the most important is the DATA DIVISION, a subject to which we devote

TIFICATION

considerable attention in Chapter

5.

In our ex-

would provide the answers to such questions as these. How does the computer know how ample

it

'ROCFDURE DIVISION. JEGIN. OPEN

INPUT TRANSACTION-FILE* MASTER-FlLEt OUTPUT REPORT-FILE.

RANSACTION-READING. READ TRANSACTION-FILE RECORD. IN

IF

MODEL-NUMBER

TRANSACTION IS EQUAL TO 99999 GO TO WRAPUP.

1ASTER-READING. READ MASTER-FILE RECORD. IS NOT

FQUAL TO MODEL-NUMBER

IN

IF

MODEL-NUMBER

IN

TRANSACTION

MASTER GO TO MASTER-READING.

MULTIPLY QUANTITY IN TRANSACTION BY UNIT-PRICE IN MASTER GIVING TOTAL-PRICE.

IF

TOTAL-PRICE IS GREATER THAN 100.00

PERFORM DISCOUNT-CALCULATION. MOVE NAME

IN

TRANSACTION TO NAME

IN

REPORT. MOVE MODEL-NUMBER

IN

REPORT. MOVE DESCRIPTION IN MASTER TO DESCRIPTION IN

IN

TRANSACTION TO MODEL-NUMBER

REPORT. MOVE QUANTITY IN TRANSACTION TO QUANTITY IN REPORT. MOVE UNIT-PRICE

IN

MASTER TO UNIT-PRICE

IN

REPORT. WRITE

REPORT. GO TO TRANSACTION-READING.

>ISC0UNT-CALCULATI0N. MULTIPLY TOTAL-PRICE BY 0.02 GIVING DISCOUNT. SUBTRACT DISCOUNT FROM TOTAL-PRICE. /RAPUP. CLOSE TRANSACTI0N-FILE» MASTER-FILE*

REPORT-FILE.

STOP RUN. Figure

1.6.

COBOL PROCEDURE DIVISION

for

a pricing application.

COBOL PROGRAMMING

14

long each data item

is

and the order

in

which the

data items appear in their records? How does the computer know which data items are NUMERIC and which are ALPHANUMERIC? How does the

computer distinguish between data names, record names, and file names? How does the computer know that the prices here have two decimal places but quantity is a whole number? These and other matters would

be described in the

all

DATA

DI-

VISION. The procedure we have developed in Figure 1.6 It specifies is now ready to go to the computer. exactly what is to be done with the data in the files; it states explicitly how to find the master record that goes with each transaction;

how

will operate correctly, without inter-

it

vention, on

states

and what to

to recognize the end of the job

do then;

it

any data

of the general type suggested

DATA

within the limits given in the

DIVISION.

many

it is,

this little

example displays

of the important ideas of data processing,

and the reader will be amply repaid for the effort necessary to master its general features. (Some of the details, such as the use of hyphens, are not critical

now, and will be fully explained

later.)

This procedure was developed with the idea of using

it

to direct the operation of a computer, but,

of course,

An is

it

could be utilized for other purposes.

explicit statement of what-is-to-be-done-when

necessary for any data processing, whether done

with a computer, with punched card machines, or

manually.

1.6

What

is

COBOL?

A

procedure like that in Figure 1.6 has been described as giving orders to a computer, but that is not quite correct.

A

machine

of the

stance,

if

puter does not "understand" words like

MULTIPLY,

PERFORM;

READ,

vocabulary includes only codes for these actions, where 01 might stand for reading a card, 58 for multiplying two or

its

numbers, and 80 for part of the actions in a PERFORM. Furthermore, some of the COBOL verbs cannot be translated into a single computer operation: in many machines, for instance, the comparison of the two model numbers and the

would require at

least

GO TO

two elementary computer

computer operations

all

operations are actually specified in terms of

the contents of storage locations.

We

matters

more

some

vestigate

these

of

shall

inin

fully

Chapter 2. For now we need only realize that a translation Fortunately, however, the computer is necessary. can do this

we

diction:

This

itself.

may seem

like a contra-

said that the computer could not di-

rectly execute the procedure, yet

The explanation

is

it

can do the trans-

that a separate set of

computer instructions does the translation; this variously called the processor, translator, or piler,

and

is

is

com-

supplied by the computer manufacturer.

It cannot be

emphasized too strongly that the a computer program. It is not separate a machine built for the purpose. It is

processor

is itself

usually the same machine that will later execute the translated program, but during the translation it is

under control of a processor program.

(We

say "usually" the same machine because in principle is possible for one computer to translate programs to be run on a different type of machine; however, this is seldom done.) The procedure shown in Figure 1.6 is called a source program; the set of basic computer instruc-

it

tions produced

by the processor

ject program.

It is the

is

called the ob-

object program that

is

actually executed by the computer to read data, do processing, and produce results. Stated other-

is

A

of

in-

are of dif-

be required to add or delete zeros or spaces. Finally, every data item in the computer must have a location in the storage of the machine, and

we

first.

number

For

MOVE

may

gram

be an intermediate translation step

to the language

DIVISION.

the two data items in a

ferent lengths, a

wise,

stands; there

is

PROCEDURE descriptions in the DATA

must com-

it

COBOL

the combination of the actions DIVISION with the data

in the

computer cannot follow a

procedure of this sort just as

most important part of the transla-

tion from the language of

lation.

Simplified though

A

operations.

write a source program; the source protranslated

into an object program; the computer executes the object program.

The word "COBOL" refers both to the sourceprogramming language and to the compilers that translate programs written in this language into the language of a particular computer.

One various

of the advantages of

COBOL

COBOL

is

that the

all accept the same source-program language. There may in some cases be features in one processor that are not found in

processors

others and the characteristics of the object computers may require some changes in the data di-

ELECTRONIC DATA PROCESSING visions,

but by and large the same source program

can be compiled to run on any machine for which there is a COBOL processor which is almost all machines. Thus a computer user is able to change



computers with much than

if all

of the

less cost of

reprogramming

procedures were written in the language

machine

itself.

Since different machines are

so different in their basic languages,

it is

generally

impossible to change machines without a complete

reprogramming job

if

machine language has been

used.

COBOL

grew out of this desire to develop a language that would be compatible, that is, acceptable as a source program language by any computer for which there is a COBOL compiler. This work began in 1959 under the direction of a group of computer experts, many of whom had worked on somewhat similar "English-language" systems, as alluded to in the acknowledgement The maintenance and at the front of the book. orderly development of the language was established as one of the functions of a group called the Conference on Data Systems Languages, which is Historically,

abbreviated

The

first

in this

book

COBOL was COBOL is therefore

formal report defining

referred to as is

COBOL-60. The version described COBOL-61, which was the latest at

the time of writing.

consists of

two types

ments: required and elective. this:

a

for

"COBOL,"

designated as quired

COBOL;

as elective

but to

if

is

15

of language ele-

The

general idea

is

source-programming language to be

must include

it

all of re-

the inclusion of features designated

at the discretion of each implementor,

such features are included they must conform

CODASYL

specifications.

Presumably, as time

goes by, some features that are

become required, and new added. This mechanism

now

elective will

elective features will be is

under study at the

present time.

This book covers

all of

to

distinguish

tive features.

It

COBOL-61 and

COBOL-61, but no attempt

the bulk of elective

made

required

was

between required and felt

is

elec-

that since different im-

plementations vary in the number of elective fea-

and since the status of implementation is changing so rapidly there would be no real value to the reader in tediously marking each

tures included

elective element.

In short, this book

is

intended as an expository

introduction to the bulk of

CODASYL.

issued in 1960; that version of

COBOL-61

AND COBOL

reference

manual

either for

COBOL

for

or for

as a

any par-

The reader who actual computer work

ticular implementation.

using

COBOL-61, not

COBOL

will be

clearly

must have a copy of the manufacturer's reference manual for his compiler.

2. COMPUTER AND

PUNCHED CARD

EQUIPMENT

tion that

The Parts of a Computer

2.1

mean One of the advantages of COBOL is that programmer using it does not have to know so much about how the machine operates as he does when programming in the Nevertheless, it machine's own language. the

is not possible to do a really effective job without learning certain facts about the com-

puter, in order to

know what can and

can-

often called reading;

that information

by

internal electronic operations.

entry of information into a computer.

legal

is

is still

We

and

will

produce correct results

very wasteful of computer time.

begin by considering the over-all or-

ganization of a computer of the type that

with

used

COBOL.*

schematically

the

Figure

is

Punched cards are widely used 2.2

Figure

This device can read

1604.

cards at the rate of 1300 per minute, which is

perhaps a

little

equipment ranges

major parts of such a

cards per minute.

machine.

for the

shows the card reader for the Control

Data Corporation

shows

2.1

we

accepted in some

is

powers and restrictions of the COBOL language, and to avoid doing things in a way but

this

machine sensible form, such as punched cards, and translated into the form in which it is stored inside the machine, which is usually some type of magnetic storage. The input section also performs a "speed translation," in that things like card readers and tape readers are always at least partly mechanical and therefore much slower than the

not be done, the reasons for some of the

that

faster

than average; other

in speed

from 100 to 2000

Most punched cards have

80 columns, each of which can hold one

The input

section handles the entry into

character; a typical rate for punched-card

the machine of data and of the coded in-

reading might be about 1000 characters per

structions that control the machine's actions.

second.

This *

is

We

the phase of the computer's opera-

are excluding analog computers, which rep-

by establishing anologies between numbers and voltages or shaft rotations and therefore have limited accuracy and also do not deal resent information

with

the

alphabetic

information

that

portant in business data processing. clude

for

which

is

the

is

We

so

im-

also

ex-

moment punched-card equipment,

usually an important adjunct of a com-

puter installation but which cannot be directed by a COBOL program. We are thus restricting ourselves

to

stored

-program

meanings of these terms

16

is

digital

will

computers;

become

the

clear shortly.

Punched paper tape input medium.

is

also

used as an

Figure 2.3 shows a section

used with 1604.

the Control Data Corporation Figure 2.4 shows the paper-tape reader

for this machine.

Reading rates vary between 10 and 1000 characters per second; the 350 per second of the Control Data reader

is

representative.

as the primary input

smaller computers, but

Paper tape

medium

is

used

only on the

it is available as an optional method, along with others, for a

COMPUTER AND PUNCHED CARD EQUIPMENT



.- —

17

^ — — «.

'

Arithmetic-

Storage

logic

Control

j

>

'

Auxiliary

storage

The functional parts of a stored program computer.

Figure 2.1.

number

CDC

of larger machines, as in the case of the

1604.

Some computers

are able to read printed char-

acters, or at least digits

directly in printed form.

and a few special symbols, If this is based on sensing

powdered metallic particles in the ink, it is called Magnetic Ink Character Recognition (MICR). If ordinary ink

is

used,

Reading (OCR).

it is

called Optical Character

Optical Character Reader, which several

IBM

IBM

Figure 2.5 shows the

computers.

may

1428

Figure 2.2. (Courtesy

be used with

Character reading

is

is

frequently used as an input and

output medium, but we shall delay discussion of

it

printer for the

until Section 2.4.

The output

able form, carrying out in reverse the translations that the input section does.

device for output

is

same two The most

a line printer, that

characters per second, which

is,

Friden Business • »

••••

••

• ••



«i

Figure 2.3.

•••••• • • •

A

section



of

• •

•••

»•

••

• •







••

Friden Business

••



• •
c6=fc63c6=fc6=>

fc



|c7=>c72t7qc7Pc7=> I

(X

or

07

Ot

iX

l

8 I

61 I

MO

NAME OF EMPLOYEE It II II l) » II 73 n

12 II 14 li

II

24 75 21 17

I

D SI04I

I

Figure 10.2.

The time card for the payroll case study.

payroll section before the time cards are sent to

One reason

data processing. that

we want

42(43 44 >i

time cards for employees whose numbers begin with 00, another for employee numbers beginning of

way

for doing it this

(Courtesy IBM Corp.)

to develop a control total.

Let us assume that there are 5000 hourly workers in the payroll and that employee numbers have five digits. Then for each "thousand group" of payroll numbers the total hours worked are recorded on paper tape and transmitted to data processing. This

numbers do not form an unbroken sequence. The average size control group might thus be more like 50 cards, which is a reasonable compromise between

means that there

the excessive cost of preparing too

is

2354

will

etc.

be a control total for the group

14396SEAR STUD 0FSCRIP1I0H PIECES

another for employee numbers beginning 02, There conceivably could be a thousand employees in a group, but ordinarily the employee 01,

STIU'EO

PIECES

SPOILED

1

TURN

4

P»»I

OF

orscmpiiON of out.

FINISHED

PIECES

So zs

SO

IS

DEPT

EMPLOYEE HO.

NO.

many

4O0

m

control

\0 HOURS

mach.no.

PIECES Pli

WORKED

FINISHED

T.

PREM

I

cO-cO"'>^ c O^ ?^cO^^cO^^i^O^cO^#* cO^O^,;0^0 p

(

^.PrPcPcPcP ~i:vi',~f:> PcP c l'cl" cl-^cl'VPc I

7S

I

"PcVcW cl^el ;3^c3 c3' c3^c:3 \Z° 3^3-1 i i i \** A^c^cA ^cPc&cW-.VcVc^cVA 4^-4 V di. 4^4 I c-5-c5-t-5 VcPcb**} i^S>. r53c5 37

STOP

3

5

5

ell;

c

I

li

t 4-

START

1

I

MAY 25-10

.8

STOP

c&dP VdtPcfP

8

.0

START

cl^c^cl^d^cl^cl^ l^cl^cl^cl^^^cr^cl^cP'^cl^cT^

HAY 25

[MPiom NO

c 8^8^ EARNINGS

PICCES SID io

ea rnTwor aeo

,

i

^ felliLtvmas DATE

eSP&c^cSPeSPe P