Вы находитесь на странице: 1из 53

Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL

Structured COBOL Programming, Stern & Stern, 9th edition

CHAPTER 1 OBJECTIVES
To familiarize you with:

1. The reasons for COBOLs popularity as a business-oriented language. 2. Some general programming practices and techniques. 3. A history of COBOLs evolution and its current ANS version. 4. An overview of how a COBOL program is structure.
Structured COBOL Programming, Stern & Stern, 9th edition

Types of Computer Programs


A program is a set of instructions that enable a

computer to process data. Software is the term used to describe all types of programs. An application program converts input data to output information.

Structured COBOL Programming, Stern & Stern, 9th edition

IPO Chart / System Flowchart


Identifies the inputs and outputs of the program. Basic IPO model.

EMPLOYEE FILE

PRINT PAYROL DATA

PAYROLL REPORT

Structured COBOL Programming, Stern & Stern, 9th edition

Two types of computer programs:


1. Operating Systems Programs
2. Applications Programs
Control the overall operations of the computer

Written by Programmers or Software Developers Programs that perform tasks required by users A set of programs that fulfill a business requirement is an Information System
Structured COBOL Programming, Stern & Stern, 9th edition

Applications Programs

Interactive vs. Batch Processing


Interactive applications typically accept input data

from a PC, workstation, or terminal. Batch Processing applications process large volumes of input at periodic intervals.
Daily Weekly Monthly etc.

Structured COBOL Programming, Stern & Stern, 9th edition

Applications Programs
Applications programs that are written for a

specific user are called customized programs. Programs that are relatively standard are application packages that might be purchased.
Off The Shelf (OTS) may be less costly depending on the amount of customization needed

Structured COBOL Programming, Stern & Stern, 9th edition

Machine Language Programs


All programs executed by the computer must be

in machine language the only language a computer understands


Binary 10110101 Must know memory address of variables etc.

Structured COBOL Programming, Stern & Stern, 9th edition

Symbolic Programs
Symbolic Programs

use English-like or symbolic instructions.


These programs must be translated or compiled into machine language.
Symbols (Variable/Data names) represent memory addresses

COBOL is a symbolic programming language used for commercial applications. As is C++, Visual Basic etc.
A compiler coverts symbolic language into

machine code

Structured COBOL Programming, Stern & Stern, 9th edition

Program Development Process


1.
2. 3. 4. 5.

6.

Determine Program Specifications Design Program Using Program Planning Tools Code and Enter Program Compile Program Test Program Document Program
Structured COBOL Programming, Stern & Stern, 9th edition

PROGRAM DEVELOPMENT PROCESS


1. Determine Program Specifications
Program Specifications consist of the following:
Record layout forms to describe the input and output (pg 6) Printer spacing charts for printed output (pg 7) Any special rules for processing
Structured COBOL Programming, Stern & Stern, 9th edition

I/O Specifications
The I/O specifications establish record names, field names, data sizes and types to be used in your program. For auxiliary storage specifications can take the form of an 01 level print out or a simply chart as follows.
Used in developing the Data Division. Payroll-Record

Type
Name Address Pay-Rate Alphanumeric Alphanumeric Numeric

Size
30 23 5.2 or 7 with 2 decimals

Etc.

Structured COBOL Programming, Stern & Stern, 9th edition

PROGRAM DEVELOPMENT PROCESS


2.

Design the Program Using Program Planning Tools using Common Tools:
Hierarchy Charts
Charts showing relationships among sections in a program A block diagram providing a pictorial representation of the logic to be used in a program English-like expressions to depict the logic of the program
Structured COBOL Programming, Stern & Stern, 9th edition

Flowcharts
Pseudocode

HIERARCHY CHART
100-CALCULATE-VEHICLE-REGISTRATION-FEES
200-INITIALIZE 210-PROCESS-RECORDS

300-GET-DATE

900-PRINT-HEADERS

310-FIND-RATE

320-PRINT-DETAILS

The first phase of problem solving is to use a top down design. Begin with a very general problem statement and break it down into smaller and smaller pieces until you know you have pieces you can solve. The hierarchy chart establishes the Paragraph names you will use in pseudo code and in your programs Procedure Division. It outlines a very general program flow and shows the relationship between modules/paragraphs. Answers the question WHAT needs to be done? Structured COBOL Programming, Stern & Stern, 9th edition

