ch02_95(cha)

45
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology Edited By: Charmaine Salvador-Ponay (UST) for lecture purposes 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College  “Copyright @ 2000 John Wiley & Sons, In. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without the express permission of the copyright owner is unlawful. Request for further information should be addressed to the permissions Department , John Wily & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibi lity for errors, omissions, or damages, caused by the use of these programs or from the use of the information contained herein.”  

Upload: sean-patrick-altea

Post on 03-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 1/45

PowerPoint Presentation:Richard H. Baum, Ph.D.DeVry Institute of TechnologyEdited By: Charmaine Salvador-Ponay(UST) for lecture purposes

9th Edition

Structured COBOLProgramming

Nancy SternHofstra University

Robert A. Stern

Nassau CommunityCollege

“Copyright @ 2000 John Wiley & Sons, In. All rightsreserved. Reproduction or translation of this work

beyond that permitted in Section 117 of the 1976United States Copyright Act without the expresspermission of the copyright owner is unlawful.Request for further information should be addressedto the permissions Department , John Wily & Sons,Inc. The purchaser may make back-up copies forhis/her own use only and not for distribution orresale. The Publisher assumes no responsibility forerrors, omissions, or damages, caused by the use ofthese programs or from the use of the informationcontained herein.”

Page 2: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 2/45

Structured COBOL Programming, Stern &Stern, 9th edition

THE NATURE OF COBOL

COBOL is a Business-OrientedLanguageCOBOL, is one of the most widespreadcommercial applications languages in usetoday.COBOL is an abbreviation for CO mmonBusiness Oriented Language,

COBOL is a Standard LanguageCOBOL is a common programming languageavailable on most computers.

Page 3: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 3/45

Structured COBOL Programming, Stern &Stern, 9th edition

THE NATURE OF COBOL

COBOL is an English-like Language All instructions can be coded using English words.The rules conform to many rules for writing inEnglish

COBOL is a User-Friendly LanguageBecause users are able to understand theEnglish-like instructions it is considered a user-

friendly language.

Page 4: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 4/45

Structured COBOL Programming, Stern &Stern, 9th edition

A HISTORY OF COBOL AND THEANS VERSIONS

Page 5: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 5/45

Structured COBOL Programming, Stern &Stern, 9th edition

WHEN IT BEGAN

Developed in 1959 by the CODASYLCommittee.

A committee consisting of representativesmembers from academia, user groups, and

computer manufacturers.Developed as a standard business-orientedlanguage for which all major manufacturerswould provide compilers.

ANS established the first standards version in1968.

Page 6: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 6/45

Structured COBOL Programming, Stern &Stern, 9th Edition

CHAPTER 2Cobol LanguageFundamentals

Page 7: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 7/45

BASIC

STRUCTURE OF ACOBOL PROGRAM

Page 8: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 8/45

Structured COBOL Programming, Stern &Stern, 9th Edition

CODING RULESThe main body of the form is subdivided into 72

positions or columns.Column 7 of a COBOL program has threeprimary purposes:1. By coding an * (asterisk) in column 7, an entire

line can be designated as a comment.2. It can be used to force the printing of

subsequent instructions on the next page of thesource listing.

3. It can be used for the continuation of nonnumericliterals.

Page 9: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 9/45

Structured COBOL Programming, Stern &Stern, 9th Edition

CODING RULES: Areas A and BPositions 8--72 of a standard COBOL programcontain program statements:

Column 8 is labeled area AColumn 12 is labeled area B

Entries in Area A, may begin in position 8, 9,10, or 11.

Most often, Area A entries begin in position 8.

If an entry is to be coded in Area B, it maybegin anywhere after position 11.

Page 10: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 10/45

Structured COBOL Programming, Stern &Stern, 9th Edition

TYPES OF COBOL ENTRIES

Divisions, sections, and paragraphs beginin Area A. Examples include:DIVISIONSIDENTIFICATION DIVISION.ENVIRONMENT DIVISION.DATA DIVISION.PROCEDURE DIVISION .

SECTIONSFILE SECTION.WORKING-STORAGE SECTION.

Page 11: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 11/45

Structured COBOL Programming, Stern &Stern, 9th Edition

TYPES OF COBOL ENTRIES

Divisions, sections, and paragraphs beginin Area A. Examples include:PARAGRAPHS

PROGRAM-ID.200-CALC-RTN.

Statements and sentences begin in AreaB; for example:SELECT PAYROLL ASSIGN TO DISK.

ADD AMT-IN TO TOTAL.

Page 12: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 12/45

Structured COBOL Programming, Stern &Stern, 9th Edition

