Академический Документы
Профессиональный Документы
Культура Документы
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 responsibility for errors, omissions, or damages, caused by the use of these programs or from the use of the information contained herein.
9th Edition
OBJECTIVES
To Familiarize You With:
1. The way structured programs should be designed. 2. Pseudocode and flowcharts as planning tools used to map out the logic in a structured program. 3. Hierarchy or structure charts as planning tools used to illustrate the relationships among modules in a top-down program.
Structured COBOL Programming, Stern & Stern, 9th Edition
OBJECTIVES
4. The logical control structures of sequence, selection, iteration, and case. 5. Techniques used to make programs easier to code, debug, maintain, and modify. 6. Interactive processing.
CONTENTS
What Makes a Well-Designed Program? Designing Programs before Coding Them
CONTENTS
Hierarchy Charts for Top-Down Programming Naming Modules or Paragraphs
Modularizing Programs
CONTENTS
A Review of Two Coding Guidelines An Introduction to Interactive Processing Debugging Programs
If programs are systematically planned before they are coded, they will be better designed.
Planning tools such as pseudocode, flowcharts, and hierarchy charts help map out program logic.
Structured COBOL Programming, Stern & Stern, 9th Edition
PROGRAMS SHOULD BE STRUCTURED Well-designed, structured programs are those that have a series of logical constructs.
Thus, the order in which these instructions are executed is standardized.
Pseudocode
A pseudocode is a set of statements that specifies the instructions and logical control structures that will be used in a program.
Flowcharts
A flowchart is a diagram or pictorial representation of the instructions and logical control structures that will be used in a program.
Structured COBOL Programming, Stern & Stern, 9th Edition
Pseudocode
Pseudocode has been designed specifically for representing the logic in a structured program.
The pseudocode for a program that reads in two numbers, adds them, and prints the total is as follows:
START
READ AMT1, AMT2 COMPUTE TOTAL = AMT1 + AMT2 WRITE TOTAL
STOP
Structured COBOL Programming, Stern & Stern, 9th Edition
Flowcharts
The following symbols are the ones most frequently used.
Symbol Name
Input/Output
Use
Used for all I/O operations Used for all arithmetic and data transfer operations.
Processing
Flowcharts
The following symbols are the ones most frequently used.
Symbol Name Decision Use Used to test for a condition.
Terminal
Connector
Predefined Process
Structured COBOL Programming, Stern & Stern, 9th Edition
WRITE TOTAL
STOP
Structured COBOL Programming, Stern & Stern, 9th Edition
2. Selection.
3. Iteration. 4. Case Structure.
Structured COBOL Programming, Stern & Stern, 9th Edition
We use a sequence to depict the logic when data is to be processed in a stepby-step order.
Structured COBOL Programming, Stern & Stern, 9th Edition
Selection is a logical control construct that executes instructions depending on the existence of a condition.
It is sometimes called an IF-THEN-ELSE logical control structure.
If the condition is true (or exists), the statement or statements following the THEN statement are executed.
Structured COBOL Programming, Stern & Stern, 9th Edition
If the condition does not exist (or is false), we execute the statement or statements following the ELSE statement.
Later we will see that a COBOL 85 program can look just like pseudocode.
The structure that makes use of the PERFORM UNTIL is called iteration. Iteration or looping is a logical control structure used for specifying the repeated execution of a series of steps.
An example follows.
PERFORM UNTIL
PERFORM
UNTIL ARE-THERE-MORE-RECORDS = 'NO
. .
.
END-PERFORM
Structured COBOL Programming, Stern & Stern, 9th Edition
The case structure is a special control structure used when there are numerous paths depending on the contents of a given field.
It is used when we wish to perform one of several possible procedures depending on some condition or value.
WHEN 2
PERFORM NEW-HIRE
WHEN OTHER
PERFORM ERROR
END-EVALUATE
Structured COBOL Programming, Stern & Stern, 9th Edition
PSEUDOCODE RULES
1. Pseudocode is written and read from top to bottom.
2. The logical control structure is defined with the use of key terms:
PERFORM . . . END-PERFORM IF-THEN-ELSE . . . END-IF CASE . . . END-CASE.
3. The operations to be executed within a PERFORM, IF-THEN-ELSE, or CASE (EVALUATE) can be coded in-line or in a separate module.
Structured COBOL Programming, Stern & Stern, 9th Edition
FLOWCHART RULES
1. A flowchart is drawn and read from top to bottom unless a specific condition alters the path. 2. The symbol itself denotes the type of operation such as input/output or processing. 3. An explanatory note within the symbol describes the specific operation to be performed.
Structured COBOL Programming, Stern & Stern, 9th Edition
HIERARCHY CHARTS
A hierarchy or structure chart is a graphic method for segmenting a program into modules.
Its main purpose is to provide a visual overview of the modules in a program.
HIERARCHY CHARTS
1. A hierarchy chart represents program modules as rectangular boxes and illustrates the interrelationships among these modules with the use of connected lines. 2. A module is a well-defined program segment that performs a specific function.
Structured COBOL Programming, Stern & Stern, 9th Edition
PERFORM B.
PERFORM C.
B.
PERFORM D. PERFORM E.
Structured COBOL Programming, Stern & Stern, 9th Edition
The hierarchy chart only illustrates modules executed from other modules.
Each block or box in a hierarchy chart represents a module.
Structured COBOL Programming, Stern & Stern, 9th Edition
HIERARCHY CHARTS
ADVANTAGES OF A HIERARCHY OR STRUCTURE CHART
1. It helps programmers, systems analysts, and users see how modules interrelate.
2. It helps programmers debug and modify programs. 3. It helps programming managers assess the efficiency of programs.
Structured COBOL Programming, Stern & Stern, 9th Edition
MODULARIZING PROGRAMS
We have seen that top-down programs are written with main units or modules planned and coded first, followed by more detailed ones.
DEBUGGING TIP
COBOL 85 programmers should always use scope terminators with the READ and IF statements.
When scope terminators are coded, periods are not used to end statements except for the last statement in a paragraph.
Scope terminators ensure that all clauses within a statement will be associated with the appropriate instruction, thereby minimizing logic errors.
Structured COBOL Programming, Stern & Stern, 9th Edition
INTERACTIVE PROCESSING
COBOL was originally developed to process files of data and is still widely used for that purpose. Many organizations, however, are using COBOL for interactive processing where- the user enters data using a keyboard on a PC or a terminal, and
INTERACTIVE PROCESSING
We use the ACCEPT verb for entering input from a keyboard and the DISPLAY verb for displaying output on a screen.
The instruction ACCEPT identifier enables the user to enter input data directly from a keyboard rather than from a disk file. The identifier is likely to be a WORKINGSTORAGE entry.
When input is entered using the ACCEPT verb, there is no need to establish a file.
Structured COBOL Programming, Stern & Stern, 9th Edition
INTERACTIVE PROCESSING
To enter as input a DISCOUNT-AMT, for example, you can code: ACCEPT DISCOUNT-AMT
The format is determined by the PIC clause for DISCOUNT-AMT.
DEBUGGING PROGRAMS
After you design a program you are ready to code it. Programs must be fully tested to ensure that there are no errors. The process of eliminating errors from a program is called debugging.
SYNTAX ERRORS
After a program has been planned and coded, it is keyed into a computer. Then it is ready to be compiled or translated into machine language.
During this translation/compilation process, the compiler will list any violations in programming rules that may have occurred.
These rule violations are called syntax errors; they must be corrected before the program can be executed.
Structured COBOL Programming, Stern & Stern, 9th Edition
SYNTAX ERRORS
When diagnostics appear in a source listing (either at the end or right after the line in question), they typically have the following format: Line No. Error Code Error Message
PC COMPILERS
Micro Focus and RM/COBOL-85 have compiler-generated messages similar to those just discussed.
Micro Focus will highlight the word and display the error messages. On-line HELP is available to further explain the meaning of the messages. These error codes are documented in its On-LineReference Guide.
Structured COBOL Programming, Stern & Stern, 9th Edition
LOGIC ERRORS
Syntax errors are detected by the compiler and, except for warnings, they should all be corrected before you run the program. However, even after a program has been compiled so that it has no syntax errors it is not yet fully debugged.
The program must be executed with test data to ensure that there are no logic errors.
Structured COBOL Programming, Stern & Stern, 9th Edition
LOGIC ERRORS
Some logic errors result in a program interrupt.
These are called run-time errors, and must be corrected before execution can continue.
CHAPTER SUMMARY
I. Program Design A. Logical Control Structures
The logical control structures are as follows:
1. Sequence 2. IF-THEN-ELSE or Selection
CHAPTER SUMMARY
B. Program Planning Tools
1. To structure a program, use pseudocode or a flowchart. 2. To illustrate the top-down approach showing how modules interrelate, use a hierarchy chart.
C. Naming Modules
Use descriptive names along with numeric prefixes that help locate the paragraphs quickly (e.g., 200-PRINT-HEADING, 500-PRINT-FINAL- TOTAL).
Structured COBOL Programming, Stern & Stern, 9th Edition
CHAPTER SUMMARY
D. A Well-Designed Program Uses: 1. Structured programming techniques.
2. A modularized organization.
3. A top-down approach:
Code main modules first, followed by minor ones.
4. Meaningful names for fields and paragraphs. 5. One clause per line and indented clauses within a sentence.
Structured COBOL Programming, Stern & Stern, 9th Edition
CHAPTER SUMMARY
II. Interactive Processing
A. You can use ACCEPT to input data from a keyboard.
CHAPTER SUMMARY
III. Debugging
A. Correct all syntax errors or rule violations that are listed by the compiler. B. Test your program carefully with test data that includes all possible values that the program might encounter during a normal production run.
Structured COBOL Programming, Stern & Stern, 9th Edition