Chapter 1 An Introduction to Structured Program Design


































- Slides: 34

Chapter 1 An Introduction to Structured Program Design in COBOL 1

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 – Applications programs - perform tasks required by users 2

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 3

Program Languages Machine language • Only language computer understands • All programs executed on computer must be in machine language • Machine language programs are difficult to write 4

Program Languages Symbolic language (like COBOL) • English-like languages used to write programs • Easier than writing programs in machine language • Must be translated or compiled into machine language to run on computer 5

Nature of COBOL • • Business-oriented language Standard language English-like language Relatively easy to understand 6

Standard Versions of COBOL • 1960 s - wide variations in COBOL compilers • 1968 - first COBOL standard set by American National Standards Institute (ANSI) • 1974 - second ANSI standard to make COBOL more efficient, standardized • 1985 - this ANSI standard incorporated structured programming techniques 7

Program Development Process 1. Determine Program Specifications 2. Design Program Using Program Planning Tools 3. Code and Enter Program 4. Compile Program 5. Test Program 6. Document Program 8

1. Program Specifications • Systems analysts, users and programmers develop specifications • Specifications include: • Description of input and output data • Step-by-step processing required to convert input to output 9

2. Design the Program planning tools used to map out structure and logic of program • Flowcharts use block diagrams to represent logic • Pseudocode uses English-like statements • Hierarchy charts (a. k. a. structure charts) show relationships among sections of program 10

3. Code and Enter Program • Programmer writes and enters program into computer • Program written in symbolic language (like COBOL) • Called source program 11

4. Compile Source Program Compiler is program that • Checks source program for rule violations • Translates source program into object program Source program in symbolic language Translated by compiler Object program in machine language 12

5. Test Program • Test or debug program to ensure it contains no errors • Check for two types of errors – Compile-Time Errors – Execution Errors 13

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 14

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

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 "GOTO-less" programming 16

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 17

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 18

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

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 20

Interactive vs Batch Programs Batch programs • Process large volumes of input at periodic intervals • Input data read in from files • Output written to files 21

Creating a Report • An Input File – Fixed record layout – Data are all “jammed” together – Records are read into the computer’s memory • An Output Report – Report layout – Data are spread out for easy reading – “Hardcopy” report is sent to the printer 22

The Input File • There are no column headings in the input file. • There are no field definitions. • The data is “all crammed together” in the file. • Your COBOL program must know where on field ends and the next field begins. 23

Sample Data File Acton Jocelyn Anderson Hazel Baker Donald Broadhurst. Ryan J Campbell J. H. 223 Connecticut St. San Francisco. CA 941070350 1247 Main Street Woodside CA 9406202500100 1532 Bancroft Road. Berkeley CA 9470303750300 Route 3 Big Trees CA 950660500 4892 Powell Street. Emeryville CA 9460802000175 Notice, each row (or record) consists of 64 consecutive bytes. A record is READ into computer memory, for use in your COBOL program. 24

Input File Layout Field Length Data Class ----------------------Last Name 10 Alphanumeric First Name 8 Alphanumeric Street Address 18 Alphanumeric City 13 Alphanumeric State 2 Alphanumeric Zip 5 Alphanumeric Target Contribution 4 Numeric Actual Contribution 4 Numeric Total Record 64 25

The Output Report • How many spaces should there be between columns in a report? • Do these spaces appear automatically? • No, your COBOL program must define the exact report layout, line by line. • Consider the following report layout: 26

Sample Report Layout Acton, Jocelyn 223 Connecticut St San Francisco CA 94107 Anderson, Hazel 1247 Main Street Woodside CA 94062 Baker, Donald 1532 Bancroft Road Berkeley CA 94703 Broadhurst, Ryan J Route 3 Big Trees CA 95066 Campbell, J. H. 4892 Powell Street Emeryville CA 94608 27

A COBOL Program • Sample Program (p. 23) Coding Form • Typically, your COBOL code will be typed in ALL UPPERCASE LETTERS. • Periods are very important to all COBOL programs. You will find many errors that are a result of missing periods. 28

Four Divisions of a COBOL Program • IDENTIFICATION DIVISION. PROGRAM-ID. PROG 1. • ENVIRONMENT DIVISION. define the files used by the program • DATA DIVISION. define all the variables • PROCEDURE DIVISION. the logic of the program 29

IDENTIFICATION DIVISION. • Two required entries – The Division Header – The PROGRAM-ID. • Notice the use of periods in this division. • These periods are required. • Omitting or misplacing periods usually causes problems. 30

ENVIRONMENT DIVISION. • This is the link between your COBOL program and the actual computer system on which it is running. • All COBOL programs (in this class) will have an INPUT-OUTPUT SECTION. • This section contains the FILE-CONTROL paragraph. 31

DATA DIVISION. • This division will typically have two sections: – FILE SECTION. – WORKING-STORAGE SECTION. • Each file listed in the ENVIRONMENT DIVISION must also be defined in the FILE SECTION of the DATA DIVISION. • FD – File Description 32

PROCEDURE DIVISION • Set of instructions to be executed by program • Organization of instructions planned before coding begins • Describes program logic and order in which instructions will be executed 33

Read/Move/Print Sequence • Data is READ into computer memory • Memory defines the fields of the input file • Data is MOVEd to computer memory bytes that define the output report layout • The report line is written to the output device (i. e. , the screen, the printer or a file). 34