Ch01.1.Spring2006

advertisement
Structured COBOL Programming
10th edition
John Wiley & Sons, Inc.
Nancy Stern
Hofstra University
Robert A. Stern
Nassau Community College
James P. Ley
University of Wisconsin-Stout
PowerPoint
Presentation
Winifred J. Rex
Bowling Green State University
1
Chapter 1
An Introduction to
Structured Program Design
in COBOL
Please note that the original slides will be modified in a number
of places by your professor.
These changes are for pedagogical reasons.
2
Chapter Objectives
To familiarize you with
 Why COBOL is a popular business-oriented
language.
 Programming practices and techniques
 History of COBOL
 Use of the current ANSI standard versions of
COBOL
 Four divisions of a COBOL program
3
Chapter Contents







Computer Programming: An Overview
Applications Program Development Process
Nature of COBOL
History of COBOL and the ANS Versions
Techniques for Improving Program Design
Sample Programs
Entering and Running a COBOL Program on
Your Computer
4
Computer Program
 A set of instructions that enables computer to
process data
 Also called software
 Two types of computer programs

Operating system programs - control overall
operations of computer


Oftentimes called System Software
Applications programs - perform tasks required
by users

Often called Applications Software  Us.
5
Applications Programs
 Written by applications programmer
 May provide quick solution to one-time problem
 Displaying average grade for set of exam scores
 Or may be run on regularly scheduled basis
 Program to print student transcripts each
semester
 Program to generate a Payroll
 Program to generate and print an Inventory
Listing
6
Application Programs - Customized
 Written for specific users like doctors, car
dealerships
 Necessary if user has special requirements
7
Applications Package – General Usage
 Written for general user who needs program
to perform standard tasks
 Standard tasks include budgeting, scheduling
payroll, etc.
 Cheaper, easier than writing customized
program
8
Program Languages
Machine language
 Only language computer understands
 All programs executed on computer must be
in machine language
 Machine language programs difficult to write
 Written in binary, such as:


0001101001010100 (actual instruction)
010110101000000011000100 (actual
instruction in binary)
9
Assembler Languages
 Level ‘higher’ than Machine Language.
 Use mnemonic codes rather than pure binary
digits, such as:
L
AR
ST
R5,X
R5,R4
R5,SUM
 Each of these instructions translates
(normally one-to-one) into a machine
language statement (that is, binary…)
10
Program Languages
Symbolic language (like COBOL)
 Called Higher-Level Languages
 English-like languages used to write
programs
 Easier than writing programs in machine
language or assembly languages.
 Must be translated or compiled into machine
language to run on computer
11
Program Development Process
1. Determine Program Specifications – the
2.
3.
4.
5.
6.
“Whats”
Design Program Using Program Planning
Tools – the “Hows.”
Code and Enter Program (using some editor)
Compile Program
Implementation
Test Program
Document Program
12
1. Program Specifications
• Systems analysts, users and programmers develop
specifications
• Specifications include:
• Description of input and output data
• Description of what the program must do to the input to
convert it to the output - that is, WHAT the program is to
do.
•
•
They may provide formulas, constraints on data, conditions,
etc. etc. BUT (again, not How the developers accomplish
this!)
In a perfect world, Systems Analysts specify the
‘requirements’ needed. (doesn’t always work this way.)
13
1. Program Specifications
Record layout forms describe format of input and
output data
 Data names of each data item in record
 Location of each data item in record
 Size of each data item
 Number of decimal positions (for numeric data
items)
 Please note that exactly WHO does this may vary
depending on the expertise of the systems
analysts, developers, etc. But these are part of
the Specifications.
14
1. Program Specifications
Printer spacing charts describe
 Spacing of outputs (see pp 6-7)


hard copy reports
screen layouts, etc.
 Layout of printed output
 Heading, detail, total lines
 Error messages and locations…
15
2. Design the Program
Program planning tools used to map out
structure and logic of program
Once specifications are captured (discuss!),
design takes place.
Two real kinds of design:

