Title: Chapter 1 Introduction
1Chapter 1 - Introduction
2Fields(Facts)
Records(Set of Fields)
Name John AdamsCredits 90Major Political
Science Name Amelia EarhartCredits 120Major
Aviation Name Orville WrightCredits 115Major
Engineering Name Georgia OKeeffeCredits 125
Major Art
Amelia Earhart 120 Aviation
Orville Wright 115 Engineering
Figure 1.1 Fields, Records, and Files
3Figure 1.2 Input, Processing, and Output
INPUT
PROCESSING
OUTPUT
STUDENT NAME ORVILLE WRIGHT
4Figure 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
5TABLE 1.1 The Flow chart and Test Data
BLOCK TIMESDESCRIPTION EXECUTED
EXPLANATION
1 Start 1 At beginning of program 2 Open
files 1 At beginning of program 3 Initial
read 1 Reads the first record (Adams) 4 Write
heading 1 At beginning of program
5 Connector 5 Entered five times 6 End-of-file
test 5 Once for each of four records once
to sense end-of-file condition 7 Close
files 1 Once, before execution stops
8 Stop 1 Executed once, at programs end
9 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
6Figure 1.5 Pseudocode
Initialization Processing Termination
Open files Read first record Write heading
DO while data remains IF engineering major
with more than 110 credits Write students name
ENDIF ENDDO
Close files Stop
7Figure 1.6 The 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
SYSIN9 ORGANIZATION IS LINE SEQUENTIAL.10
SELECT PRINT-FILE ASSIGN TO SYSOUT11 ORGANIZATIO
N IS LINE SEQUENTIAL.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
8Figure 1.6 The 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
9Figure 1.6 The First COBOL Program (continued)
41 PROCEDURE DIVISION. 42 PREPARE-SENIOR-RE
PORT. 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 gt
110 AND STU-MAJOR ENGINEERING61
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
10Figure 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. PERFO
RM WRITE-HEADING-LINE. PERFORM PROCESS-RECORDS
UNTIL DATA-REMAINS-SWITCH NO.
PROCESS-RECORDS. IF STU-CREDITS gt 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.
11Rejected for wrong major
JOHN ADAMS 090POLITICAL SCIAMELIA
EARHART 120AVIATIONORVILLE WRIGHT 115ENGINEER
INGGEORGIA OKEEFE 125ARTMERIWETHER
LEWIS 115TRAVELJOHN KENNEDY 115POLITICAL
SCIALEX BELL 090ENGINEERINGEMILY
DICKENSON 085LITERATUREJOHN REOBLING 115ENGINE
ERING
(a)Test Data
Rejected for insufficient credits
STUDENT NAME ORVILLE WRIGHT JOHN
ROEBLING
(b) Output
Figure 1.8 Test Data and Associated Output
12Table 1.2 Programmer-Supplied Names
PROGRAMMER-SUPPLIED NAME
EXPLANATION
- 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
13Table 1.3 Numeric Nonnumeric Literals
LITERAL
EXPLANATION
- 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
14TABLE 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 gt Greater than
lt Less than gt Greater than
or equal to lt Less than or equal to
15Figure 1.9 An Alternate Look at COBOL
41 PROCEDURE DIVISION. 42 PREPARE-SENIOR-RE
PORT. 43 OPEN INPUT STUDENT-FILE 44
OUTPUT PRINT-FILE. 45
PERFORM WRITE-HEADING-LINE. 46 PERFORM
UNTIL DATA-REMAINS-SWITCH NO 47
READ STUDENT-FILE 48 AT
END49 MOVE NO TO
DATA-REMAINS-SWITCH50 NOT AT
END51 PERFORM
PROCESS-RECORDS52 END-READ53
END-PERFORM.54 CLOSE
STUDENT-FILE55 PRINT-FILE.56
STOP RUN.57 58 WRITE-HEADING-LINE.
59 MOVE HEADING-LINE TO PRINT-LINE.60
WRITE PRINT-LINE.61 62
PROCESS-RECORDS.63 IF STU-CREDITS gt
110 AND STU-MAJOR ENGINEERING64
MOVE STU-NAME TO PRINT-NAME65
MOVE DETAIL-LINE TO PRINT-LINE66
WRITE PRINT-LINE67 END-IF.
Inline Perform
False condition branch
16End of Chapter 1