1 / 30

Chapter 1 - Introduction

Chapter 1 - Introduction. 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

bastien
Download Presentation

Chapter 1 - Introduction

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

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

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

  4. John Adams 90 Political Science Engineering major with more than 110 credits Amelia Earhart 120 Aviation Orville Wright 115 Engineering Georgia O'Keeffe 125 Art Figure 1.2Input, Processing, and Output INPUT PROCESSING OUTPUT STUDENT NAME ORVILLE WRIGHT

  5. Program Specifications / Documentation • System Flowchart • Narrative • Hierarchy Chart • Psuedo code/Flow Chart • Input/Output Specifications

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

  7. System Flowchart / IPO Chart Identifies the inputs and outputs of the program. Basic IPO model. Meaningful program name and cobol file names are established here. Used in the development of the environment division. May also contain file external / physical name. PAYROLL-MASTER-FILE PRINT-EARNINGS-REPORT EARNINGS-REPORT

  8. 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 pseudocode and in your program’s Procedure Division. It also outlines a very general program flow. Answers the question WHAT needs to be done?

  9. PSEUDO-CODE Pseudo – almost like. Rough notes to yourself regarding program design. Provides for a medium level design of your program - logic can be spelled out in English like terms and latter translated to program code. The paragraph names established in the hierarchy chart are used here and again in the actual coding of your program. The level of detail required here – depends on the complexity of the program and the programmer’s understanding of the problem’s solution. IT IS NOT A MODIFIED LISTING OF A COMPLETED PROGRAM.

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

  11. START OPEN FILES READFIRSTRECORD WRITEHEADINGS PROCESSRECORDS END OFFILEREACHED? CLOSEFILES STOP Figure 1.4 Flowchart to Select Engineering Seniors 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 (b) Detail of PROCESS-RECORDS

  12. TABLE 1.1The Flow chart and Test Data BLOCK & TIMESDESCRIPTION EXECUTED EXPLANATION 1 Start 1 At beginning of program 2 Open files 1 At beginning of program3 Initial read 1 Reads the first record (Adams)4 Write heading 1 At beginning of program5 Connector 5 Entered five times6 End-of-file test 5 Once for each of four records; once to sense end-of-file condition7 Close files 1 Once, before execution stops 8 Stop 1 Executed once, at program’s end9 Qualifying test 4 Once for each student10 Write 1 Executed for Wright only11 Connector 4 Entered four times12 Read 4 Reads every record but the first, and detects the end-of-file condition

  13. Figure 1.5Pseudocode 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

  14. Divisions of a Cobol Program • Identification Division • Environment Division • Data Division • Procedure Division

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

  16. Figure 1.6The First COBOL Program (continued) Data Division 23 FD PRINT-FILE24 RECORD CONTAINS 132 CHARACTERS25 DATA RECORD IS PRINT-LINE. 26 01 PRINT-LINE PIC X(132).27 28 WORKING-STORAGE SECTION. 29 01 DATA-REMAINS-SWITCH PIC X(2) VALUE SPACES.30 31 01 HEADING-FILE.32 05 FILLER PIC X(10) VALUE SPACES. 33 05 FILLER PIC X(12) VALUE ‘STUDENT NAME’.34 05 FILLER PIC X(110) VALUE SPACES.35 36 01 DETAIL-LINE. 37 05 FILLER PIC X(8) VALUE SPACES.38 05 PRINT-NAME PIC X(25). 39 05 FILLER PIC X(99) VALUE SPACES.40

  17. Figure 1.6The First COBOL Program (continued) 41 PROCEDURE DIVISION. 42 PREPARE-SENIOR-REPORT. 43 OPEN INPUT STUDENT-FILE 44 OUTPUT PRINT-FILE. 45 READ STUDENT-FILE 46 AT END MOVE ‘NO’ TO DATA-REMAINS-SWITCH47 END-READ. 48 PERFORM WRITE-HEADING-LINE. 49 PERFORM PROCESS-RECORDS50 UNTIL DATA-REMAINS-SWITCH = ‘NO’.51 CLOSE STUDENT-FILE52 PRINT-FILE.53 STOP RUN.54 55 WRITE-HEADING-LINE.56 MOVE HEADING-LINE TO PRINT-LINE.57 WRITE PRINT-LINE.58 59 PROCESS-RECORDS.60 IF STU-CREDITS > 110 AND STU-MAJOR = ‘ENGINEERING’61 MOVE STU-NAME TO PRINT-NAME62 MOVE DETAIL-LINE TO PRINT-LINE63 WRITE PRINT-LINE64 END-IF.65 READ STUDENT-FILE66 AT END MOVE ‘NO’ TO DATA-REMAINS-SWITCH67 END-READ. Procedure Division

  18. Programming Structures • Sequence • Selection • Iteration/Repetition

  19. Figure 1.7 Procedure Division Logic PROCEDURE DIVISION.PREPARE-SENIOR-REPORT. OPEN INPUT STUDENT-FILE OUTPUT PRINT-FILE. READ STUDENT-FILE AT END MOVE ‘NO’ TO DATA-REMAINS-SWITCH END-READ. PERFORM WRITE-HEADING-LINE. PERFORM PROCESS-RECORDS UNTIL DATA-REMAINS-SWITCH = ‘NO’. PROCESS-RECORDS. IF STU-CREDITS > 110 AND STU-MAJOR = ‘ENGINEERING’ MOVE STU-NAME TO PRINT-NAME MOVE DETAIL-LINE TO PRINT-LINE WRITE PRINT-LINE END-IF. READ STUDENT-FILE AT END MOVE ‘NO’ TO DATA-REMAINS-SWITCH END-READ. DATA-REMAINS-SWITCH =‘NO’? FALSE TRUE CLOSE STUDENT-FILE PRINT-FILE.STOP RUN.

  20. Rejected for wrong major JOHN ADAMS 090POLITICAL SCIAMELIA EARHART 120AVIATIONORVILLE WRIGHT 115ENGINEERINGGEORGIA O’KEEFE 125ARTMERIWETHER LEWIS 115TRAVELJOHN KENNEDY 115POLITICAL SCIALEX BELL 090ENGINEERINGEMILY DICKENSON 085LITERATUREJOHN REOBLING 115ENGINEERING (a)Test Data Rejected for insufficient credits STUDENT NAME ORVILLE WRIGHT JOHN ROEBLING (b) Output Figure 1.8 Test Data and Associated Output

  21. Elements of a Cobol Program • Reserved Words • Programmer supplied Names • Literals • Symbols • Level Numbers • Pictures

  22. Programmer Supplied Names • Alphabetic, Numbers, and hyphen • 30 characters • May not begin with hyphen

  23. SUM SUM-OF-X SUM OF X SUM-OF-X- SUM-OF-ALL-THE-XS SUM-OF-ALL-THE-XS-IN-THE-ENTIRE-PROGRAM GROSS-PAY-IN-$ 12345 Invalid - reserved word Valid Invalid - contains blanks Invalid - ends with a hyphen Valid Invalid - contains more than 30 characters Invalid - contains a $ Valid as a paragraph name but invalid as a data name Table 1.2 Programmer-Supplied Names PROGRAMMER-SUPPLIED NAME EXPLANATION

  24. Literals • Alphanumeric or Numeric • Alphanumeric • enclosed in quotes • 160 characters max • Numeric • 18 digits max • can not end in a decimal point

  25. 123.4 ‘123.4’ +123 ‘IDENTIFICATION DIVISION’ 123. 123- Valid numeric literal Valid nonnumeric literal Valid numeric literal Valid nonnumeric literal Invalid numeric literal - may not end with a decimal point Invalid numeric literal- the minus sign must be in the leftmost position Table 1.3 Numeric & Nonnumeric Literals LITERAL EXPLANATION

  26. TABLE 1.4 Symbols CATEGORY SYMBOL MEANING Punctuation . Denotes end of COBOL entry , Denotes clauses ‘ or “ Sets off nonnumeric literals Arithmetic + Addition - Subtraction * Multiplication / Division ** Exponentiation Relational = Equal to > Greater than < Less than >= Greater than or equal to <= Less than or equal to

  27. A Second Lookat a 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

  28. A Second Look at a COBOL Program (continued) Data Division 23 FD PRINT-FILE24 RECORD CONTAINS 132 CHARACTERS25 DATA RECORD IS PRINT-LINE. 26 01 PRINT-LINE PIC X(132).27 28 WORKING-STORAGE SECTION. 29 01 DATA-REMAINS-SWITCH PIC X(2) VALUE SPACES.30 31 01 HEADING-FILE.32 05 FILLER PIC X(10) VALUE SPACES. 33 05 FILLER PIC X(12) VALUE ‘STUDENT NAME’.34 05 FILLER PIC X(110) VALUE SPACES.35 36 01 DETAIL-LINE. 37 05 FILLER PIC X(8) VALUE SPACES.38 05 PRINT-NAME PIC X(25). 39 05 FILLER PIC X(99) VALUE SPACES.40

  29. A Second Look at a COBOL Program (continued) 41 PROCEDURE DIVISION. 42 PREPARE-SENIOR-REPORT. 43 OPEN INPUT STUDENT-FILE 44 OUTPUT PRINT-FILE. 45 READ STUDENT-FILE 46 AT END MOVE ‘NO’ TO DATA-REMAINS-SWITCH47 END-READ. 48 PERFORM WRITE-HEADING-LINE. 49 PERFORM PROCESS-RECORDS50 UNTIL DATA-REMAINS-SWITCH = ‘NO’.51 CLOSE STUDENT-FILE52 PRINT-FILE.53 STOP RUN.54 55 WRITE-HEADING-LINE.56 MOVE HEADING-LINE TO PRINT-LINE.57 WRITE PRINT-LINE.58 59 PROCESS-RECORDS.60 IF STU-CREDITS > 110 AND STU-MAJOR = ‘ENGINEERING’61 MOVE STU-NAME TO PRINT-NAME62 MOVE DETAIL-LINE TO PRINT-LINE63 WRITE PRINT-LINE64 END-IF.65 READ STUDENT-FILE66 AT END MOVE ‘NO’ TO DATA-REMAINS-SWITCH67 END-READ. Procedure Division

  30. End of Chapter 1

More Related