1 / 24

Structured COBOL Programming

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 Winifred J. Rex Presentation Bowling Green State University.

elaine-hunt
Download Presentation

Structured COBOL Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 Winifred J. Rex Presentation Bowling Green State University

  2. Chapter Objectives To familiarize you with •  Structured programs •  Pseudocode •  Hierarchy or Structure Charts •  Logical Control Structures • Good programming techniques • Interactive processing

  3. Well-Designed Programs Are structured programs – when using procedural languages (COBOL, C, …) • Use instructions executed in standardized order • Divide program into modules, each performing a specific function • Control returns to place module called from • Simple PERFORM used in COBOL to execute modules (paragraphs)

  4. Well-Designed Programs Use top-down approach • Code modules in hierarchical order • Main modules first, then secondary modules with detailed code • Step-wise refinement • Top modules are ‘control’ modules; abstract; drivers; contain ‘Performs’… • As we go down the hierarchy, control becomes less and computations and data manipulation becomes greater.

  5. Well-Designed Programs Are modular • Group related statements together into modules • Execute each module or paragraph in COBOL with simple PERFORM • For example, statements to calculate students’ tuition in one module, statements to calculate room and board in another module

  6. Designing Before Coding • Design program first • So program will work efficiently • So program works as integrated whole • Design techniques applicable to all languages • Code program only after design done • Use syntax rules of language • Syntax rules are language-specific

  7. Pseudocode • Primary tool for planning program logic • We will use structure charts for our architectural design and pseudo-code for our lower-level detail (algorithmic) design. • Specifies instructions and logical control structures used by program • Use one or more lines of pseudo-code to describe each program step

  8. Four Logical Control Structures • Used by structured programs to specify order in which instructions are executed 1. Sequence 2. Selection 3. Iteration 4. Case Structure All programs may be written using some combination of these control structures!

  9. Sequence • Instructions executed in order they appear • Three instructions below executed one after the other(pseudo-code shown)START Read Amt1, Amt2 Compute Total = Amt1 + Amt2 Write TotalSTOP • Note: no syntax; no periods, just generic procedure. Imperative statements. Nothing conditional or repetitive.

  10. Selection (true / false) • Instructions executed depending on existence of a condition • Called IF-THEN-ELSE logical control structure • Condition: if amt > 40 … • The condition is amt>40. This is evaluated. It is either TRUE or FALSE. • Present value of amt either equals 40 or not! • Subsequent actions take place based on the truth value of the condition!

  11. IF condition THEN instructions to do if condition exists ELSE instructions to do if condition doesn’t exist END-IF Example (again, this is in pseudocode.) IF X is Less Than Y THEN Add X To Y ELSE Subtract X From Y END-IF Selection Structure Pseudocode

  12. Iteration (Looping Constructs) • To specify repeated execution of series of steps • Use in-line or standard PERFORM … UNTIL for iteration in COBOL • There are additional forms – later. • Both execute group of instructions repeatedly until a condition is met

  13. Iteration Pseudocode In-line PERFORM UNTIL PERFORM UNTIL condition . . statements to be repeated . END-PERFORM . . Statements following PERFORM . MUST use a scope terminator! Needed to ‘bound’ the scope. Note: statements within Perform may never be executed. Remember the ‘pre-condition’ followed by ‘post-conditions.’

  14. Iteration Pseudocode Standard PERFORM UNTIL PERFORM paragraph-1 UNTIL condition . . Statements following PERFORM . Paragraph-1. located elsewhere in program . . statements to be repeated .

  15. Infinite Loops • In-line and standard PERFORM UNTIL both repeat instructions until condition met • If condition never met, loop never ends • Causes error called an infinite loop

  16. Infinite Loops • Make sure loop ends by including instruction in loop that causes condition to be met • For example, if condition is WS-MORE-DATA = ‘NO’ • Make sure there is statement in loop that sets WS-MORE-DATA to ‘NO’ when there is no more data

  17. Two Examples move 0 to counter. perform until counter > 10 …. …. end-perform Will generate an infinite loop: move 0 to counter. perform until counter = 10 …. add 1 to counter end-perform Will terminate loop after 10 iterations:

  18. Case Structure • To choose from one of several sets of instructions depending on a condition • For example, assume • Different instructions should be executed when field Code-In has values of 1, 2 or 3 • Any other value of Code-In is considered an error

  19. Case Structure Pseudocode EVALUTATE Code-In WHEN 1 PERFORM paragraph-1 WHEN 2 PERFORM paragraph-2 WHEN 3 PERFORM paragraph-3 WHEN OTHER PERFORM error-paragraph END-EVALUATE Note: scope terminator, indentation. Will cause branches only if value of Code-In is either a 1 or a 2 or a 3; otherwise, error-paragraph will be performed. Note also: ‘integer’ values!

  20. Hierarchy Charts (Structure Charts) • To illustrate top-down relationships among modules • Graphic method to divide program into modules • Modules shown as rectangular boxes • Relationships among modules represented by connected lines • Note: only DOWN not across. • We are functionally decomposing higher-level modules into its parts.

  21. Example of Hierarchy Chart 0000-main Very Important! 2000-some-name1 1000-some-name. 1300-xxx 1600-xxx 2300-yyy 2600-yyy 2900-yyy DISCUSS PARAGRAPH NAMING CONVENTIONS

  22. Hierarchy Chart • Letters A-H represent modules or paragraphs • A is main module • B and C are subordinate modules called from main paragraph with a PERFORM • D and E represent modules called from paragraph B • We will use our standards.

  23. Pseudocode and Hierarchy Charts • Pseudocode shows actual sequence of instructions – detailed algorithmic steps. • Do this secondly • Hierarchy charts show relationships among modules – higher level, architectural design. Do this first. • Both help programmers • Develop efficient programs • Debug and modify programs

  24. Naming Paragraphs • Name up to 30 characters - letters, digits, hyphen • Choose meaningful name that describes type of instructions in module • Use numeric prefixes to indicate relative location of module in program • Examples 1000-Main-Module 2000-Process-Data

More Related