900-PRINT-HEADERS

REMEMBER
The sooner you start coding the longer it will take you to complete the project!!!!!

To Reduce Cost of Fixing Errors


Phase in which error is detected Requirements Design Relative cost of repair 0.1 0.2 0.5

Coding
Program testing Acceptance test Maintenance

1
2 5
Structured COBOL Programming, Stern & Stern, 9th edition

2X
4X 10X 40X

20

PROGRAM DEVELOPMENT PROCESS


3. Code and Enter the Program
The programmer writes and then keys or enters the source program into the computer system using a keyboard.

4. Compile the Program


The COBOL compiler checks the source code to insure there are no rule violations. A syntax error is a type of error that is found if a programming rule is violated.
Source program in symbolic language Translated by compiler Object program in machine language

Structured COBOL Programming, Stern & Stern, 9th edition

PROGRAM DEVELOPMENT PROCESS


5. Test the Program
Programs are tested or debugged to ensure they have no errors. Runtime errors
A logic error produces incorrect results An Operating System violation results in program termination

6. Document the Program


Procedure manuals for users and computer operators, called documentation, is prepared for use by the operating staff for regular production.
Structured COBOL Programming, Stern & Stern, 9th edition

PROGRAM DEVELOPMENT PROCESS


Remember, coding is undertaken only after the

program requirements have been fully specified and the logic has been carefully planned.

Structured COBOL Programming, Stern & Stern, 9th edition

DEBUGGING TECHNIQUES
Desk Checking

Reviewing the program before and after keying


Correcting Syntax Errors

Using the printed source list of the diagnostic messages to find and correct the errors

Structured COBOL Programming, Stern & Stern, 9th edition

DEBUGGING TECHNIQUES
Program Walkthroughs

Manually stepping through the program with test data.


Detecting Logic Errors by Executing the

Program
Often the most difficult part of debugging. The preparation of test data is an extremely critical aspect of debugging.
Structured COBOL Programming, Stern & Stern, 9th edition

THE NATURE OF COBOL


COBOL is a Business-Oriented Language COBOL, is one of the most widespread commercial applications languages in use today.
COBOL is an abbreviation for COmmon Business Oriented Language,

COBOL is a Standard Language COBOL is a common programming language available on most computers.
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 in English COBOL is a User-Friendly Language Because users are able to understand the English-like instructions it is considered a user-friendly language.

Structured COBOL Programming, Stern & Stern, 9th edition

WHEN IT BEGAN

Developed in 1959 by the CODASYL Committee.


A committee consisting of representatives members from academia, user groups, and computer manufacturers.

Developed as a standard business-oriented language for which all major manufacturers would provide compilers. ANS established the first standards version in 1968. COBOL 85 the current standard

http://www.ansi.org

2002+ Standard

Structured COBOL Programming, Stern & Stern, 9th edition

THE FUTURE OF COBOL


COBOL is likely to remain an important

language in the years ahead for two reasons:


1. Older, mainframe-based legacy systems will need to be maintained by maintenance programmers who know COBOL. 2. COBOL is still being used by many organizations for new application development.

Structured COBOL Programming, Stern & Stern, 9th edition

Use of COBOL
About 200 billion lines of COBOL source code in

use 5 billion new lines added each year Used by 42.7% of application programmers in medium to large U.S. companies $200 million in expected revenues for 2001

Structured COBOL Programming, Stern & Stern, 9th edition

Interactive vs Batch Programs


Cobol suited for developing both types of

programs

Interactive programs Accept input data from keyboard Input data processed immediately Output (results) displayed on screen immediately
Structured COBOL Programming, Stern & Stern, 9th edition

Interactive vs Batch Programs


Batch programs Process large volumes of input at periodic intervals Input data read in from files Output written to files

Structured COBOL Programming, Stern & Stern, 9th edition

TECHNIQUES FOR IMPROVING PROGRAM DESIGN

Structured COBOL Programming, Stern & Stern, 9th edition

Improving Program Design


Two techniques used to develop programs that are easier to understand, test, debug and modify
Structured Programming Top-Down Programming

Structured COBOL Programming, Stern & Stern, 9th edition

Structured Programming
Eliminates use of GO TO statements

Allowed skipping to different sections of program without returning to starting point