CODING REQUIREMENTS OF THEIDENTIFICATION DIVISION

Page 13: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 13/45

Structured COBOL Programming, Stern &Stern, 9th Edition

Paragraphs in theIDENTIFICATION DIVISION

IDENTIFICATION DIVISION.PROGRAM-ID. program-name.

[AUTHOR. [comment-entry] . . .][INSTALLATION. [comment-entry] . . .][DATE-WRITTEN. [comment-entry] . . .]

[DATE-COMPILED. [comment-entry] . . .][SECURITY. [comment-entry] . . .]

Page 14: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 14/45

QUESTIONS?

Page 15: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 15/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELF-TEST

1. If an entry must begin in Area A, it maybegin in position _____ ;

if an entry must begin in Area B, it may beginin position _____ .

Solution: 8, 9, 10, or 11; 12, 13, 14, and so on

Page 16: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 16/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELF-TEST

2. The four divisions of a COBOLprogram must appear in order as _____

; _____ ; _____ ; and, _____ .Solution: IDENTIFICATION;

ENVIRONMENT; DATA; PROCEDURE

Page 17: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 17/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELF-TEST

3. What entries must be codedbeginning in Area A?

Solution: Division, section, andparagraph-names

Page 18: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 18/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELF-TEST

4. Most entries such as PROCEDUREDIVISION instructions are coded in

Area _____ .

Solution: B

Page 19: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 19/45

Page 20: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 20/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELF-TEST

6. The first two entries of a COBOL programmust always be _____ and _____ .

Solution: IDENTIFICATION DIVISION.PROGRAM-ID. program-name.

Page 21: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 21/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELF-TEST

7. Each of the preceding entriesmust be followed by a _____ ,

which, in turn, must be followed by a ____ .

Solution: period; space or blank

Page 22: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 22/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELF-TEST

8. The first two entries of a program areboth coded beginning in Area _____ .

Solution: A

Page 23: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 23/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELF-TEST

9. Code the IDENTIFICATION DIVISION for aprogram called EXPENSES for a corporation,Dynamic Data Devices, Inc., written July 15,1997. This program has a securityclassification and is available to authorizedpersonnel only. It produces a weekly listing

by department of all operating expenses.

Page 24: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 24/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELF-TEST9. Suggested solution:

IDENTIFICATION DIVISION.PROGRAM-ID. EXPENSES.

AUTHOR. N. B. STERN.

INSTALLATION. DYNAMIC DATA DEVICES, INC.DATE-WRITTEN. 7/15/97.DATE-COMPILED.SECURITY. AUTHORIZED PERSONNEL ONLY.

Page 25: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 25/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELF-TEST

10. The DATE-COMPILED paragraph usuallydoes not include a comment entry because

_____ .

Solution: the computer itself can supply thedate of the compilation (The current date isstored in main memory.)

Page 26: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 26/45

Structured COBOL Programming, Stern &Stern, 9th Edition

THE SECTIONS OF THEENVIRONMENT DIVISION

The ENVIRONMENT DIVISION is the onlymachine-dependent division of a COBOLprogram.

Entries in this division will depend upon:(1) the computer system and(2) the specific devices or hardware used in theprogram.*

*Interactive programs that use keyed data as input anddisplay screen output will not need this division.

Page 27: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 27/45

Structured COBOL Programming, Stern &Stern, 9th Edition

THE CONFIGURATION SECTIONSupplies information about the computer on which

the COBOL program will be compiled and executed.SOURCE-COMPUTER:

The computer that will be used for compiling theprogram.

OBJECT-COMPUTER:- The computer that will be used for executing or

running the program.* SOURCE- COMPUTER and OBJECT-COMPUTER are

coded primarily as documentation entries.

Page 28: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 28/45

Page 29: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 29/45

Structured COBOL Programming, Stern &Stern, 9th Edition

CONFIGURATION SECTIONEXAMPLE

ENVIRONMENT DIVISION.CONFIGURATION SECTION.

SOURCE-COMPUTER. IBM AS400.OBJECT-COMPUTER. DEC ALPHA.

Page 30: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 30/45

Structured COBOL Programming, Stern &Stern, 9th Edition

INPUT-OUTPUT SECTION

The INPUT-OUTPUT SECTION optionallyfollows the CONFIGURATION SECTION

It supplies information concerning the input and

output devices used in the program by means of aFILE-CONTROL paragraph.

In the FILE-CONTROL paragraph, a file-nameis designated and assigned to a device foreach file used in the program.

Page 31: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 31/45

Structured COBOL Programming, Stern &Stern, 9th Edition

