1 / 53

Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL

Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL. CHAPTER 1 OBJECTIVES. To familiarize you with: 1. The reasons for COBOL’s popularity as a business-oriented language. 2. Some general programming practices and techniques.

pembroke
Download Presentation

Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL

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. Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL Structured COBOL Programming, Stern & Stern, 9th edition

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

  3. 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 programconverts input data to output information. Structured COBOL Programming, Stern & Stern, 9th edition

  4. 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

  5. Two types of computer programs: 1. Operating Systems Programs • Control the overall operations of the computer 2. Applications Programs • 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

  6. 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

  7. 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

  8. 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

  9. Symbolic Programs • Symbolic Programs use English-like or symbolicinstructions. • 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

  10. Program Development Process • 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

  11. 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

  12. 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 Size  Name Alphanumeric 30 Address Alphanumeric 23 Pay-Rate Numeric 5.2 or 7 with 2 decimals Etc. Structured COBOL Programming, Stern & Stern, 9th edition

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

  14. HIERARCHY CHART 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 program’s 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

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

  16. To Reduce Cost of Fixing Errors Structured COBOL Programming, Stern & Stern, 9th edition

  17. 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

  18. 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

  19. PROGRAM DEVELOPMENT PROCESS • Remember, coding is undertaken only after the program requirements have been fully specified and the logichas been carefully planned. Structured COBOL Programming, Stern & Stern, 9th edition

  20. 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

  21. 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

  22. 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

  23. 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

  24. WHENIT 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

  25. 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

  26. 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

  27. 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

  28. 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

  29. TECHNIQUES FOR IMPROVING PROGRAM DESIGN Structured COBOL Programming, Stern & Stern, 9th edition

  30. 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

  31. 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

  32. 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

  33. 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

  34. 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

  35. Program Specifications • System Flowchart • Input/Output Specifications • Hierarchy Chart • Psuedo code • Narrative – as comments in program Structured COBOL Programming, Stern & Stern, 9th edition

  36. System Flowchart INPUT PROCESSING OUTPUT Attendance Report PRINT STUDENT ATTENDANCE Student-File Structured COBOL Programming, Stern & Stern, 9th edition

  37. START OPEN FILES READFIRSTRECORD WRITEHEADINGS PROCESSRECORDS END OFFILEREACHED? CLOSEFILES STOP Program Flow Chart 1 2 3 4 5 6 7 8 PROCESSRECORDS ENGINEERINGMAJOR ANDMORE THAN 110 CREDITS FALSE TRUE 9 WRITESTUDENTNAME 10 11 READNEXTRECORD 12 STOP (a) Overall Flowchart Structured COBOL Programming, Stern & Stern, 9th edition (b) Detail of PROCESS-RECORDS

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

  39. 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 organization’s set of files Structured COBOL Programming, Stern & Stern, 9th edition

  40. Jphn Adams 90 Political Science John Adams 90 Political Science Amelia Earhart 120 Aviation Orville Wright 115 Engineering Georgia O'Keeffe 125 Art Georgia O’Keeffe 125 Art Fields(Facts) Records(Set of Fields) Name: John AdamsCredits: 90Major: Political Science Name: Amelia EarhartCredits: 120Major: Aviation Name: Orville WrightCredits: 115Major: Engineering Name: Georgia O’KeeffeCredits: 125Major: Art Amelia Earhart 120 Aviation Orville Wright 115 Engineering Figure 1.1 Fields, Records, and Files Structured COBOL Programming, Stern & Stern, 9th edition

  41. Programming Structures • Sequence • Selection • Iteration/Repetition Structured COBOL Programming, Stern & Stern, 9th edition

  42. 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

  43. 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

  44. 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

  45. Structured Programming Using Modular Design for Coding Paragraphs • The typical structured program is divided intoparagraphs 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

  46. 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

  47. 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 200-INITIALIZE 210-WAGE ROUTINE Structured COBOL Programming, Stern & Stern, 9th edition

  48. RULES FOR INTERPRETING PSEUDOCODE • 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… • The instructions between the: PERFORM UNTIL NO MORE DATA executed repeatedly UNTIL there are no more records to process END-PERFORM. Structured COBOL Programming, Stern & Stern, 9th edition

  49. 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

  50. Figure 1.6The First COBOL Program Identification Division 1 IDENTIFICATION DIVISION.2 PROGRAM-ID. SENIOR.3 AUTHOR. ROBERT GRAUER.45 ENVIRONMENT DIVISION.6 INPUT-OUTPUT SECTION.7 FILE-CONTROL.8 SELECT STUDENT-FILE ASSIGN TO ‘A:\CHAPTR02\SENIOR.DAT’9 ORGANIZATION IS LINE SEQUENTIAL.10 SELECT PRINT-FILE11 ASSIGN TO PRINTER.1213 DATA DIVISION.14 FILE SECTION.15 FD STUDENT-FILE16 RECORD CONTAINS 43 CHARACTERS17 DATA RECORD IS STUDENT-IN.18 01 STUDENT-IN.19 05 STU-NAME PIC X(25).20 05 STU-CREDITS PIC 9(3).21 05 STU-MAJOR PIC X(15).22 Environment Division Data Division Structured COBOL Programming, Stern & Stern, 9th edition

More Related