Program logic easier to follow with "GO-TO-less"

programming

Structured COBOL Programming, Stern & Stern, 9th edition

Structured Programming
Program divided into paragraphs Main paragraph or module controls logic flow using PERFORM statements Main module "performs" other modules when instructions in that module required Each module can be written and tested independently of others
Structured COBOL Programming, Stern & Stern, 9th edition

Top-Down Programming
Another technique to make programs easier to

understand, test, debug and modify Develop program like term paper
Develop outline first Add details for each of main steps Add further refinement for more complex steps

Structured COBOL Programming, Stern & Stern, 9th edition

Top-Down Programming
For COBOL program Code main modules or routines first Code intermediate modules next Details deferred to minor modules and coded last

Structured COBOL Programming, Stern & Stern, 9th edition

Program Specifications
System Flowchart
Input/Output Specifications Hierarchy Chart Psuedo code Narrative as comments in program

Structured COBOL Programming, Stern & Stern, 9th edition

System Flowchart
INPUT PROCESSING OUTPUT

Student-File

PRINT STUDENT ATTENDANCE

Attendance Report

Structured COBOL Programming, Stern & Stern, 9th edition

START

Program Flow Chart


PROCESS RECORDS

OPEN FILES

READ FIRST RECORD FALSE

WRITE HEADINGS

ENGINEERING MAJOR AND MORE THAN 110 CREDITS

TRUE

5
PROCESS RECORDS END OF FILE REACHED?

10 11

WRITE STUDENT NAME

12
CLOSE FILES

READ NEXT RECORD

STOP

STOP

(a) Overall Flowchart

Structured COBOL Programming, Stern & (b) Detail of PROCESS-RECORDS Stern, 9th edition

Pseudo Code
Open files Initialization Read first record Write heading DO while data remains IF engineering major with more than 110 credits Write students name ENDIF ENDDO Close files Termination Stop
Structured COBOL Programming, Stern & Stern, 9th edition

Processing

Hierarchy of Data
Bit - binary 0 or 1 Byte / Character - 8 bits Field - a basic fact about some entity

Customer - Current-Balance Inventory - Selling-Price

Record - a collection of related facts File - a collection of related records Database - an organizations set of files

Structured COBOL Programming, Stern & Stern, 9th edition

Fields
(Facts)
Name: Credits: Major: John Adams 90 Political Science

Records
(Set of Fields)
Jphn Adams 90 Political Science

Name: Credits: Major:

Amelia Earhart 120 Aviation

Amelia Earhart

120

Aviation

Name: Credits: Major:

Orville Wright 115 Engineering

Orville Wright

115

Engineering

Name: Credits: Major:

Georgia OKeeffe 125 Georgia OKeeffe 125 Art

Art

Structured Programming, Figure 1.1 Fields, Records, and Files COBOL9th edition Stern & Stern,

Programming Structures
Sequence
Selection Iteration/Repetition

Structured COBOL Programming, Stern & Stern, 9th edition

Structured Programming Using Modular Design for Coding Paragraphs


The most important technique for improving the

design of a program in any language is called structured programming. Structured Programming is a technique using logical control constructs that make programs easier to read, debug, and modify if changes are required.
Structured COBOL Programming, Stern & Stern, 9th edition

Modular Programming
Each module/paragraph must meet the following

characteristic
COMPLETENESS taken together the modules completely satisfy the program specifications COHESIVE a paragraph must perform one and only one task COUPLING paragraphs are loosely coupled that is a paragraph does not depend on other paragraphs
Structured COBOL Programming, Stern & Stern, 9th edition

Structured Programming Using Modular Design for Coding Paragraphs


Structured programming is often called GO-

TO-less programming since programmatic branches do not use GO TO statements. In COBOL this means writing programs using PERFORM statements

Structured COBOL Programming, Stern & Stern, 9th edition

Structured Programming Using Modular Design for Coding Paragraphs


The typical structured program is divided into

paragraphs or modules, where a main module calls in other modules as needed.


Each block on the hierarchy chart represents a paragraph Each module can be tested independently.
Paragraph, routine, module are used interchangeably

Structured COBOL Programming, Stern & Stern, 9th edition

The Top-Down Approach for Coding Modules