INPUT-OUTPUT SECTION

The FILE-CONTROL paragraph consistsof SELECT statementseach is coded in Area B followed by a period.

A SELECT statement defines a file-name. assigns a device name to that file*.

A file is the major collection of data for a givenapplication.

Page 32: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 32/45

Structured COBOL Programming, Stern &Stern, 9th Edition

INPUT-OUTPUT SECTION

Batch processing applications have aninput file and an output file.Interactive processing allows input usinga keyboard;

therefore, it is not necessary to establish aninput file.

Page 33: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 33/45

Structured COBOL Programming, Stern &Stern, 9th Edition

INPUT-OUTPUT SECTION

If the output is printed or saved on disk, anoutput file must exist in the ENVIRONMENTDIVISION.

If the output is displayed on a screen, then nofile declaration is necessary in theENVIRONMENT DIVISION.- When this is the case, the ENVIRONMENT

DIVISION may be entirely omitted.

Page 34: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 34/45

ASSIGNING FILESTO DEVICES IN THE

ENVIRONMENTDIVISION

Page 35: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 35/45

Structured COBOL Programming, Stern &Stern, 9th Edition

OVERALL FORMAT

The instruction format for the SELECT statementfollows:

SELECT file-name-1

ASSIGN TO implementor-name-1[ORGANIZATION IS LINE SEQUENTIAL]

The implementor-name is a machine-dependent

device specification that is typically provided by thecomputer center.

Page 36: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 36/45

Structured COBOL Programming, Stern &Stern, 9th Edition

OVERALL FORMAT

File-Name Rules1. The file-name assigned to each device must

conform to the rules for forming user-definedwords.

2. A user-defined word is a word chosen by theprogrammer to represent some element in aprogram such as a file-name:

Page 37: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 37/45

Structured COBOL Programming, Stern &Stern, 9th Edition

OVERALL FORMATRules for Forming User-Defined Words (Suchas File-Names)1. 1 to 30 characters.2. Letters, digits, and hyphens (-) only.3. No embedded blanks

It is best to use hyphens to separate words (e.g.,EMPLOYEE-NAME)

4. At least one alphabetic character.

Page 38: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 38/45

Structured COBOL Programming, Stern &Stern, 9th Edition

OVERALL FORMAT

5. May not begin or end with a hyphen.6. No COBOL reserved words such asDATA, DIVISION, etc.

A full list of reserved words appears in Appendix Aand in the COBOL Syntax Reference Guide.

Page 39: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 39/45

Structured COBOL Programming, Stern &Stern, 9th Edition

OVERALL FORMAT

A SELECT statement must be specified foreach file in the program,. If a program requires a disk file as input and

produces a printed report as an output file, twoSELECT statements will be specified.

one file-name will be assigned to the disk file

the other to the print file.

Page 40: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 40/45

Structured COBOL Programming, Stern &Stern, 9th Edition

DEBUGGING TIP

File names assigned by theprogrammer should be meaningful.

Examples: SALES-INSALES-REPORT-OUT

OVERALL FORMAT

Page 41: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 41/45

Structured COBOL Programming, Stern &Stern, 9th Edition

OVERALL FORMATImplementor-Names or

Device SpecificationsMost systems enable the programmer toaccess frequently used devices by special

device names.

OVERALL FORMAT

Page 42: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 42/45

Structured COBOL Programming, Stern &Stern, 9th Edition

OVERALL FORMATImplementor-Names or

Device SpecificationsThe following are common shorthand device

specifications that you may be able to use withyour system:Printer SYSLST or SYS$OUT or

PRINTER

Disk DISC or DISK followed by adisk file-name

Page 43: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 43/45

Structured COBOL Programming, Stern &Stern, 9th Edition

SELECT Statements for PCs

1. Device SpecificationFor input or output files on disk, PC versionsof COBOL use device names that specify:(1) The drive on which the disk file appears followed

by a colon (e.g., C:, D:, etc.). If your file is in a subdirectory, you must specify thatas well (e.g., C:\COBOL).

Page 44: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 44/45

Page 45: ch02_95(cha)

8/12/2019 ch02_95(cha)

http://slidepdf.com/reader/full/ch0295cha 45/45

Structured COBOL Programming, Stern &

SELECT Statements For PCs

PC Disk files are most often created so thatthey resemble text files.This is done by using a SELECT statement

followed by:

ORGANIZATION IS LINE SEQUENTIAL.Example:SELECT SALES-FILE ASSIGN TO 'C:\SALES.DAT'

ORGANIZATION IS LINE SEQUENTIAL.