home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
cobol
/
compiler
/
cobol650
/
doc
/
cobol650.doc
Wrap
Text File
|
1990-10-11
|
154KB
|
4,295 lines
.PL
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
INTRODUCTION
This manual is a guide on how to properly write Cobol
programs on the IBM-PC using Ansi-Standard COBOL Version
6.50. It is a guide on structured coding style and good
programming techniques, as well as a COBOL manual. It
will explain in detail the features used and the
examples, but will limit the discussion to the most
commonly used features of COBOL.
Our goal as programmers is to write reasonably efficient
programs that are easy for other programmers to read,
this is necessary for maintaining the program. Whenever
possible, I have tried to present a style that is useful
and has been tested on other computer systems,
especially the large IBM mainframe used in business. I
acknowledged the possibility that the reader may one day
use what he learns from this manual to write programs
for such mainframes, or may port software, that is
already written on these machines to the PC using COBOL
6.50.
LIMITIATIONS
You should note that :
1) COBOL Version 6.50 does not have the sort/merge
feature. This is being added and may be out by the
time you receive this manual. Please note the readme
file on the floppy.
NOTE:SORT MERGE HAS BEEN ADDED TO THE LIBARY.
2) It does not have the report writer feature and never
will.
3) It does not have the communications feature such as
CICS. I will probably add this into it, but at this
time I do not have any plans to.
4) Certain features are implimented at it's first or
lowest level.
5) It does have extensive screen formatting features
that are not available in Cobol for the mainframe.
The manual is divided into 2 parts. Chapters ? -
chapters ? will familiarize the reader with the most
important components of Ansi-Standard COBOL Version 6.50
and will allow him or her to start writing programs.
Chapters ? - chapters ? are very important once he or
she starts writing actual and especially more complex
programs. The last chapter is very important in that it
illustrates how to use the COBOL COMPILIER to write
programs and how to write applications.
INTRODUCTION PAGE 1
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
TABLE OF CONTENTS
Cobol Version 6.50 users Manual
Introduction
LIMITIATIONS
CHAPTER 1
Hardware and Software 1
Computer Systems 1
Types of Computer Systems 1
Hardware 2
Software 2
System Software 2
Programs 2
Pseudo Code 3
Figure 1.1 3
Applications 3
Developing Applications 3
CHAPTER 3
ANSI-COBOL Version 6.50 4
Introduction 4
General Characteristics 4
X3.23-1974 4
Components of COBOL 5
Statements 5
example 3.1 5
Sentence 6
example 3.2 6
Clause 6
example 3.3 6
Paragraph 7
example 3.4 7
Section 7
example 3.5 8
STATEMENT FORMAT 8
example 3.6 9
Cobol Character Set 10
Rules For Punctuation 10
Characters used in Conditions 10
Characters used in Arithmetic 11
Characters used for print editing 11
Types of Words 12
Reserved Words 12
Reserved Words List
Reserved words ACCEPT - RERUN 13
Reserved Words List
Reserved words list RESERVE - ZEROS 14
Non-reserved words rules 15
Data Format 15
Elementary Data Items 15
Group Data Items 16
Records 16
Files 16
COBOL Coding Form 17
CHAPTER 4
Basic COBOL Statements
INTRODUCTION 18
The ACCEPT statment (format 2)
TABLE OF CONTENTS PAGE 1
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Fig.4.1
The (PRINTER) DISPLAY STATEMENT
example 4.2 20
example 4.3 21
THE MOVE STATEMENT 21
EXAMPLE 4.4 21
EXAMPLE 4.5
THE ADD STATEMENT 23
EXAMPLE 4.6 23
EXAMPLE 4.7 24
THE SUBTRACT STATEMENT 24
EXAMPLE 4.8 24
EXAMPLE 4.9 25
THE MULTIPLY STATEMENT 25
EXAMPLE 4.10 25
EXAMPLE 4.11
THE DIVIDE STATEMENT 27
EXAMPLE 4.12 27
EXAMPLE 4.13 28
THE GIVING CLAUSE 28
EXAMPLE 4.14 28
EXAMPLE 4.15 29
THE ROUNDED CLAUSE 29
EXAMPLE 4.16 30
EXAMPLE 4.17 31
THE PERFORM STATEMENT 31
EXAMPLE 4.20 31
THE ON SIZE ERROR CLAUSE 32
EXAMPLE 4.22 32
THE GO TO STATEMENT 33
EXAMPLE 4.24 34
THE COMPUTE STATEMENT 35
EXAMPLE 4.26 35
CHAPTER 5
BASIC FILE OPERATIONS
INTRODUCTION 37
FILES 38
FILE ORGANIZATION 38
RECORDS 38
OPEN STATEMENT 39
OPEN RULES 39
THE CLOSE STATEMENT 39
THE READ STATEMENT 40
THE WRITE STATEMENT (PRINT FILE) 40
EXAMPLE 5.01 41
CHAPTER 6
CODING THE IDENTIFICATION
AND ENVIRONMENT DIVISIONS
INTRODUCTION 43
THE IDENTIFICATION DIVISION 44
THE ENVIRONMENT DIVISION. 44
THE CONFIGURATION SECTION 44
THE INPUT-OUTPUT SECTION 45
RULES FOR CODING
THE INPUT-OUTPUT SECTION 45
CHAPTER 7
TABLE OF CONTENTS PAGE 2
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
CODING THE DATA DIVISION
Introduction 46
Sections 47
File Section 47
FILE SECTION RULES 47
File Record Entries 47
Data Item Definition 48
Rules for coding
Data items 48
WORKING-STORAGE SECTION 49
LINKAGE SECTION 49
SCREEN SECTION 49
CHAPTER 8
CODING THE PROCEDURE DIVISION
INTRODUCTION 50
Structured programming 51
Program Constructs 51
The IF condition 51
Modular Programming 52
The Main Line Section 52
Other sections 52
Paragraphs 53
Procedure Names 53
Statements and Sentences 54
CHAPTER 9
Screen Processing
Accept 3 format
Introduction 55
Screen Format 56
Screen Header 56
Data Area 56
THE SCREEN SECTION 57
RULES FOR CODING THE
SCREEN SECTION 57
THE DISPLAY VERB
The Accept (3) 59
EXAMPLE 9.01 59
TABLE OF CONTENTS PAGE 3
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Chapter 1: Hardware and Software
INTRODUCTION
The first 2 chapters provide an introduction for those
who have no experience with developing applications or
writing programs. Hopefully they may have some
background in programming, possibly in BASIC. Otherwise
the reader may go immediately to chapter 3.
Computer Systems
A computer, or more accurately computer system, is a set
of electronic and electromechanical devices that perform
a series of functions under the control of a set of
instructions written by human being. This set of
devices is called hardware and this set of instructions
is software. This hardware under control of the proper
software will compute payroll of a company, guide a
spacecraft to the stars or allow Pacman to gobble up
dots on a video display.
Types of Computer Systems
There are several types of computers systems.
Mainframes are the medium to large computers used by
businesses or other large organizations. They can
handle many jobs running concurrently and have large
memories and can handle many input devices including
terminals. Many computers are smaller than mainframes
and are used in specialized applications by business
organizations. They handle a smaller number of jobs
concurrently and have a smaller number of input devices.
Microcomputers which include PCs are smaller than many
computers. They have only a limited number of devices,
can fit on the top of a desk, hence, are sometimes
called desktype computers and usually run only one job
at a given time. They are extremely useful for small
personal use and also for some very specialized use by a
small group even large business organizations.
PAGE 1
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Hardware
The IBM-PC's are composed of several hardware
components. These are the systems unit, Electronics
comprising the microprocessor, either the 8088, 80186,
80286, 80386, and the newer 80486. Memory which maybe
extended, expanded or conventional and a video display
unit, This maybe any one of the types listed below and
who knows what will come up next. Monocrome, CGA, BGA,
VGA, VEGA drives the keyboard and the hard drives.
Software
There are 2 types of software. Applications software is
written to solve a specific user problem. Examples are
software that prints payroll checks or displays
inventory stock information. This software is either
written by the user himself using a language like COBOL,
BASIC, or FORTRAN or bought off the shelf as a complete
package. Software, manuals, technical support, etc.
Such packaged software is generally written by an
independent software company.
System's Software
System software does not solve specific problems, but
rather makes it easier for the user to use computer
system. It is generally developed by hardware or
independent software companies. Examples are operating
systems such as DOS, compilers such as Ansi-Standard
COBOL and interpreters such as IBM Basic, saved on
diskette or on hard drive and before it can be used it
must first be loaded into the computers memory. This is
done by typing in the proper command such as COBOL600
followed by the enter key.
Programs
A set of instructions written together as a single unit
defines both a beginning and an end is called a program.
Thus a program is a specific piece of software, system
software and application software. They are more
commonly known as systems programs and applications
programs respectively. In this manual the latter terms
will be used. Note that when a program is executing it
is said to be running. In other words the program
executes is the same as the program is running or the
program runs. Computer people often say the job runs or
the job is running.
PAGE 2
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Pseudo Code
We will illustrate the concept of a program by using
Pseudo Code, which is a mix of words that are valid in
programs and other descriptive words that are not.
While a program written in it cannot execute because of
invalid words it's primary use is to make the program
logic easy to understand on paper. This is shown in
figure 1.1. Note the capitalized words are valid in
COBOL programs.
FIGURE 1.1
______________________________________________________________
: :
: ACCEPT first operator-entered number into memory. :
: ACCEPT second operator-entered number into memory. :
: ADD first number TO, second number GIVING result-field. :
: DISPLAY result-field. :
:______________________________________________________________:
Pseudo Code of a segment of a program code that adds 2 numbers and
displays the sum.
Applications
An application, more commonly known as an application
system to simple system, is a specific job or sequence
of jobs that run or will be run on the computer. For
instance, a payroll system prints out paychecks, W2
forms, etc. An inventory system allows the operator to
enter or verify stock information on a video display
unit, etc. In this user's manual we will use system for
a specific application, thus payroll system instead of
payroll application.
Developing Applications
When a computer user needs an application he has a
choice of either buying it off the shelf as a package
"programs, manuals, tech support, etc." or developing
the system himself. If he decides on the latter he
first has to determine his requirements in detail and
design a system that impliments the application. This
is known as system design. In large organizations this
systems design is generally done by the systems analyst
who consults the user on his requirements and then
translate them into a series of specifications that can
be given to the applications programmers. They in turn
translate these specifications into applications
programs that can be run on the computer.
PAGE 3
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Chapter 3: ANSI-COBOL Version 6.50
Introduction
COBOL "common business-oriented language" is a language
developed specifically for the programming requirements
of business applications. Among programming languages
it is the most extensive file processing features,
allowing the programmer to manipulate a large amount of
data in various formats, for many types of devices. It
also has the extensive report formatting features
allowing the programmer, for instance, to easily print
numbers with dollar signs, commas, negative signs, etc.
COBOL was developed by the CONFERENCE ON DATA SYSTEMS
LANGUAGES "CODASYL" COBOL committee which is made up of
representatives of computer manufacturers and computer
users. However, current and future standards are into
the ospices of the American National Standards Institute
"ANSI". Manufacturers and independent software
programmers, myself included, can only use the name
COBOL if the product agrees with the standard. Ansi-
Standard COBOL Version 6.50 does!
General Characteristics
COBOL is close to English Pros in style which allows a
programmer to use easily understood and self-defining
words like MULTIPLING , STOP, WORKING-STORAGE, etc.
Instead of the short, hard to remember symbols required
in many other languages. The Language is also free form
allowing the programmer to write the code in any column
he wants with certain limits which the potential of
making the program easier to read and understand.
Ansi-Standard COBOL 6.50
COBOL Version 6.50 conforms to the low-intermediate
level of American National Standards. X3.23-1974. It
provides 9 out of the 12 standard COBOL functional
modules which are implimented in either Level I or Level
II capabilities.
The 3 modules not provided are the following:
1) Communication, note this is currently being added.
2) Sort-merge, note this is currently being added.
3) Report writer, note no plans at this time to add this
module.
PAGE 4
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Components of COBOL
Although COBOL is close to the English Pros in style, it
has it's own Syntax rules. We can think of a COBOL
program as a book, consisting of 4 parts each being a
COBOL division. Each division consists of 1 or more
sections. Each section corresponding to a chapter in a
book. Each section in turn consists of 1 or more
paragraph which in turns consists of 1 or more
sentences. We will now define certain COBOL terms, but
we will restrict our discussion to how they are used in
the most common division, the PROCEDURE DIVISION, where
the logic is stated. Most definitions are however valid
for other divisions, which are much easier to code than
the PROCEDURE DIVISION.
STATEMENTS
A statement is a basic unit of the PROCEDURE DIVISION.
It is a correct combination of words and symbols that
specifies an action to be done, "ADD, MOVE, DIVIDE,
ETC.", or a condition to be tested "IF". Unless
subordinated to another statement as for example in IF
conditon it is best for program and readability to code
them starting in column 12. Figure 3.1 shows a segment
of a program code with 6 statements. The last statement
is quite long and therefore coded in 2 lines. Also for
readability the continuation is indented from this.
Your first exposure to typical COBOL program that the
code is quite easy to understand.
______________________________________________________________________________
12345678901234567890123456789012345678901234567890123456789012345678901234567890
IF W010-MONTH-SALES GREATER THAN 499.99
MOVE "*" TO W040-DETAIL-EXCEPTIONAL-SALES
ELSE MOVE TO W040-DETAIL-EXCEPTIONAL-SALES.
MOVE W010-MONTH-SALES TO W040-DETAIL-MONTH-SALES
MOVE W010-ANNUAL-SALES TO W040-DETAIL-ANNUAL-SALES
WRITE SALES-PERFORMANCE-LINE FROM W040-SALES-DETAIL-LINE
AFTER ADVANCING W040-PRINT-SKIP LINES.
EXAMPLE 3.1
_______________________________________________________________________________
PAGE 5
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Sentence
A sentence is 1 or more statements that ends in a period
and is followed by a space. Notice it is followed by a
space. The beginning of a sentence is always a
statement that is not subordinated to another and should
therefore start in column 12. This concept of a
sentence is very important and the programmer is advised
to terminate a statement with a period when possible.
This makes a statement independent of other statements
and thus avoids potential problems as you will see later
on in figure 3.2. Figure 3.2 shows a segment of a
program code with 4 sentences. These are actually the
same statements as figure 3.1, but it now has 4
sentences from the 4 periods that end statements.
Figure 3.1 only has 2 sentences.
______________________________________________________________________________
12345678901234567890123456789012345678901234567890123456789012345678901234567890
IF W010-MONTH-CELLS GREATER THAN 499.99
MOVE "*" TO W040-DETAIL-EXCEPTIONAL-CELLS
ELSE MOVE TO W040-DETAIL-EXCEPTIONAL-CELLS.
MOVE W010-MONTH-CELLS TO W040-DETAIL-MONTH-CELLS.
MOVE W010-ANNUAL-CELLS TO W040-DETAIL-ANNUAL-CELLS.
WRITE CELLS-PERFORMANCE-LINE FROM W040-CELLS-DETAIL-LINE
AFTER ADVANCING W040-PRINT-SKIP LINES.
EXAMPLE 3.2
_______________________________________________________________________________
Clause
A clause is part of complex statement and is only
meaningful in specific statements. Examples are
"GIVING" "ROUNDED". Clauses of an arithmetic statement.
It maybe mandatory or optional depending on the
statement. Figure 3.3 shows use of 2 clauses and a
MULTIPLY statement.
______________________________________________________________________________
12345678901234567890123456789012345678901234567890123456789012345678901234567890
MULTIPLY W010-NUMBER-OF-HOURS BY W030-HOURLY-RATE
GIVING W020-WEEK-GROSS-PAY
ROUNDED.
EXAMPLE 3.3
______________________________________________________________________________
PAGE 6
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Paragraph
A paragraph is 1 or more sentences that together perform
a certain function maybe grouped in 1 paragraph by
putting them under a paragraph header consisting of a
paragraph name and a period. For program readability,
this paragraph header is best coded starting in column
8. The concept of a paragraph is very important since
we will learn later on that it is best to execute the
logic by controlling paragraphs through the verb
PERFORM. Therefore adjacent paragraphs should be
seperated from each other by a line seperated. "* in
column 7". Figure 3.2 does 1 function for instance
print a detail line from data coming from a record. It
can then be coded as a paragraph putting a paragraph
header before it. Figure 3.4 is the result.
______________________________________________________________________________
12345678901234567890123456789012345678901234567890123456789012345678901234567890
*
*
C060-PRINT-CELLS-REPORT-DETAIL.
MULTIPLY W010-NUMBER-OF-HOURS BY W030-HOURLY-RATE
GIVING W020-WEEK-GROSS-PAY
ROUNDED.
EXAMPLE 3.4
______________________________________________________________________________
Section
1 or more related paragraphs maybe grouped together in
one section by putting them under a section header which
consists of a section name followed by the literal
"SECTION" followed by period. The section ends
immediately before the next section header or at the end
of the program. Except for "DECLARATIVES SECTION" which
also ends with the "END DECLARATIVES" statement. The
concept of a section is very important in the PROCEDURES
DIVISION where as we will later discuss related
paragraphs are best grouped into sections. If we put
the paragraph into figure 3.4 under a section header we
get one section with 1 subordinate paragraph naturally
we can put as many paragraphs as you want in the same
section, but for readability of the program, the section
header is also coded started in column 8. Also we code
a line seperater which is an * in column 7 between the
section header and the paragraph header. The result is
in figure 3.5.
PAGE 7
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
______________________________________________________________________________
12345678901234567890123456789012345678901234567890123456789012345678901234567890
*
*
C000-PRINT-CELLS-REPORT SECTION.
*
C060-PRINT-CELLS-REPORT-DETAIL.
MULTIPLY W010-NUMBER-OF-HOURS BY W030-HOURLY-RATE
GIVING W020-WEEK-GROSS-PAY
ROUNDED.
EXAMPLE 3.5
______________________________________________________________________________
STATEMENT FORMAT
Each statement in the language has a general format and
the programmer has to use the prescribed rules for each
statement regarding spelling "reserved words must be
spelled correctly". Providing the names of data to be
used and the order of the clauses in the statement. To
a large extent the rules of format follow common sense.
For instance, program logic is coded with statements
which start with a verb like "ADD, MOVE, MULTIPLY, ETC."
followed by the operend used by the verbs followed if
any by optional clauses. For instances, to multiply 2
numbers we code:
MULTIPLY first-operend BY second-operend
GIVING product-field
ROUNDED
ON SIZE ERROR,
imperative statements.
The 2 operends are multiplied and the product is placed
in the product field if the GIVING option is specified.
It maybe rounded off and it may not fit into high order
left most part of the product field. The imperative
statements will be executed instead of the next
following statement. Note that the GIVING, ROUNDED, and
ON SIZE ERROR are optional clauses. Before we go any
further, examine fig. 3.6.
PAGE 8
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
______________________________________________________________________________
12345678901234567890123456789012345678901234567890123456789012345678901234567890
IDENTIFICATION DIVISION.
*
PROGRAM-ID. EXMP36.
*
***********************************************************
* DATE-WRITTEN. 08/13/90. *
***********************************************************
*
ENVIRONMENT DIVISION.
*
DATA DIVISION.
*
WORKING-STORAGE SECTION.
01 HELLO-WORLD PIC X(20)
VALUE "Hello world".
*
PROCEDURE DIVISION.
*
DISPLAY HELLO-WORLD.
STOP RUN.
EXAMPLE 3.6
______________________________________________________________________________
The program logic is in the PROCEDURE DIVISION. At the
moment the reader should concern himself only with the
last 2 lines. The DISPLAY shows HELLO-WORLD from a
COBOL program on the video display and the STOP RUN
which as a name suggests stops execution of the program.
Thus you now know 2 verbs, DISPLAY and STOP in COBOL.
As you see they are self defining.
PAGE 9
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
COBOL Character Set
With the exception of non-numeric literals and comments
where the entire COBOLs character set maybe used only 52
characters are allowed in a COBOL program. They are :
1) letters A-Z and a-z.
2) spaces or blanks.
3) digits 0-9.
4) the following special characters:
+, -,*, =, >, <, $, , , ;, ., ", (, ), ', -.
If the computer detects any other characters, if not
found under these exceptions noted, an error will be
detected.
Characters Used in Words
A word is composed of a combination of not more than 30
characters. It cannot begin or end with a hyphen and
the valid characters are letters A-Z, digits 0-9, and
hyphen.
Characters Used for Punctuation
The following characters are used for punctuation: (, ),
,, ;,.
Rules for Punctuation
Punctuation characters are used according to the
following rules.
1) When used as punctuation a period, semicolon, or
comma must be followed by a space.
2) At least one space must appear between 2 successive
words in literals.
3) Relation characters (=, >, <) must always be
proceeded by a space and followed by another space.
4) You may optionally use a comma as a seperater between
successive oprands of a statement or between 2
subscripts.
5) You may optionally use a semicolon or comma to
seperate a series of statements or clauses.
6) You may use an apostrophe in place of a quotation
mark when delementing non-numeric literals.
Characters Used in Conditions
The following characters are used in conditions:
1) The greater than sign.
2) The less than sign.
3) The equal sign.
PAGE 10
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Characters Used in Arithmetic
Arithmetic expressions are used in the COMPUTE statement
and they make use of the arithmetic operators.
Evaluation is done in the following order:
1) Expressions within the parenthesis are evaluated
first from the inner most pair to the outer most
pair.
2) Within a pair of parenthesis or if there is none the
order is according to the following operators:
a) Unary "+ or - in the variable or number".
b) Expodentation "**".
c) Mulitiplication and division.
d) Addition and subtraction.
3) For operators with the same order mulitplication and
division or addition and subtraction evaluation is
left to right.
Characters Used for Print Editing
Editing characters are replaced characters in a data
item to be printed. They are used to optimize a
presentation of the data item in a report. They are:
1) 9 numeric character.
2) V decimal point.
3) , comma.
4) Z zero suppress.
5) * check protection.
6) $ currency sign.
7) + plus.
8) - minus.
9) B blank.
10) 0 zero.
11) / slash.
12) CR credit.
13) DR debit.
PAGE 11
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Types of Words
Reserved words are those that have a specific meaning in
COBOL and they must be spelled correctly and used in
only the way that they were intended. Examples are
"ADVANCING, MOVE, PAGE" etc. Program refined words,
non-reserved words, are coded by the programmer for the
following uses:
1) data names,
2) files names,
3) condition names,
4) procedure names.
Reserved Words
Reserved words have specific meanings in COBOL and
therefore use only according to proper Syntax rules.
These words must be spelled correctly. However, reserved
words enclosed in quotation marks become non-numerical
literals and are not reserved words. There are 3 types
of reserved words.
1) Key word - key word is a word which is required in
the statement. There are 3 types:
a) verbs, such as ADD, MOVE, READ.
b) required words that appear in certain statements,
such as TO and the ADD statement.
c) words that have specific functional meaning, such
as PAGE, ZERO, POSITIVE.
2) Optional words - an optional word may or may not be
included in a statement. Examples are GIVING,
ROUNDED, and ON SIZE ERROR, which are clauses in
arithmetic statements.
3) Connectives - connective is a word that joins or
connects 2 adjacent words. There are 2 types:
a) qualifier connective. This is "OF" which
associates a data name, condition name or
paragraph name with it's qualifier.
b) logical connectives. These are words used in
compound combinations. They are AND and OR.
PAGE 12
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
RESERVED WORDS LIST
===================
ACCEPT BLANK CONFIGURATION DYNAMIC
ACCESS BLINK CONTAINS ELSE
ADD BLOCK COPY EMPTY-CHECK
ADVANCING BOTTOM COUNT END
AFTER BY CURRENCY END-OF-PAGE
ALL CALL DATA ENVIRONMENT
ALPHABETIC CHAIN DATE EOP
ALTER CHAINING DATE-COMPILED EQUAL
AND CHARACTER DATE-WRITTEN ERASE
ARE CHARACTERS DAY ERROR
AREA CLOSE DEBUGGING ESCAPE
AREAS CODE-SET DECIMAL-POINT EVERY
ASCENDING COL DECLARATIVES EXCEPTION
ASCII COLLATING DELETE EXHIBIT
ASSIGN COLUMN DELIMITED EXIT
AT COMMA DELIMITER EXTEND
AUTHOR COMP DEPENDING FD
AUTO COMP-0 DESCENDING FILE
AUTO-SKIP COMP-3 DISK FILE-CONTROL
BACKGROUND-COLOR COMPUTATIONAL DISPLAY FILE-ID
BEEP COMPUTATIONAL-0 DIVIDE FILLER
BEFORE COMPUTATIONAL-3 DIVISION FIRST
BELL COMPUTE DOWN FOOTING
FOR IS NAMED POINTER
FOREGROUND-COLOR JUST NATIVE POSITIVE
FROM JUSTIFIED NEGATIVE PRINTER
FULL KEY NEXT PROCEDURE
GIVING LABEL NO PROCEDURES
GO LEADING NO-ECHO PROCEED
GREATER LEFT NOT PROGRAM
HIGH-VALUE LEFT-JUSTIFY NUMBER PROGRAM-ID
HIGH-VALUES LENGTH-CHECK NUMERIC PROMPT
HIGHLIGHT LESS OCCURS Q-RW-Q
I-O LIN OFF QUOTE
I-O-CONTROL LINAGE OMITTED QUOTES
IDENTIFICATION LINAGE-COUNTER ON RANDOM
IF LINE OPEN READ
INDEX LINES OR READY
INDEXED LINKAGE ORGANIZATION RECORD
INITIAL LOCK OUTPUT RECORDS
INPUT LOW-VALUE OVERFLOW REDEFINES
INPUT-OUTPUT LOW-VALUES PAGE RELATIVE
INSPECT MERGE PERFORM RELEASE
INSTALLATION MODE PIC REPLACING
INTO MOVE PICTURE REQUIRED
INVALID MULTIPLY PLUS RERUN
PAGE 13
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
RESERVE SIGN TO ZEROES
RESET SIZE TOP ZEROS
RESTART-FILE SORT TRACE
RETURN SORT-MERGED TRAILING
REVERSE-VIDEO SOURCE-COMPUTER TRAILING-SIGN
REWRITE SPACE UNDERLINE
RIGHT SPACE-FILL UNSTRING
RIGHT-JUSTIFY SPACES UNTIL
ROUNDED SPECIAL-NAMES UP
RUN STANDARD UPDATE
SAME STANDARD-1 UPON
SCREEN START USAGE
SD STATUS USE
SEARCH STOP USING
SECTION STRING VALUE
SECURE SUBTRACT VALUES
SECURITY SYNC VARYING
SELECT SYNCHRONIZED WHEN
SENTENCE TALLYING WITH
SEPARATE THAN WORKING-STORAGE
SEQUENCE THROUGH WRITE
SEQUENTIAL THRU ZERO
SET TIME ZERO-FILL
PAGE 14
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Non-reserved words are coded according to these rules:
1) Only the 26 letters upper and lower case, digits 0-9,
and hyphen can be used.
2) All words must begin with a letter except procedure
names which may consist entirely of digits.
3) A word may not begin or end with a hyphen.
4) A word can have from 1-30 characters.
5) A data name or condition name does not have to be
unique as long as they may be qualified with unique
names of a higher level.
6) A word ends with a space or a punctuation mark.
Data Format
Data used in programs maybe represented in 4 ways. They
are:
1) Display. The data consists of a combination without
the numeric or special characters which each
character using 1 byte of memory. If the data
contains only numbers it maybe used in arithmetic
operation. The "USAGE IS DISPLAY" clause maybe
specified or omitted. Display is a default for the
usage clause.
2) Packed decimal. The data consists of digits with 2
digits packed together in 1 byte except the right
most digit which is packed with the sign. This field
is used for arithmetic or numeric move operations.
The "USAGE IS COMP-3 | COMPUTATIONAL-3". Clause must
be specified.
3) Binary item. The data consists of binary numbers.
The "USAGE IS COMP-0 | COMPUTATIONAL-0". Clause must
be specified.
4) Index. The data item which is defined with the usage
is index clause but without a picture clause is used
as an index data item in a relational condition as a
varying item and performing varying statement or in
place of a subscript.
Elementary Data Items
A data item that is not further subdivided into still
other items within a program is an elementary data item.
It is therefore the lowest level of data item in a
group. Examples are employee numbers, gross salary,
etc. The maximum level of elementary data item is 4,095
bytes.
PAGE 15
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Group Data Item
A data item that is further subdivided into still other
data items is a group item. For instance, the group
item date of birth may consist of 3 elementary data
items - month, day, year. The elementary data item or
the group item maybe used in statements. The maximum
length of a group data item is 4,095 bytes. The
exception are at leve-01 group items records which are
not checked for length so that long tables can be used
in programs. However, statements and procedure division
cannot use data items longer than 4,095 byte limit.
There is no problem with tables because statements are
always referred to individual elements in the table, not
the whole table.
Records
Elementary and group data items that belong to a single
entity maybe grouped together under a single 01 level
record. For instance, all data items employee number,
gross salary, date hired, etc. belong to one employee
may be grouped into a single employee record.
Files
A group of records maybe written or grouped together in
a single file. For instance, all employee records for
all employees in a company belong to the employee master
file.
PAGE 16
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
The COBOL Coding Form
In good ole days when cards were used to enter programs
programmers used to write COBOL source programs on these
coding forms before punching them or having them punched
by keypunch operators. Now a days most programmers
enter their code directly on the screen via text editor
thus negating the need for coding forms. HOWEVER!!! You
still must adhere to the coding form rules and they are:
1) Columns 1-6 were originally used to enter line
numbers. The reason if some clot was to drop the
cards they can easily be sorted again. Today you may
or may not enter the line numbers, it does not make
any difference.
2) Column 7 is used 4 ways. They are:
a) if an asterisk is entered the line is considered a
comment.
b) if a slash is entered it will cause a page eject
in the program listing.
c) if non-numerical literal is to be continued on the
next line a hyphen must be entered.
d) if the letter D is entered than the line is
compiled as part of the program IF AND ONLY IF the
statement camps with debugging mode. Clauses
included in the SOURCE-COMPUTER paragraph of the
CONFIGURATION SECTION in the ENVIRONMENT DIVISION.
3) Columns 8-11 define area A a statement that starts a
group of related statements must start anywhere
within this area. Examples are division headers,
section headers, 01 level group items, paragraph
names, etc. However, for the sake of readability you
should always start them in Column A.
4) Columns 12-77 define area B all other statements that
cannot start in area A must start here.
5) Columns 78-80 are not processed by this compiler.
6) For the PC, characters may be entered in either
lowercase or uppercase.
PAGE 17
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
BASIC COBOL STATEMENTS
INTRODUCTION
Before we go into the details of coding, let us take a
few more simpilified program examples that will
familiarize us with many of the concepts that we will be
using later on. These concepts will be very useful when
we attempt to write larger programs. Let me remind you
that you have already seen the two verbs DISPLAY and
STOP.
PAGE 18
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
ACCEPT statement (format 2)
The ACCEPT verb may be used to allow the operator to
enter data on the console display in its normal
scrolling mode. This version (format 2) is generally
used if there is no need to have data entered on a
formatted screen (formatted screens are needed if a lot
of data is entered on the same screen). The program is
shown in fig. 4.1. Look at line 34 in the PROCEDURE
DIVISION which shows that the program accepts data from
the operator. The data then goes into field W005-
MESSAGE-FIELD, which line 28 shows can accommodate as
many as thirty-two characters. The same data is then
displayed back on the video display unit at line 35.
Note that each complete statement ends with a period,
making it a sentence.
PROGRAM LISTING 4.01
--------------------
PROG401 COB 12:00:14 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG401.
4 *
5 ***************************************************
6 * *
7 * 1. DATE-WRITTEN. 08/01/90. *
8 * *
9 * 2. THIS PROGRAM DISPLAYS ON THE CONSOLE DISPLAY *
10 * A MESSAGE ENTERED BY THE OPERATOR. *
11 * *
12 ***************************************************
13 *
14 *
15 ENVIRONMENT DIVISION.
16 *
17 *
18 DATA DIVISION.
19 *
20 *
21 ****************************************************
22 * *
23 WORKING-STORAGE SECTION.
24 * *
25 ****************************************************
26 *
27 *
28 01 W005-MESSAGE-FIELD PIC X(32).
29 *
30 *
31 PROCEDURE DIVISION.
32 *
33 DISPLAY-ACCEPTED-MESSAGE.
PAGE 19
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
34 ACCEPT W005-MESSAGE-FIELD.
35 DISPLAY W005-MESSAGE-FIELD.
36 STOP RUN.
--------------------------------------------------------
The PRINTER DISPLAY STATEMENT
We have seen that the DISPLAY verb can display
information on the video display unit. Actually this
verb is very powerful and can also be used to display
information on the printer. Note that this is useful
for displaying a small amount of information only and
should not replace the technique of using the printer
as a afile which presents in a nice format a very large
amount of information. also, this feature should not
be intersperced with the printing of reports since it
will get mixed with the later. The program is shown in
fig.4.2. Note lines 17 to 21. These specify that the
printer will be used for displayed information. Lines
42 to 44 are similar to lines 34 to 36 of fig.4.1
execpt that the DISPLAY statement now includes the
operands "UPON PRINTER-DISPLAY". This ties up with
statement 21 and the information entered by the
operator on the console display is printed out at line
43. The result is fig.4.3. Note that the operator
entered "THIS MESSAGE IS OPERATOR ENTERED".
PROGRAM LISTING 4.2
-------------------
PROG402 COB 12:18:22 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG402.
4 *
5 ***************************************************
6 * *
7 * 1. DATE-WRITTEN. 08/01/90. *
8 * *
9 * 2. THIS PROGRAM DISPLAYS ON THE PRINTER *
10 * A MESSAGE ENTERED BY THE OPERATOR. *
11 * *
12 ***************************************************
13 *
14 *
15 ENVIRONMENT DIVISION.
16 *
17 CONFIGURATION SECTION.
18 *
19 SPECIAL-NAMES.
20 *
21 PRINTER IS PRINTER-DISPLAY.
PAGE 20
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
22 *
23 *
24 DATA DIVISION.
25 *
26 *
27 ****************************************************
28 * *
29 WORKING-STORAGE SECTION.
30 * *
31 ****************************************************
32 *
33 *
34 01 W005-MESSAGE-FIELD PIC X(32).
35 *
36 *
37 PROCEDURE DIVISION.
38 *
39 DISPLAY-ACCEPTED-MESSAGE.
40 DISPLAY "PROGRAM PROG402: PRINT DISPLAY OUTPUT:"
41 UPON PRINTER-DISPLAY.
42 ACCEPT W005-MESSAGE-FIELD.
43 DISPLAY W005-MESSAGE-FIELD UPON PRINTER-DISPLAY.
44 STOP RUN.
--------------------------------------------------------
EXAMPLE 4.3
PROGRAM PROG402: PRINT DISPLAY OUTPUT:
THIS MESSAGE IS OPERATOR ENTERED
--------------------------------------------------------
THE MOVE STATEMENT
The MOVE verb moves data to a data field. The data may
be a literal specified in the statement or another data
field. The program is shown in fig. 4.4. The reader
should look at lines 38 and 40. These are the fields
involved in the MOVE statements in lines 49 and 50. The
operator will enter the data into the field "W005-
ACCEPT-MESSAGE-FIELD" and this is moved to the field
"W005-DISPLAY-MESSAGE-FIELD". The rest are the same as
in PROG402. The result is shown in fig.4.5.
PROGRAM LISTING 4.4
-------------------
PROG404 COB 12:34:20 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG404.
4 *
5 ***************************************************
PAGE 21
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
6 * *
7 * 1. DATE-WRITTEN. 08/01/90. *
8 * *
9 * 2. THIS PROGRAM DISPLAYS ON THE PRINTER *
10 * A MESSAGE ENTERED BY THE OPERATOR. *
11 * *
12 * 3. THE MESSAGE IS INITIALLY ENTERED INTO ONE *
13 * WHICH IS THEN MOVED TO ANOTHER FIELD BEFORE *
14 * BEING PRINTED ON THE PRINTER. *
15 * *
16 ***************************************************
17 *
18 *
19 ENVIRONMENT DIVISION.
20 *
21 CONFIGURATION SECTION.
22 *
23 SPECIAL-NAMES.
24 *
25 PRINTER IS PRINTER-DISPLAY.
26 *
27 *
28 DATA DIVISION.
29 *
30 *
31 ****************************************************
32 * *
33 WORKING-STORAGE SECTION.
34 * *
35 ****************************************************
36 *
37 *
38 01 W005-ACCEPT-MESSAGE-FIELD PIC X(32).
39 *
40 01 W005-DISPLAY-MESSAGE-FIELD PIC X(32).
41 *
42 *
43 PROCEDURE DIVISION.
44 *
45 DISPLAY-ACCEPTED-MESSAGE.
46 DISPLAY "PROGRAM PROG404: PRINT DISPLAY OUTPUT:"
47 UPON PRINTER-DISPLAY.
48 ACCEPT W005-ACCEPT-MESSAGE-FIELD.
49 MOVE W005-ACCEPT-MESSAGE-FIELD
50 TO W005-DISPLAY-MESSAGE-FIELD.
51 DISPLAY W005-DISPLAY-MESSAGE-FIELD
52 UPON PRINTER-DISPLAY.
53 STOP RUN.
--------------------------------------------------------
EXAMPLE 4.5
PROGRAM PROG404: PRINT DISPLAY OUTPUT:
THIS MESSAGE IS OPERATOR ENTERED
--------------------------------------------------------
PAGE 22
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
THE ADD STATEMENT
The ADD verb adds two numbers and as options rounds off
the sum, checks it for overflow, or places it into a
specific field. Here, we will take up the most basic
version of the statement where we add two numbers
(contained in the two operands) and the sum is placed in
the second operand and thus replaces its original value.
The program is fig.4.6. Lines 34 and 36 specify the
operands to be used and their respective values. Line
42 does the ADD operation. The result is fig.4.7.
PROGRAM LISTING 4.6
--------------------
PROG406 COB 12:49:48 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG406.
4 *
5 ***************************************************
6 * *
7 * 1. DATE-WRITTEN. 08/01/90. *
8 * *
9 * 2. THIS PROGRAM DISPLAYS ON THE PRINTER *
10 * A VALUE COMPUTED FROM AN ADD OPERATION. *
11 * *
12 ***************************************************
13 *
14 *
15 ENVIRONMENT DIVISION.
16 *
17 CONFIGURATION SECTION.
18 *
19 SPECIAL-NAMES.
20 *
21 PRINTER IS PRINTER-DISPLAY.
22 *
23 *
24 DATA DIVISION.
25 *
26 *
27 ****************************************************
28 * *
29 WORKING-STORAGE SECTION.
30 * *
31 ****************************************************
32 *
33 *
34 01 W005-FIRST-OPERAND PIC 9 VALUE 2.
35 *
36 01 W005-SECOND-OPERAND PIC 99 VALUE 12.
37 *
PAGE 23
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
38 *
39 PROCEDURE DIVISION.
40 *
41 PRINT-COMPUTED-VALUE.
42 ADD W005-FIRST-OPERAND TO W005-SECOND-OPERAND.
43 DISPLAY "PROGRAM PROG406: THE SUM OF 2 + 12 IS:"
44 UPON PRINTER-DISPLAY.
45 DISPLAY W005-SECOND-OPERAND UPON PRINTER-DISPLAY.
46 STOP RUN.
---------------------------------------------------------
EXAMPLE 4.7
PROGRAM PROG406: THE SUM OF 2 + 12 IS:
14
----------------------------------------------------------
THE SUBTRACT STATEMENT
The SUBTRACT verb subtracts two numbers and as options
rounds off the result, checks it for overflow, or places
it into a specific field. Here, we will take up the
most basic version of the statement where we subtract
two numbers (contained in the two operands ) and the
result is placed in the second operand ( the minuend)
and thus replaces the original value. The program is
shown in fig.4.8. Line 42 subtracts the two numbers,
which is then displayed on the printer. The result is
fig.4.9.
PROGRAM LIST 4.8
----------------
PROG408 COB 13:01:10 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG408.
4 *
5 ***************************************************
6 * *
7 * 1. DATE-WRITTEN. 08/01/90. *
8 * *
9 * 2. THIS PROGRAM DISPLAYS ON THE PRINTER *
10 * A VALUE COMPUTED FROM A SUBTRACT OPERATION. *
11 * *
12 ***************************************************
13 *
14 *
15 ENVIRONMENT DIVISION.
16 *
17 CONFIGURATION SECTION.
18 *
19 SPECIAL-NAMES.
20 *
PAGE 24
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
21 PRINTER IS PRINTER-DISPLAY.
22 *
23 *
24 DATA DIVISION.
25 *
26 *
27 ****************************************************
28 * *
29 WORKING-STORAGE SECTION.
30 * *
31 ****************************************************
32 *
33 *
34 01 W005-SUBTRAHEND PIC 9 VALUE 2.
35 *
36 01 W005-MINUEND PIC 99 VALUE 12.
37 *
38 *
39 PROCEDURE DIVISION.
40 *
41 PRINT-COMPUTED-VALUE.
42 SUBTRACT W005-SUBTRAHEND FROM W005-MINUEND.
43 DISPLAY "PROGRAM PROG408: THE RESULT OF 12 - 2 IS:"
44 UPON PRINTER-DISPLAY.
45 DISPLAY W005-MINUEND UPON PRINTER-DISPLAY.
46 STOP RUN.
--------------------------------------------------------
EXAMPLE 4.9
PROGRAM PROG408: THE RESULT OF 12 - 2 IS:
10
---------------------------------------------------------
THE MULTIPLY STATEMENT
The MULTIPLY verb multiplies two numbers and as options
rounds off the product, checks it for overflow, or puts
it into a specific field. Here, we will take up the
most basic version of the statement where we multiply
two numbers (contained in the two operands) and the
product is placed in the second operand ( the
multiplier) and thus replaces its original value. The
program is shown in fig.4.10. Line 42 does the
multiplication which is then printed out. The result is
fig.4.11.
PROGRAM LIST 4.10
-----------------
PROG410 COB 13:13:40 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG410.
PAGE 25
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
4 *
5 ***************************************************
6 * *
7 * 1. DATE-WRITTEN. 08/01/90. *
8 * *
9 * 2. THIS PROGRAM DISPLAYS ON THE PRINTER *
10 * A VALUE COMPUTED FROM A MULTIPLY OPERATION. *
11 * *
12 ***************************************************
13 *
14 *
15 ENVIRONMENT DIVISION.
16 *
17 CONFIGURATION SECTION.
18 *
19 SPECIAL-NAMES.
20 *
21 PRINTER IS PRINTER-DISPLAY.
22 *
23 *
24 DATA DIVISION.
25 *
26 *
27 ****************************************************
28 * *
29 WORKING-STORAGE SECTION.
30 * *
31 ****************************************************
32 *
33 *
34 01 W005-MULTIPLICAND PIC 9 VALUE 2.
35 *
36 01 W005-MULTIPLIER PIC 99 VALUE 12.
37 *
38 *
39 PROCEDURE DIVISION.
40 *
41 PRINT-COMPUTED-VALUE.
42 MULTIPLY W005-MULTIPLICAND BY W005-MULTIPLIER.
43 DISPLAY "PROGRAM PROG410: THE PRODUCT OF 2 * 12 IS:"
44 UPON PRINTER-DISPLAY.
45 DISPLAY W005-MULTIPLIER UPON PRINTER-DISPLAY.
46 STOP RUN.
---------------------------------------------------------
EXAMPLE 4.11
PROGRAM PROG410: THE PRODUCT OF 2 * 12 IS:
24
----------------------------------------------------------
PAGE 26
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
THE DIVIDE STATEMENT
The DIVIDE verb divides two numbers and as options
rounds off the quotient, checks it for overflow, or
places it into a specific field. Here, we will take up
the most basic version of the statement where we divide
two numbers and the quotient is placed in the second
operand (the dividend) and thus replaces its original
value. The program is shown in fig.4.12. Line 42
divides the two numbers and the result is then printed
out. The result is fig.4.13. You will notice that the
result is 06, not simply 6.
PROGRAM LIST 4.12
-------------------
PROG412 COB 13:25:31 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG412.
4 *
5 ***************************************************
6 * *
7 * 1. DATE-WRITTEN. 08/01/90. *
8 * *
9 * 2. THIS PROGRAM DISPLAYS ON THE PRINTER *
10 * A VALUE COMPUTED FROM A DIVIDE OPERATION. *
11 * *
12 ***************************************************
13 *
14 *
15 ENVIRONMENT DIVISION.
16 *
17 CONFIGURATION SECTION.
18 *
19 SPECIAL-NAMES.
20 *
21 PRINTER IS PRINTER-DISPLAY.
22 *
23 *
24 DATA DIVISION.
25 *
26 *
27 ****************************************************
28 * *
29 WORKING-STORAGE SECTION.
30 * *
31 ****************************************************
32 *
33 *
34 01 W005-DIVISOR PIC 9 VALUE 2.
35 *
PAGE 27
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
36 01 W005-DIVIDEND PIC 99 VALUE 12.
37 *
38 *
39 PROCEDURE DIVISION.
40 *
41 PRINT-COMPUTED-VALUE.
42 DIVIDE W005-DIVISOR INTO W005-DIVIDEND.
43 DISPLAY "PROGRAM PROG412: THE QUOTIENT OF 12 / 2 IS:"
44 UPON PRINTER-DISPLAY.
45 DISPLAY W005-DIVIDEND UPON PRINTER-DISPLAY.
46 STOP RUN.
---------------------------------------------------------
EXAMPLE 4.13
PROGRAM PROG412: THE QUOTIENT OF 12 / 2 IS:
06
---------------------------------------------------------
THE GIVING CLAUSE
We have so far used the four arithmetic operations where
we allowed the result to replace one of the original
operands. This may be all right for some programs, but
in others you may want to preserve the original numbers
because you may need them later on. We accomplish this
by including the optional GIVING clause which specifies
a data item that will contain the result of the
arithmetic operation. An example is fig.4.14. Line 40
defines the data item that will receive the result of
the DIVIDE operation, which is coded in line 46. This
is the data item that we will also display on the
printer. The result is fig.4.15.
PROGRAM LISTING 4.14
---------------------
PROG414 COB 13:37:26 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG414.
4 *
5 ***************************************************
6 * *
7 * 1. DATE-WRITTEN. 08/01/90. *
8 * *
9 * 2. THIS PROGRAM DISPLAYS ON THE PRINTER *
10 * A VALUE COMPUTED FROM A DIVIDE OPERATION. *
11 * *
12 * 3. THE QUOTIENT IS PLACED INTO A DIFFERENT FIELD*
13 * *
14 ***************************************************
15 *
16 *
PAGE 28
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
17 ENVIRONMENT DIVISION.
18 *
19 CONFIGURATION SECTION.
20 *
21 SPECIAL-NAMES.
22 *
23 PRINTER IS PRINTER-DISPLAY.
24 *
25 *
26 DATA DIVISION.
27 *
28 *
29 ****************************************************
30 * *
31 WORKING-STORAGE SECTION.
32 * *
33 ****************************************************
34 *
35 *
36 01 W005-DIVISOR PIC 9 VALUE 2.
37 *
38 01 W005-DIVIDEND PIC 99 VALUE 12.
39 *
40 01 W005-QUOTIENT PIC 9.
41 *
42 PROCEDURE DIVISION.
43 *
44 PRINT-COMPUTED-VALUE.
45 DIVIDE W005-DIVISOR INTO W005-DIVIDEND GIVING W005-QUOTIENT.
46 DISPLAY "PROGRAM PROG414: THE QUOTIENT OF 12 / 2 IS:"
47 UPON PRINTER-DISPLAY.
48 DISPLAY W005-QUOTIENT UPON PRINTER-DISPLAY.
49 STOP RUN.
---------------------------------------------------------
EXAMPLE 4.15
PROGRAM PROG414: THE QUOTIENT OF 12 / 2 IS:
6
---------------------------------------------------------
THE ROUNDED CLAUSE
In certain arithmetic operations, especially division
and sometimes multiplication with decimals, there may be
extra digits in the result to the right of the decinal
point that cannot be accommodated in the data item that
holds this result. ANSI-COBOL automatically truncates
these digits from the result without rounding off the
remaining loworder (rightmost) digit, unless the
optional ROUNDED clause is included. Fig. 4.16 shows
the differnce between division without rounding and one
with rounding. Both versions will be displayed for
comparison. Lines 50 to 53 shows division without
rounding, followed by the corresponding display; and
lines 54 to 58, those with rounding. Incidentally, line
52 shows how a non-numeric literal is continued in the
next line. The result is fig.4.17. The quotient of 5/3
PAGE 29
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
is 1 if not rounded, and 2 if rounded. Since the
rounded version is closer to the true answer, this
option should always be used if truncation can occur.
PROGRAM LISTING 4.16
--------------------
PROG416 COB 14:01:37 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG416.
4 *
5 *********************************************************
6 * *
7 * 1. DATE-WRITTEN. 08/01/90. *
8 * *
9 * 2. THIS PROGRAM DISPLAYS ON THE PRINTER *
10 * A VALUE COMPUTED FROM A DIVIDE OPERATION. *
11 * *
12 * 3. THE QUOTIENT IS PLACED INTO A DIFFERENT FIELD *
13 * *
14 * 4. THE DIVIDE OPERATION AND DISPLAY WILL BE DONE TWICE*
15 * A) TRY #1 - QUOTIENT IS NOT ROUNDED OFF. *
16 * B) TRY #2 - QUOTIENT IS ROUNDED OFF. *
17 * *
18 *********************************************************
19 *
20 *
21 ENVIRONMENT DIVISION.
22 *
23 CONFIGURATION SECTION.
24 *
25 SPECIAL-NAMES.
26 *
27 PRINTER IS PRINTER-DISPLAY.
28 *
29 *
30 DATA DIVISION.
31 *
32 *
33 ****************************************************
34 * *
35 WORKING-STORAGE SECTION.
36 * *
37 ****************************************************
38 *
39 *
40 01 W005-DIVISOR PIC 9 VALUE 3.
41 *
42 01 W005-DIVIDEND PIC 9 VALUE 5.
43 *
44 01 W005-QUOTIENT PIC 9.
45 *
46 *
PAGE 30
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
47 PROCEDURE DIVISION.
48 *
49 PRINT-COMPUTED-VALUE.
50 DIVIDE W005-DIVISOR INTO W005-DIVIDEND GIVING W005-QUOTIENT.
51 DISPLAY "PROGRAM PROG414: THE QUOTIENT OF 5 / 3 UNROUNDED IS
52 - ":" UPON PRINTER-DISPLAY.
53 DISPLAY W005-QUOTIENT UPON PRINTER-DISPLAY.
54 DIVIDE W005-DIVISOR INTO W005-DIVIDEND
55 GIVING W005-QUOTIENT ROUNDED.
PROG416 COB 14:01:37 02-Sep-90 PAGE 2
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
56 DISPLAY "PROGRAM PROG414: THE QUOTIENT OF 5 / 3 ROUNDED IS:"
57 UPON PRINTER-DISPLAY.
58 DISPLAY W005-QUOTIENT UPON PRINTER-DISPLAY.
59 STOP RUN.
-----------------------------------------------------------
EXAMPLE 4.17
PROGRAM PROG416: THE QUOTIENT OF 5 / 3 UNROUNDED IS:
1
PROGRAM PROG416: THE QUOTIENT OF 5 / 3 ROUNDED IS:
2
----------------------------------------------------------
THE PERFORM STATEMENT
The PERFORM verb executes a set of one or more
contiguous sections or paragraphs, then returns control
to the statement following the PERFORM. It is thus a
temporary branch from the current set of statements
being executed. It is an extremely useful verb and is
generally used to control the program logic by selecting
which statements are to be executed at any given time.
The program is shown in fig.4.20.
PROGRAM LISTING 4.20
--------------------
PROG420 COB 14:35:22 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG420.
4 *
5 ENVIRONMENT DIVISION.
6 *
7 CONFIGURATION SECTION.
8 *
9 SPECIAL-NAMES.
PAGE 31
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
10 *
11 PRINTER IS PRINTER-DISPLAY.
12 *
13 *
14 DATA DIVISION.
15 *
16 *
17 WORKING-STORAGE SECTION.
18 *
19 01 W005-DIVISOR PIC 9 VALUE 2.
20 *
21 01 W005-DIVIDEND PIC 99 VALUE 12.
22 *
23 01 W005-QUOTIENT PIC 9.
24 *
25 *
26 PROCEDURE DIVISION.
27 *
28 MAIN-LINE-LOGIC.
29 PERFORM PRINT-COMPUTED-VALUE.
30 STOP RUN.
31 *
32 *
33 PRINT-COMPUTED-VALUE.
34 DIVIDE W005-DIVISOR INTO W005-DIVIDEND GIVING W005-QUOTIENT.
35 DISPLAY "12/2 IS".
36 DISPLAY W005-QUOTIENT.
---------------------------------------------------------
THE ON SIZE ERROR CLAUSE
If after decimal point alignment and rounding, the high-
order (left-most) portion of the result cannot fit in
the data item for the result, the "size error" condition
occurs. If the ON SIZE ERROR option is not used in the
arithmetic statement, the result is unpredictable.
Otherwise, the imperative statements that fall under the
ON SIZE ERROR clause will be executed. An example is
fig.4.22.
PROGRAM LISTING 4.22
--------------------
PROG422 COB 14:36:08 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. CHAP422.
4 *
5 ENVIRONMENT DIVISION.
6 *
7 CONFIGURATION SECTION.
8 *
9 SPECIAL-NAMES.
PAGE 32
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
10 *
11 PRINTER IS PRINTER-DISPLAY.
12 *
13 DATA DIVISION.
14 *
15 WORKING-STORAGE SECTION.
16 *
17 01 W005-DIVISOR PIC 9 VALUE 0.
18 *
19 01 W005-DIVIDEND PIC 99 VALUE 5.
20 *
21 01 W005-QUOTIENT PIC 9.
22 *
23 *
24 PROCEDURE DIVISION.
25 *
26 MAIN-LINE-LOGIC.
27 PERFORM PRINT-COMPUTED-VALUE.
28 STOP RUN.
29 *
30 *
31 PRINT-COMPUTED-VALUE.
32 DIVIDE W005-DIVISOR INTO W005-DIVIDEND GIVING W005-QUOTIENT
33 ON SIZE ERROR
34 DISPLAY "ON SIZE ERROR ENCOUNTERED"
35 DISPLAY "PROGRAM ABORTING"
36 STOP RUN.
37 DISPLAY "No On Size error".
38 DISPLAY "PROGRAM EXITING NORMALLY".
39 STOP RUN.
---------------------------------------------------------
THE GO TO STATEMENT
The GO TO statement verb provides an unconditional
branch from the current set of statements to a specific
section or paragraph in the program. Unlike the PERFORM
verb, there is no return to where it came from and the
execution will continue right at the section or
paragraph specified as the operand of the verb. Many
studies in structured programming have shown that the
uncontrolled use of this verb can make the program logic
hard to follow because of the many "jumps" that occur.
I therefore suggest that we only use this verb in
certain conditions. Fig. 4.24 shows an example of the
GO TO.
PAGE 33
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
PROGRAM LISTING 4.24
--------------------
PROG424 COB 14:37:39 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. CHAP424.
4 *
5 ENVIRONMENT DIVISION.
6 *
7 CONFIGURATION SECTION.
8 *
9 SPECIAL-NAMES.
10 PRINTER IS PRINTER-DISPLAY.
11 *
12 *
13 DATA DIVISION.
14 *
15 WORKING-STORAGE SECTION.
16 *
17 01 W005-DIVISOR PIC 9 VALUE 0.
18 *
19 01 W005-DIVIDEND PIC 99 VALUE 5.
20 *
21 01 W005-QUOTIENT PIC 9.
22 *
23 *
24 PROCEDURE DIVISION.
25 *
26 MAIN-LINE-LOGIC.
27 GO TO PRINT-COMPUTED-VALUE.
28 *
29 *
30 PRINT-COMPUTED-VALUE.
31 DIVIDE W005-DIVISOR INTO W005-DIVIDEND GIVING W005-QUOTIENT
32 ON SIZE ERROR
33 DISPLAY "ON SIZE ERROR ENCOUNTERED"
34 DISPLAY "PROGRAM ABORTING"
35 STOP RUN.
36 DISPLAY "No On Size error".
37 DISPLAY "PROGRAM EXITING NORMALLY".
38 STOP RUN.
PAGE 34
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
THE COMPUTE STATEMENT
The COMPUTE statement is used to evaluate an arithmetic
expression. It can therefore be used in place of
individual ADD, SUBTRACT, MULTIPLY, or DIVIDE
statements. It is also used ijn exponentialtion
(raising a number to a power), although VERSION 6.50
only allows integers for the exponent. It's main
drawback is that the intermediate results are
manipulated by the statement (not the programmer) and
may result in truncation of digits to the right of tthe
decimal point. Therefore, be careful when using this
statement. An example of the use of COMPUTE is
fig.4.26.
PROGRAM LISTING 4.26
--------------------
PROG426 COB 14:41:15 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 *
2 IDENTIFICATION DIVISION.
3 *
4 PROGRAM-ID. CHAP426.
5 *
6 ENVIRONMENT DIVISION.
7 *
8 CONFIGURATION SECTION.
9 *
10 SPECIAL-NAMES.
11 PRINTER IS PRINTER-DISPLAY.
12 *
13 *
14 DATA DIVISION.
15 *
16 WORKING-STORAGE SECTION.
17 *
18 *
19 01 W005-GROSS-PAY PIC 9(4)V99.
20 *
21 01 W005-BASE-PAY PIC 999V99 VALUE 500.
22 *
23 01 W005-WEEK-HOURS PIC 99V99 VALUE 39.5.
24 *
25 *
26 PROCEDURE DIVISION.
27 *
28 MAIN-LINE-LOGIC.
29 GO TO PRINT-COMPUTED-VALUE.
30 *
31 *
32 PRINT-COMPUTED-VALUE.
33 COMPUTE W005-GROSS-PAY ROUNDED =
34 W005-BASE-PAY * ( 1 + 1.5 * ( W005-WEEK-HOURS - 35 ) / 35 )
35 DISPLAY W005-GROSS-PAY.
PAGE 35
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
36 COMPUTE W005-GROSS-PAY ROUNDED =
37 W005-BASE-PAY * ( 1 + ( 1.5 / 35 )
38 * ( W005-WEEK-HOURS - 35)).
39 DISPLAY W005-GROSS-PAY.
40 STOP RUN.
PAGE 36
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
CHAPTER 5
BASIC FILE OPERATIONS
INTRODUCTION
Cobol was deveeloped for business applications and as
such was designed to make it easier ( compared to other
language ) for programmers to write programs for
applications like PAYROLL, INVENTORY CONTROL, ACCOUNTS
REC. ECT. While its arithmetic capablities, though more
than adequate for business applications, are not as
extensive as those of fortran, its ablitity to process
large amounts of data of different formats from
different locations make it the most popular programming
language for commercial applications.
PAGE 37
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
FILES
Data used in COBOL programs (except for low-volume data
like an end-of-cycle date entered at the begining of the
computer run) are generally contained in files. We may
think of files as similar to file cabinets that contain
a lot of information about a particular subject matter.
In a payrole application, the PAYROLE MASTER FILE is one
that contains information for all employees in the
company. In an Inventory application, the INVENTORY
MASTER FILE contains the relevant information about all
items being stocked by the company.
FILE ORGANIZATION
Files used by ANSI-STANDARD COBOL 6.50 may fall under
four types of organization. The regular sequential
(usually called sequential) organization file is the
type normally created by COBOL programs. The records are
only logically sequential because the will appear that
way to the program. They may not really be physically
in sequence since DOS uses the first available sector on
the disk on file operations. However, thisdoes not
concern the programmer in cobol because DOS will
retrieve these records in the proper sequence.
The records in the file are of variable length and each
one has a 2-byte prefix created by DOS containing the
record number. This prefix is transparent to COBOL and
is therefore not defined as part of the record.
The line sequentional organization file has each record
followed by a CR/LF. This type file is created normally
by a word proc.
The indexed organization and relative organization will
be discussed in greater detail later on in the text.
RECORDS
Each record in the file may have up to 4,095 bytes but
no more.
PAGE 38
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
THE OPEN STATEMENT
Each file used must be opened before any activity is
allowed on it; else an error occurs. Any sequential
READ statement will then retrieve the first record in
the file. The format of the OPEN statement is:
OPEN INPUT|OUTPUT|I-O|EXTEND FDFILENAME
The following rules apply:
1. Filename corresponds to those in the SELECT and FD
(file description) entries.
2. Files that are simultaneously opend as either
INPUT,OUTPUT,I-O, or EXTEND may be grouped together.
3. INPUT,OUTPUT,I-O, and EXTEND may be coded in the same
statement.
4. Use INPUT if the file already exists and will be used
only for "READING" data from it.
5. Use OUTPUT if the file does not exist or you want to
replace an existing file with new records generated
in the program. The printer is ALWAYS an output file.
6. Use I-O if you want to add new records (WRITE), or
update old records (REWRITE after a READ) to an
existing disk file. NOTE: the file must already exist
if the I-O mode is used. Also, the WRITE verb cannot
be used in I-O mode if organization is sequential.
7. Use EXTEND if you want to append new records at the
end of an existing file. NOTE: The file must already
exist if tthe EXTEND mode is used. Only WRITE
statements are allowed and only sequential files may
be opened in EXTEND mode.
THE CLOSE STATEMENT
Each file used must be closed if no longer required, as
for instance when all records have been read from or
written to it. Closing files allows the operating
system to do its housekeeping chores on the file,
disposing of them properly depending on their nature.
The format of the CLOSE statement is :
CLOSE FDFILENAME WITH LOCK.
You may thus close as many files you want in a single
statement. The WITH LOCK option makes sure that the
file cannot be reopened in the same program. If
required, it is coded for the specific files that
require them.
PAGE 39
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
THE READ STATEMENT
The read statement brings an existing record into your
program. It can only be used for files that are opened
as INPUT or I-O. The format is:
READ FDFILENAME INTO DATA-NAME
AT END, statements
The INTO option specifies a data name in the WORKING-
STORAGE section that will receive the data. The AT END
condition specifies the imperative statements that will
be executed when that are no more records in the file.
THE WRITE STATEMENT (PRINT FILE)
The WRITE statement writes records into an output file.
Here, we will only discuss it's use in generating print
lines on the printer. This is used to prepare well-
structured reports of the type used by management and
employee personal, unlike the DISPLAY verb, which is
basically used to print unstructured, short messages for
the computer operator. Extreme care must be made when
using both features since we don't want messages mixed
in with reports. The format for the WRITE statement is:
WRITE print-record AFTER ADVANCING data-name|literal
LINES|PAGE
Print-record is th 01-level record defined as part of
the FD entry for the file. The "AFTER ADVANCING" clause
specifies the printer carrage control skipping action
before the line is printed. The "AFTER ADVANCING PAGE"
option specifies that the line is printed after the
paper is positioned on a new page. The "AFTER ADVANCING
data-name|literal LINES" option specifies that the paper
is advanced so many lines before the line is printed.
The literal must be an unsigned integer and the data-
name defined as an unsigned integer, and skipping will
occur according to the following values they hold:
VALUE CARRIAGE CONTROL ACTION
--------------------------------------------------------
0 NO SPACING
1 NORMAL (PRINT ON NEXT LINE)
2 1 BLANK SPACE BEFORE PRINTING
3 2 BLANK SPACES BEFORE PRINTING
. ....
. ....
120 119 BLANK SPACES BEFORE PRINTING
PAGE 40
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
PROGRAM LISTING 5.01
--------------------
PROG501 COB 15:25:03 02-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG501.
4 *
5 DATE-WRITTEN. 08/13/90.
6 *
7 AUTHOR. BOB NOWECK.
8 *
9 SECURITY. NONE.
10 *
11 *
12 ENVIRONMENT DIVISION.
13 *
14 INPUT-OUTPUT SECTION.
15 *
16 FILE-CONTROL.
17 *
18 SELECT EMPLOYEE-ADDRESS-MASTER
19 ASSIGN TO DISK
20 ORGANIZATION IS LINE SEQUENTIAL.
21 *
22 SELECT EMPLOYEE-ADDRESS-PRINT
23 ASSIGN TO PRINTER.
24 *
25 *
26 DATA DIVISION.
27 *
28 FILE SECTION.
29 *
30 FD EMPLOYEE-ADDRESS-MASTER
31 LABEL RECORDS STANDARD
32 VALUE OF FILE-ID IS "FIOPRT.DAT".
33 01 EMPLOYEE-ADDRESS-MASTER-RECORD.
34 05 EMPLOYEE-ADDRESS-MASTER-NAME PIC X(30).
35 05 EMPLOYEE-ADDRESS-MASTER-STREET PIC X(30).
36 05 EMPLOYEE-ADDRESS-MASTER-CITY PIC X(30).
37 *
38 FD EMPLOYEE-ADDRESS-PRINT
39 LABEL RECORDS OMITTED.
40 01 EMPLOYEE-ADDRESS-PRINT-LINE PIC X(30).
41 *
42 *
43 WORKING-STORAGE SECTION.
44 *
45 01 W005-END-OF-FILE-SWITCH PIC X.
46 88 W005-END-OF-FILE VALUE "1".
47 01 W005-LINE-SKIP PIC 99.
48 *
49 PROCEDURE DIVISION.
50 *
PAGE 41
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
51 C000-MAIN-LINE-LOGIC.
52 *
53 OPEN INPUT EMPLOYEE-ADDRESS-MASTER
54 OUTPUT EMPLOYEE-ADDRESS-PRINT.
55 MOVE "0" TO W005-END-OF-FILE-SWITCH.
PROG501 COB 15:25:03 02-Sep-90 PAGE 2
Line Number Source Line ANSI 74-85 Standard Cobol V.6.0 (c)1990.
56 PERFORM C060-READ-EMPLOYEE-MASTER.
57 PERFORM C020-PROCESS-EMPLOYEE-MASTER
58 UNTIL W005-END-OF-FILE.
59 CLOSE EMPLOYEE-ADDRESS-MASTER
60 EMPLOYEE-ADDRESS-PRINT.
61 STOP RUN.
62 *
63 C020-PROCESS-EMPLOYEE-MASTER.
64 *
65 MOVE EMPLOYEE-ADDRESS-MASTER-NAME
66 TO EMPLOYEE-ADDRESS-PRINT-LINE.
67 MOVE 3 TO W005-LINE-SKIP.
68 PERFORM C040-WRITE-DETAIL-LINE.
69 MOVE EMPLOYEE-ADDRESS-MASTER-STREET
70 TO EMPLOYEE-ADDRESS-PRINT-LINE.
71 MOVE 3 TO W005-LINE-SKIP.
72 PERFORM C040-WRITE-DETAIL-LINE.
73 MOVE EMPLOYEE-ADDRESS-MASTER-CITY
74 TO EMPLOYEE-ADDRESS-PRINT-LINE.
75 MOVE 3 TO W005-LINE-SKIP.
76 PERFORM C040-WRITE-DETAIL-LINE.
77 PERFORM C060-READ-EMPLOYEE-MASTER.
78 *
79 C040-WRITE-DETAIL-LINE.
80 *
81 WRITE EMPLOYEE-ADDRESS-PRINT-LINE
82 AFTER ADVANCING W005-LINE-SKIP LINES.
83 *
84 C060-READ-EMPLOYEE-MASTER.
85 *
86 READ EMPLOYEE-ADDRESS-MASTER
87 AT END, MOVE "1" TO W005-END-OF-FILE-SWITCH.
PAGE 42
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
CODING THE IDENTIFICATION AND ENVIRONMENT DIVISIONS
INTRODUCTION
In the past chapters, we have discussed enough basic
features of COBOL for the reader to code simple
programs. In the previous chapter, we mentioned the
concept of "structured programming" to write programs
that are easy to read and therefore maintain. From now
on, we will broaden this concept to include specific
techniques that are useful in the four COBOL divisions.
This extends the concept beyond the original idea of
structured programming, which was mainly for easy-to-
read code in the PROCEDURE DIVISION.
PAGE 43
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
THE IDENTIFICATION DIVISION
This division identifies the program, and as options may
identify it author, it's purpose, and other
characteristics like when it was written, ect. Besides
the division header "IDENTIFICATION DIVISION." which is
coded starting in column 8, there is only one other
required entry for the division and this is the
"PROGRAM-ID." entry which is also coded starting in
column 8. The operand must be 8 characters or less and
start with an alphabetic character.
The periods after "IDENTIFICATION DIVISION." are
manditory, as well as the "PROGRAM-ID.".
DATE-WRITTEN.
SOURCE-COMPUTER.
OBJECT-COMPUTER.
AUTHOR.
SECURITY.
are not manditory but maybe added for arcival purposes.
THE ENIVRONMENT DIVISION
This division, which starts with the division header
"ENVIRONMENT DIVISION." coded starting in column 8,
contains the entries that relate your program to the
physical characteristics of the hardware to be used.
While COBOL is to a large extent machine-independent,
this division is needed to specify things like file
organization, device type, and others which are to some
extent machine-dependent.
CONFIGURATION SECTION
This division contains two opional sections,
"CONFIGURATION SECTION." and "INPUT-OUTPUT SECTION."
which are coded in column 8 and must be in that order if
both are present, There are 2 paragraphs in the
"CONFIGURATION SECTION.". The "SOURCE-COMPUTER."
paragraph is used in debugging and will be explained
later on. The "SPECIAL-NAMES." paragraph has severial
entries, one of which is the "PRINTER IS" entry which is
coded in column 12 and is used with displaying of
information on the printer.
PAGE 44
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
INPUT-OUTPUT SECTION
The "INPUT-OUTPUT SECTION." contains the "FILE-CONTROL."
paragraph, which is coded in column 8, and which is
required if the program uses files. There will be
entries under this paragraph, one for each file used.
Each entry is a SELECT statement that starts in column
12, and may be continued on the next line, and ends with
a period. The format for the SELECT statement is:
SELECT data-file-name ASSIGN TO DISK|PRINTER
FILE STATUS IS data-name
ACCESS MODE IS SEQUENTIAL|RANDOM|DYNAMIC
ORGANIZATION IS SEQUENTIAL|LINE
SEQUENTIAL|RELATIVE|INDEXED
RECORD KEY IS data-name-2
RELATIVE KEY IS data-name-3
The following rules apply:
1. Use filenames that are self-documenting. In the
example I use EMPLOYEE-ADDRESS-MASTER and EMPLOYEE-
ADDRESS-PRINT as file names.
2. Use DISK if it is a disk file and PRINTER if it is
the printer.
3. The FILE STATUS clause is used for disk files with
relative or indexed file organization, data-name is a
two-character data item that contains the value set
after every I-O statement. The returned values are:
FILE STATUS value MEANING
______________________________________________
00 SUCCESSFUL COMPLETION
10 END OF FILE
21 KEY NOT IN SEQUENCE(INDEXED)
22 DUPLICATE KEY ON WRITE
23 NO RECORD FOUND
24 DISK FULL
30 HARDWARE ERROR (DISK NOT READY ECT.)
91 FILE STRUCTURED DESTROYED
PAGE 45
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
CHAPTER 7
CODING THE DATA DIVISION
Introduction
The data division is where data used in the program
except for literals used in statements are defined.
The data maybe coming from a file will be written to
a file or used in intermediate processing. It is
important that certain techniques be used so that the
data names can be easily located and read from the
program listing and thus facilitate program
debugging. It is also important that we select the
proper data format so as to help make the program
more efficient.
PAGE 46
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Sections
This division starts with the division header "DATA
DIVISION" that is coded starting in column 8. There
are 4 optional sections that maybe defined all of
which start with a section header that is coded
starting in column 8. These sections are "FILE
SECTION", "WORKING-STORAGE SECTION", "LINKAGE
SECTION", "SCREEN SECTION" and must appear in that
order if defined.
FILE SECTION
This section starts with header "FILE SECTION" and
contains one entry for each file defined in the
select statement in the file control paragraph of the
ENVIRONMENT DIVISION. The file description entry has
the following format.
FD file name
LABEL RECORD | RECORDS IS | ARE OMITTED | STANDARD
VALUE OF FILE ID IS data name.
The following rules apply:
1) the 2 clauses LABEL RECORDS AND VALUE OF can be in
any order.
2) the FD "file description" literal is coded in
column 8, but file name in clauses are coded
starting in column 12.
3) all file names defined by select statements must
have a corresponding FD entry and the spelling of
the file name is naturally identical for both
entries.
4) the LABEL RECORDS must be specified as standard
for disc files and omitted for printer.
5) the value of file ID clause must be specified for
disc files and omitted for printer. It is used by
DOS for locating the file during the computer run
and is therefore defined according to the rules
for file names for DOSS. It has the format
DRIVE:FILE NAME.EXTENSION.
FILE RECORD ENTRIES
The format for records in each file is coded right after
the corresponding FD entry. Each record is defined with
an O1 Level with the level number starting in column 8.
The data name itself starts in column 12. This record
maybe further subdivided into lower level data items or
fields.
PAGE 47
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Data Item Definition
The data items coded in various sections of this
division except for those of screen formatting use
similar formats. The format is:
level # data-name REDEFINES data name.
level # data-name PICTURE | PIC IS picture type
OCCURS integer TIMES
INDEX BY index-name
USAGE IS usage-type
VALUE IS literal.
The following rules apply:
1) The level # is 01 if we are defining a record. A
record here means that either a file record entry at
the file section, a group of data names at the
working storage section or the linkage section or the
format of the whole screen in the screen section.
2) The level # for entries under the 01 range from 02-
49. However it is best to use numbered steps like
05,10,15, etc. so any further changes later on maybe
easily made by using numbers in between.
3) The level number for a condition name entry is 88.
This entry can only have a data name in the value
clause.
4) I suggest that you do not use level 77 which are
independent from other data items. It is better to
code data names which are used together as groups so
they are easily seen together in the program listing.
This is also used full when you write COBOL for
mainframes because of paging problems in virtual
storage systems.
5) Data name should be defined so that the reader
immediately notices what the data represents just
from it's name. An example is EMPLOYEE-ADDRESS-
MASTER.
6) The redefines clause specifies that the area occupied
by data-name-2 will also contain data-name-1. It is
often used to provide alternate grouping or
description of the same data item. If coded it
should be the first clause following data-name-1 and
data-name-2 is a data item coded just ahead of it.
7) Pic or picture specifies the format of the data item
and should be coded only for elementary data items.
The different picture types are the following:
a) Alphanumeric. This applies to a data item which
may contain alphabet and numeric characters and
therefore not used in arithmetic operations.
Picture type is specified with Xs. A number
enclosed in parenthesis means a repeat of one
occurence of an X. For instance, picXXXXX is
identical to picX[5].
b) Numeric. This field contains only numbers and is
usefful for fields in arithmetic operations. This
is defined with an S. If there is a sign 9 is
PAGE 48
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
used for digits and V for the assumed position of
the decimal point. This data item has the usage
display oprand as a default or must have the comp-
0 "binary" or comp-3 "packed decimal" specified.
c) Editing. This field is used for editing numeric
fields in preparation for printing them the
reports.
d) Try to code pic or picture somewhere in column 44
or 48 or even further to a line off picture
specification for easy reading. You will
generally have enough space on the left for the
data items and on the right for the other clauses.
e) In this section, file section, the value clause is
only used for condition names and not data names.
f) Code line seperators as in other divisions.
-------------------------------------------------------------------------------
WORKING STORAGE SECTION
This section contains data that are mainly used for
intermediate processing such as counters, tables, etc.
This data are generally not directly related to records
and files. The file record entries under FDs except
where we use the into option of verb or from option of
the write or rewrite verbs. Coding techniques for this
section is basically identical to those of the file
section except the following:
1) The 01 level group item does not correspond to any
record and therefore the programmer may group data
items under it in any way he chooses. He should,
however, try to group data together that are related.
2) The value clause maybe used in this section.
LINKAGE SECTION
This section is used if the program is being called by
another program. It will contain description of data
items that the called program needs and has the
correspondence to certain data items defined in the
working storage section of the calling program. This
section will actually not have memory allocated for it,
but will just use the memory allocated to the
corresponding files in the calling program. Just like
the data items in the file section the value clause
maybe specified only for condition names.
SCREEN SECTION
This section defines format of the screen to be used in
the program for displaying formatted data. Display or
exhibit verbs or accepting formatted data except verbs.
PAGE 49
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
CODING THE PROCEDURE DIVISION
Introduction
This division contains specific instructions that the
programmer wants executed and thus carries logic of the
program. It is the division that can benefit most from
good programming techniques and it contributes most to
the rehability and efficiency of the program.
PAGE 50
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Structure Programming
This is a technique that grew out of research begun in
the academic community some 30 or 40 years ago. It's
main aim was to make programs easier to read and thus
understand by having the programmer code them in a
certain style. One of it's main ideas is to avoid any
GO TO statements since they made the larger quota to
follow. The unconditional branch caused by each GO TO
disrupts the normal flow of control from a statement to
the one following it. Some proponents of structure
programmings have expand and redefined this idea to
include many other techniques. They have not eliminated
GO TOs all together, but just restrict their use to
certain conditions.
Program Constructs
Structured programming requires statements follow the
rule of one entry and one exit. Constructs which
consists of one or more statements must acquire control
starting execution at only one point in a relinquished
control stop execution at only one point. Reading the
program listing is thus made easier since we know that a
construct will eventually exit at one point. Any branch
outside of the construct will only be temporary done
through performed verbs. From this we can conclude that
GO TOs are to be avoided. GO TOs are supported although
in version 6.50. Examples of this are MOVE, DISPLAY,
EXHIBIT, etc. Statements which we simply execute before
proceeding in the next statement. Let's look at the
following set of statements. MOVE "ERA 5" TO MESSAGE
005-MESSAGE-CODE. EXHIBIT NAMED W005-MESSAGE-CODE.
DISPLAY "TEST 01 RUN ABORTED". You will note that each
statement is simply executed and control flows right
through to the next statement.
The IF Condition
We must understand that statements under the true or
false boxes could be a combination of valid constructs.
The important thing is always is to have one entry point
and one exit thus nested IFs something that may seem
tricky to use are very powerful to the structure
programming. While confusing if done improperly they
are easy to understand if properly indented. Note that
the constructs start at the IF statement and ends with a
period. No matter what values of W005-TRANS-HOURS and
W01-HOURS-LIMIT are. Control will eventually reach the
statement following the construct. Perform until
constructs. The construct governed by the false
condition the performed body will be executed repeatedly
until condition becomes true. At which time the
apparent original construct exists. When the constructs
in the performed body must eventually set the condition
true to enable use to exit from the apparent construct
PAGE 51
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
otherwise we have it endlessly.
Note that the paragraph C200-0-OUT-CELLS will be
executed repeatedly until the value of W05CELLS I is
greater than the value of total stores. The sentence
statement will cause this to happen at some point in the
construct exits.
Modular Programming
One of the developments in structure programming was the
idea of modularizing the program by coding into it's
sections. This idea is extensively used to COBOL
programs written for mainframes where the use of
advanced features like Sort require it. It is also
useful and is used in COBOL 6.50. It is mandatory if
the program is too large for computer memory requiring
it to be segmented. Secondly you may some day want to
write COBOl programs for mainframes or port the programs
that you have already written over to mainframes and you
would need to know how these sections are used.
The Main Line Section
The programs start to execute at the first verb of the
PROCEDURE DIVISION excluding statements and the
declarative section. It is therefore a good idea to
control the program logic in this area. It is also the
first part of the program a programmer would look at.
The most common name for this section is C000-MAIN-LINE.
C00 is a prefix which will be described later on. The
first paragraph of this section as a minimum does the
following:
1) Performs initialization section if any. This section
will execute the initial routines like read and
attail, accept the date used in processing, etc.
2) Open the files to be used in the section.
3) Perform the initial read of the input files.
4) Perform the paragraph that processes the input files
until the end of file perform until.
5) Performs the finalization section if any. This
section executes a final housekeeping routines like
print control, etc.
6) Close files using the section.
7) Issues a stop run statement.
Other Sections
Sections invogued by the mainline section to the perform
statements are coded in the following matter:
1) The first paragraph the section controls through the
perform statement the processing of the whole
section. It therefore does the following:
a) opens all files to be processed in the section.
b) performs initial read of the input files.
PAGE 52
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
c) performs a paragraph that processes the files
until all records have been processed.
d) closes all files processed in thesection.
e) exit section.
Paragraphs
Paragraphs that fall under the section are coded as they
are needed. Each one should only do one function so as
to keep it as simple and as easy to read as possible.
If the paragraph you are currently coding does too many
different functions than you should break it up into
several paragraphs. Seperate all paragraphs from each
other. In front of section headers, space and a line
seperator between them.
Prefixes for Procedure Names
In much the same manner that the prefixes for data names
make it easier to pinpoint their location in the program
listing section and paragraph name should also have
prefixes. This task just is to have the prefix
consisting of a letter followed by 3 digit number
followed by hyphen. You can easily use the letter C for
the first section, F for the second, J for the third,
etc. However you prefer to do it. And have enough
letters in between for future modifications. The digits
start with 000 for the section header and incremented by
20 for the paragraphs. This should give you enough
numbers for the paragraphs in the section. Otherwise
makes succeeding paragraphs have 4 digit numbers in the
prefix.
Self Documented Procedure Names
Just like data names it is important that the procedures
names be self documenting. You are allowed 30
characters for this procedure names and this is
generally enough to allow the user to understand the
function of the procedure from the name. A paragraph
name like C200-COMPUTE-GLOSSARY-PAY is much better than
C200-COMPUTE.
PAGE 53
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Statements and Sentences
The logic in the PROCEDURE DIVISION is coded with
statements each one being sentactically correct
combination of words and symbols thus specifies an
action to be done, ADD, MULTIPLY, MOVE, etc. or a
condition to be tested, IF. One or more statements that
terminates with a period is called a sentence. The
following are suggested in coding statements and
sentences:
1) there should only be one statement per line.
2) always start each sentence in column 12.
3) if the statement has to be continued in another line
indent the continuation line relative to the start of
the sentence.
4) if a statement is independent of other statements
make it into a sentence ending it with a period.
5) If a statement has several optional clauses code them
in succeeding lines instead of the same line so they
standout better. They should also be indented
relative to the start of the statement.
6) if you use IFs if subordinate to other IFs than aline
the Ls to the corresponding IF for readability.
PAGE 54
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
CHAPTER 9
Screen Processing Format Accept 3
Introduction
One feature of personal computers is of any display unit
which is extensively used to accept data entered by or
displayed for the operator. Unlike typical COBOL
programs written for mainframes where the datas are
generally batched together by the data entry department
unless a teleprocessing package like CICS is used the
ANSI-STANDARD COBOL 6.50 allows use of format it's
grades for easily input and output of information. Much
like an online system the operator may enter data via
the keyboard and this maybe immediately used by the
program to add update retrieve for delete records and
files. We will deal here with the screen processing
based on the format 3 version of the accept verb. This
allows the processing of individual fields as they are
entered in the keyboard. Format 4 processing which is
actually simpler to code will be discussed later on.
PAGE 55
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
Screen Format
We will deal only with the IBM Monochrome Display Unit
which is 24 by 80 columns for information. While there
is a total of 1980 characters that maybe entered the
program generally uses only a portion of this capacity
in applications.
Screen Header or Title
A typical screen used will have 3 areas defined. The
top one are 2 lines will be the header or title and has
literal value that will be indicated to the operator
what he or she is using. Typically headers would be
"ACCOUNTS RECEIVABLE ENTRY or PAYROLL ENTRY", something to
tell the operator what he is looking at. The header must
naturally be self defining and is usually defined with
the highlight oprand so it can be easily read.
Application Data Area
The main portion of the screen is where the application
data which contains the information entered by the
operator which comes from files. This consists of 2
types of data. One is field identifiers which are used
to identify the fields on the screen. This has literal
value that will indicate to the operator what he or she
is looking at. The field identifier is generally coded
just above the data it defines or to it's left in which
case it generally ends with a semicolon. Some typical
field identifiers have values like "NAME:" to identify
the name field, "DEPT:" for a department number. This
field is generally specified with the HIGHLIGHT operand
so it can be easily seen on the screen. The data itself
is the information that is important to the operator and
is usually defined with the REVERSE-VIDEO operand so it
is easily differentiated from its field identifier.
Some programmers may prefer to define this with the
HIGHLIGHT operand instead of the REVERSE-VIDEO operand.
In this case, make sure that the identifier does no have
the HIGHLIGHT operand so the two can be differentiated.
THE OPERATOR MESSAGE AREA
The operator message area is generally coded at the
bottom of the screen and contains the literal that is
displayed for the operator. If this message corresponds
to an error, the programmer should define the field with
both the HIGHLIGHT and BLINK operands so it is easily
seen by the operator. If this message guides the
operator, then it should be defined with either REVERSE-
VIDEO (prefered) or HIGHLIGHT operand.
PAGE 56
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
THE SCREEN SECTION.
While the programmer is able to display or accept
information on the screen without formatting, this has
limited capabilities because only the formatted screen
as defined in the SCREEN SECTION of the DATA DIVISION
will allow the programmer to use aids such as HIGHLIGHT,
REVERSE-VIDEO, FOREGROUND-COLOR, ect. This is almost
mandatory for typical applications since they require
the entry of several different types of data where a
formatted screen is needed. The following is
'suggested' rules for coding the SCREEN SECTION:
1). The whole screen corresponds to a 01-level screen-name.
2). The fields on the screen are defined with level
02 to 49 just like those in the WORKING-STORAGE
SECTION.
3). Each elementary item is defined as follows:
a. The level number is specified in the same
manner as in the WORKING-STORAGE SECTION.
b. Screen-name is defined if we use the group
or elementary item in ACCEPT and DISPLAY
statements in the PROCEDURE DIVISION.
Therefore, data fields and operator messages
have their corresponding screen-names.
Headers and field identifiers do not
normally need screen-names.
c. BLANK SCREEN. Is always coded by itself as
the first entry after the 01-level entry.
This erases the previous screen before a new
screen is displayed.
d. All elementary items must have the LINE
NUMBER and COLUMN NUMBER operands. This
specifies the exact location on the screen
that the data-item will start.
e. The REVERSE-VIDEO operand is used for data
fields, and is the logical choice for non-
error initiated operator messages.
f. The HIGHLIGHT opernad is used for the screen
headers. It is the logical choice for field
identifiers if the data fields are defined
with the REVERSE-VIDEO operand. It is also
the second choice for operator messages that
are not error-initiated. The HIGHLIGHT and
BLINK operands together is the logical
choice for operator messages that are
displayed on errors.
g. The BLINK operand, as noted before, is used
in conjunction with the HIGHLIGHT operand
for error-initiated operator messages.
i. The FOREGROUND-COLOR operand sets the
foreground color, it should be coded on a
line by itself. It must have an integer or
integer constant to specify the color
choice.
0 - BLACK
PAGE 57
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
1 - LOW-LEVEL BLUE
2 - LOW-LEVEL GREEN
3 - LOW-LEVEL LIGHT BLUE
4 - LOW-LEVEL RED
5 - LOW-LEVEL MAGENTA
6 - LOW-LEVEL BROWN
7 - LOW-LEVEL WHITE
8 - LOW-LEVEL GRAY
9 - HIGH-LEVEL BLUE
10 - HIGH-LEVEL GREEN
11 - HIGH-LEVEL LIGHT BLUE
12 - HIGH-LEVEL RED
13 - HIGH-LEVEL MAGENTA
14 - HIGH-LEVEL YELLOW
15 - HIGH-LEVEL WHITE
j. The BACKGROUND-COLOR operand is coded as the
FOREGROUND-COLOR operand with the exception
of only the 0 - 9 colors.
k. The "VALUE IS literal" operand is used for
headers and field identifiers or any field
that must contain an initial value when the
screen is displayed. Data fields generally
do not have this operand because the data
will be what is entered by the operator.
l. The "PIC IS picture string" operand is used
for data fields, the "FROM", "TO", and
"USING" operands in certain combinations.
m. For most applications, the "USING
identifier" is the most useful. This means
that the data item will receive the data
entered be the operator via the ACCEPT verb
and will also be the source of the data on
the DISPLAY verb.
n. The "FROM indentifier" operand will contain
data to be displayed on the screen through a
MOVE instruction. This operand functions
only in the DISPLAY mode.
o. The "TO indentifier" operand is used for
data entry fields. This operand functions
only with the ACCEPT verb.
THE DISPLAY VERB
In chapters 3 and 4, I explained the use of the DISPLAY
verb. I will now give a more detailed explanation,
especially on the aspect of the verb that displays data
on the formatted screens. the format is:
DISPLAY screen-name
Screen-name is the same as that defined in the SCREEN
SECTION. The location on the display where the data
items will show is defined in the LINE and COLUMN
operands of that item. If you wish you can write to the
screen location by using the DISPLAY verb. The format
is:
PAGE 58
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
DISPLAY ( ROW, COLUMN )
THE ACCEPT FORMAT 3
The format 3 version is:
ACCEPT ( position-spec ) identifier WITH AUTO-SKIP
The following rules apply:
1). Position-spec has the same value as in the DISPLAY verb.
2). Identifier is the field that will receive data.
3). The "WITH AUTO-SKIP" is useful for fixed-length
input fields. The input will automatically end
without the operator having to press the enter key,
when the length is reached, as defined by the PIC
operand.
4). The ACCEPT ends, which means we go to the next
following statement, if:
a. A terminator key is hit. These are ENTER, TAB,
BACK-TAB(shift + tab), ESCAPE, and the Function
Keys.
b. AUTO-SKIP is specified and the operator entered
a character in the low-order(rightmost) data
input position.
PROGRAM LISTING 9.01
--------------------
PROG901 COB 13:38:54 03-Sep-90 PAGE 1
Line Number Source Line ANSI 74-85 Standard Cobol V.6.50(c)1990.
1 IDENTIFICATION DIVISION.
2 *
3 PROGRAM-ID. PROG901.
4 * *
5 ***************************************************************
6 * *
7 * 1. DATE-WRITTEN. 08/03/90. *
8 * *
9 * 2. THIS PROGRAM ACCEPTS ENTRIES FROM THE CONSOLE DISPLAY *
10 * AND DISPLAYS THEM ON THE PRINTER. THE FIELDS ARE: *
11 * A) FIELD 1 - NAME *
12 * B) FIELD 2 - ADDRESS *
13 * C) FIELD 3 - CITY/STATE *
14 * *
15 ***************************************************************
16 *
17 *
18 ENVIRONMENT DIVISION.
19 *
20 CONFIGURATION SECTION.
21 *
22 SPECIAL-NAMES.
23 *
PAGE 59
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
24 PRINTER IS PRINTER-DISPLAY.
25 *
26 *
27 DATA DIVISION.
28 *
29 ***************************************************************
30 * *
31 WORKING-STORAGE SECTION.
32 * *
33 ***************************************************************
34 *
35 * USES OF W005-KEYBOARD-KEY-SWITCH
36 * ] . F9 KEY -- END OF JOB.
37 *
38 01 W005-KEYBOARD-KEY-SWITCH PIC 99.
39 88 W005-F9-KEY-ACTIVATED VALUE 10.
40 *
41 01 W005-RECORD-ACCEPTED-COUNT PIC 9(4) VALUE +0.
42 *
43 01 W010-EMPLOYEE-WK-RECORD.
44 05 W010-EMPLOYEE-WK-NAME PIC X(30).
45 05 W010-EMPLOYEE-WK-STREET PIC X(25).
46 05 W010-EMPLOYEE-WK-CITY PIC X(25).
PROG901 COB 13:38:54 03-Sep-90 PAGE 2
Line Number Source Line ANSI 74-85 Standard Cobol V.6.50(c)1990.
47 /
48 ***************************************************************
49 * *
50 SCREEN SECTION.
51 * *
52 ***************************************************************
53 *
54 *
55 01 SCREEN1-ADDRESS-ENTRY.
56 05 BLANK SCREEN.
57 05 LINE 1 COLUMN 16 VALUE "E M P L O Y E E"
58 HIGHLIGHT.
59 05 LINE 1 COLUMN 35 VALUE "A D D R E S S"
60 HIGHLIGHT.
61 05 LINE 1 COLUMN 52 VALUE "E N T R Y"
62 HIGHLIGHT.
63 05 LINE 3 COLUMN 24 HIGHLIGHT
64 VALUE "NAME:".
65 05 SCREEN1-NAME LINE 3 COLUMN 30
66 PIC X(30)
67 REVERSE-VIDEO
68 USING W010-EMPLOYEE-WK-NAME.
69 05 LINE 5 COLUMN 22 HIGHLIGHT
70 VALUE "STREET:".
71 05 SCREEN1-STREET LINE 5 COLUMN 30
72 PIC X(25)
73 REVERSE-VIDEO
74 USING W010-EMPLOYEE-WK-STREET.
75 05 LINE 7 COLUMN 18 HIGHLIGHT
PAGE 60
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
76 VALUE "CITY/STATE:".
77 05 SCREEN1-CITY LINE 7 COLUMN 30
78 PIC X(25)
79 REVERSE-VIDEO
80 USING W010-EMPLOYEE-WK-CITY.
PROG901 COB 13:38:54 03-Sep-90 PAGE 3
Line Number Source Line ANSI 74-85 Standard Cobol V.6.50(c)1990.
81 /
82 PROCEDURE DIVISION.
83 *
84 ***************************************************************
85 * *
86 C000-MAIN-LINE SECTION.
87 * *
88 ***************************************************************
89 *
90 C020-MAIN-LINE-LOGIC.
91 MOVE 98 TO W005-KEYBOARD-KEY-SWITCH.
92 PERFORM C120-DISPLAY-NEW-SCREEN.
93 PERFORM C040-PROCESS-NAME-ENTRY
94 THRU C100-PROCESS-SCREEN-EXIT
95 UNTIL W005-F9-KEY-ACTIVATED.
96 PERFORM C980-EOJ-ROUTINE.
97 STOP RUN.
98 *
99 C040-PROCESS-NAME-ENTRY.
100 ACCEPT ( 3, 30 )
101 W010-EMPLOYEE-WK-NAME.
102 ACCEPT W005-KEYBOARD-KEY-SWITCH FROM ESCAPE KEY.
103 IF W005-F9-KEY-ACTIVATED
104 GO TO C100-PROCESS-SCREEN-EXIT.
105 *
106 C060-PROCESS-STREET-ENTRY.
107 ACCEPT ( 5, 30 )
108 W010-EMPLOYEE-WK-STREET.
109 ACCEPT W005-KEYBOARD-KEY-SWITCH FROM ESCAPE KEY.
110 IF W005-F9-KEY-ACTIVATED
111 GO TO C100-PROCESS-SCREEN-EXIT.
112 *
113 C080-PROCESS-CITY-ENTRY.
114 ACCEPT ( 7, 30 )
115 W010-EMPLOYEE-WK-CITY.
116 ACCEPT W005-KEYBOARD-KEY-SWITCH FROM ESCAPE KEY.
117 IF W005-F9-KEY-ACTIVATED
118 GO TO C100-PROCESS-SCREEN-EXIT.
119 EXHIBIT NAMED W010-EMPLOYEE-WK-NAME UPON PRINTER-DISPLAY.
120 EXHIBIT NAMED W010-EMPLOYEE-WK-STREET UPON PRINTER-DISPLAY.
121 EXHIBIT NAMED W010-EMPLOYEE-WK-CITY UPON PRINTER-DISPLAY.
122 ADD 1 TO W005-RECORD-ACCEPTED-COUNT.
123 PERFORM C120-DISPLAY-NEW-SCREEN.
124 C100-PROCESS-SCREEN-EXIT. EXIT.
125 *
126 C120-DISPLAY-NEW-SCREEN.
127 MOVE SPACES TO W010-EMPLOYEE-WK-NAME
PAGE 61
ANSI-COBOL 6.50
USERS MANUAL
COPYWRITE 1990
128 W010-EMPLOYEE-WK-STREET
129 W010-EMPLOYEE-WK-CITY.
130 DISPLAY SCREEN1-ADDRESS-ENTRY.
PROG901 COB 13:38:54 03-Sep-90 PAGE 4
Line Number Source Line ANSI 74-85 Standard Cobol V.6.50(c)1990.
131 /
132 C980-EOJ-ROUTINE.
133 IF W005-RECORD-ACCEPTED-COUNT GREATER THAN ZEROS
134 DISPLAY "JOB PROG901: SUCCESSFUL ENTRY COMPLETED"
135 UPON PRINTER-DISPLAY
136 ELSE DISPLAY "JOB PROG901: UNSUCCESSFUL ENTRY"
137 UPON PRINTER-DISPLAY.
138 EXHIBIT NAMED W005-RECORD-ACCEPTED-COUNT
139 UPON PRINTER-DISPLAY.
PAGE 62