Architectural design (high level, parts;
components, blocks of functionality;
relationships among these blocks, and

Detail design – the logic inside each
block, part, component, etc.
16
2. Design the Program
 Different tools may be used to capture the
preliminary (architectural) design as well as the
detail (logic; algorithms) design.
 Architectural Design:

For many traditional systems, we may use Data
Flow Diagrams; Structure Charts, System Flow
Charts, and similar technologies
 For Detail design:

Most practitioners use flowcharts, pseudocode,
HIPO, or other techniques to capture the module
17
 Architectural design: Book suggests
Hierarchy charts show relationships among
sections of program.

We will use these and call them Structure
Charts.
 Book cites for Detail Design:


Flowcharts use block diagrams to represent
logic – a graphical model, and
Pseudo-code uses English-like statements

This one is preferred but some hang on to the
flowchart. In some cases, it ‘is’ clearer, though.
18
3. Code and Enter Program
 Programmer writes and enters program into
computer
 Program written in symbolic language (like
COBOL)
 Called source program
19
4. Compile Source Program
Compiler is program that
 Checks source program for rule violations
 Translates source program into object
program
 (See p. 8 for System Flow Chart. Know this.)
Source program in
symbolic language
Translated
by compiler
Object program in
machine language
20
5. Test Program
 Test or debug program to ensure it contains
no errors
 Check for two types of errors


Compile-Time Errors
Execution Errors
21
Compile-Time Errors
 Errors detected by compiler during translation
from COBOL to machine language
 Detects violations of programming rules



Misspelled reserved words
Missing punctuation
Errors in use of the programming language
 Also called syntax errors
22
Execution Errors
 Detected when program is run
 Logic error causes incorrect output


Sequence of instructions incorrect
Wrong instruction coded
 Run-time error if computer cannot execute
instruction


Attempt to divide by zero
Attempt to read a file that cannot be found
23
Debugging Techniques
 Desk checking

always do this. Can be costly to omit.
 Correcting syntax errors

Correct syntax errors and resubmit
 Program walkthroughs


Sometimes done in teams; good approach
Can be done prior to submitting for compilation.
 Executing the program

 Just because a program runs to EOJ, does
NOT mean that program was successful!!
24
6. Document the Program
 Documentation - formal set of procedures
and instructions to specify how to use
program
 Written for




Those working with output
Computer operators who run program
Maintenance programmers who make
modifications to program
In some circles called: program maintenance
manual, operators manual, users manual,
etc…
25
Nature of COBOL
 Business-oriented language



Great for business data processing
Large volumes of data
Great for data manipulation


No language is better for transaction processing
or data manipulation than COBOL
Has other major deficiencies, but not these.
 Standard language
 English-like language

Multiply hours-worked by rate giving salary
 Relatively easy to understand
26
History of COBOL
 Developed in 1959 as standard language to
meet needs of business
 Committee to develop language convened by
Department of Defense
 Included representatives from academia,
business, computer manufacturers
27
Standard Versions of COBOL
 1960s
 wide variations in COBOL compilers
 1968
 first COBOL standard set by American
National Standards Institute (ANSI)
 1974
 1985
 second ANSI standard to make COBOL
more efficient, standardized
 this ANSI standard incorporated
structured programming techniques
28
Current and Future Standards
  1985 currently the most widely used
 Sometimes called COBOL 2.
 2002+ is next standard
 Approval expected in 2002
 Information on 2002+ COBOL standard at
http://www.ansi.org
29
Future of COBOL
Likely to remain important language
 Unlike academic environment, most
programs are developed to be used for many
years to realize a ROI. This implies the need
to maintenance as requirements change and
errors are discovered.
 Older COBOL programs need to be updated
 Still used by many for new program
development
30
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
31
Year 2000 Problem (Y2K)
 Year stored as two digits in older programs to
save space
 19 assumed as valid prefix for all years

95 represented year 1995
 Invalid as prefix for years 2000 and beyond

00 could mean 1900 or 2000
32
Year 2000 Problem (Y2K)
Many calculations with dates incorrect starting
in 2000
 To find your age if you were born in 1970
Subtract 70 from 95 (95 - 70 = 25)
 Calculation incorrect for year 2000 and
beyond
00 - 70 = -70 when age should be 30
33
Year 2000 Problem (Y2K)
To correct problem
 Billions of lines of code, many written in
COBOL needed to be examined
 Code changed to use four digits for year
 Age, other calculations now correct
1995 - 1970 = 25
2000 - 1970 = 30
34
Improving Program Design
Two techniques used to develop programs that
are easier to understand, test, debug and
modify
 Structured Programming
 Top-Down Programming
35
Structured Programming
 Eliminates use of GO TO statements

Allowed skipping to different sections of
program without returning to starting point

Advocated the use of simple program
constructs:

sequence

selection

iteration plus two extensions (later)
 Program logic easier to follow with "GO-TO-
less" programming
36
Structured Programming
Program divided into paragraphs
 Main paragraph or module controls logic flow using
PERFORM statements
 Sometime called a ‘driver’ module…
 Main module "performs" other modules when
instructions in that module required
 Control transferred to a different paragraph and,
upon completion of the instructions in that
paragraph, control returns to the main paragraph.
 Each module can be written and tested
independently of others
37
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
38
Top-Down Programming
For COBOL program
 Code main modules or routines first
 Code intermediate modules next
 Details deferred to minor modules and coded
last
 We will use this technique a lot later on. We
may refer to this technique as ‘drivers’ and
‘stubs.’

This is an outstanding approach to developing
larger programs…
39
Download