Proper design is best achieved by developing major modules before minor ones. Main routines are coded first and are followed by intermediate routines and then minor ones. Coding using the top-down manner gives the primary attention to the origination of the program. Details are deferred or saved for minor modules, which are coded last.

Incremental testing
Structured COBOL Programming, Stern & Stern, 9th edition

HIERARCHY OR STRUCTURE CHART


Structure charts illustrate the logic flow in a

program.
The following chart shows the relationships among modules in a program:
100-MAIN MODULE

200INITIALIZE
Structured COBOL Programming, Stern & Stern, 9th edition

210-WAGE ROUTINE

RULES FOR INTERPRETING PSEUDOCODE


1. 2.

Each block on the Hierarchy chart needs to be represented in pseudocode Paragraph names are prepared in numerical sequence
100-Main-Module 200-Initialize 210-Wage-Routine 220-Finalize-Program Etc

3.

The instructions between the:


PERFORM UNTIL NO MORE DATA executed repeatedly UNTIL there are no more records to process Structured COBOL Programming, Stern & END-PERFORM. Stern, 9th edition

Divisions of a Cobol Program

Identification Division
Identifies program to OS Provides documentation

Environment Division
Defines files Establishes Logical (program) and physical (computer) relationship

Data Division
Describes all input and output data As well as scratch pad data (working storage)

Procedure Division
All the program logic
Structured COBOL Programming, Stern & Stern, 9th edition

Figure 1.6

The First COBOL Program

Identification Division

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

IDENTIFICATION DIVISION. PROGRAM-ID. SENIOR. AUTHOR. ROBERT GRAUER.

Environment Division

ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STUDENT-FILE ASSIGN TO A:\CHAPTR02\SENIOR.DAT ORGANIZATION IS LINE SEQUENTIAL. SELECT PRINT-FILE ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD STUDENT-FILE RECORD CONTAINS 43 CHARACTERS DATA RECORD IS STUDENT-IN. 01 STUDENT-IN. 05 STU-NAME PIC X(25). 05 STU-CREDITS PIC 9(3). 05 STU-MAJOR PIC X(15). Structured COBOL Programming, Stern & Stern, 9th edition

Data Division

Figure 1.6

The First COBOL Program (continued)


Data Division

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

FD

01

PRINT-FILE RECORD CONTAINS 132 CHARACTERS DATA RECORD IS PRINT-LINE. PRINT-LINE PIC X(132).

WORKING-STORAGE SECTION. 01 DATA-REMAINS-SWITCH

PIC X(2)

VALUE SPACES.

01

HEADING-FILE. 05 FILLER 05 FILLER 05 FILLER


DETAIL-LINE. 05 FILLER 05 PRINT-NAME 05 FILLER

PIC X(10) PIC X(12) PIC X(110)

VALUE SPACES. VALUE STUDENT NAME. VALUE SPACES.

01

PIC X(8) PIC X(25). PIC X(99)

VALUE SPACES. VALUE SPACES.

Structured COBOL Programming, Stern & Stern, 9th edition

Figure 1.6
41

The First COBOL Program (continued)

42

43

PROCEDURE DIVISION. 42 100-PREPARE-SENIOR-REPORT. 43 OPEN INPUT STUDENT-FILE 44 OUTPUT PRINT-FILE Procedure Division 45 READ STUDENT-FILE 46 AT END MOVE NO TO DATA-REMAINS-SWITCH 47 END-READ 48 PERFORM 200-WRITE-HEADING-LINE 49 PERFORM 210-PROCESS-RECORDS 50 UNTIL DATA-REMAINS-SWITCH = NO 51 CLOSE STUDENT-FILE 52 PRINT-FILE 53 STOP RUN. 54 55 200-WRITE-HEADING-LINE. 56 MOVE HEADING-LINE TO PRINT-LINE 57 WRITE PRINT-LINE. 58 59 210-PROCESS-RECORDS. 60 IF STU-CREDITS > 110 AND STU-MAJOR = ENGINEERING 61 MOVE STU-NAME TO PRINT-NAME 62 MOVE DETAIL-LINE TO PRINT-LINE 63 WRITE PRINT-LINE 64 END-IF 65 READ STUDENT-FILE 66 AT END MOVE NO TO DATA-REMAINS-SWITCH Structured COBOL Programming, Stern & 67 END-READ. Stern, 9th edition

End

Вам также может понравиться