Title: CS 313001Day 7
1CS 313-001 Day 7
- Chapter 3
- ENVIRONMENT and DATA DIVISIONS
2Todays Outline
- Handouts
- Roll
- CoE Labs Log in
- Lab Materials BRING ON MONDAY
- Report to the lab (120 Houser)
- Continue with LAB0
3(No Transcript)
4Lab Number 0
- Write a COBOL that will display the college wide
id, name, street address, city state, zip, and
classification of each student in the CS 313
computer science class during the Fall 2004.
5 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
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
7 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
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
8You will have mastered the material in Chapter 1
when you can
- Identify the advantages and disadvantages of
COBOL - Understand the difference between record
input/output and stream input/output - List the steps required by the programming
process - Name the logic structures used in a structured
program
9- Describe the top-down design and top-down
programming - Name the four divisions of a COBOL program
- Specify the purpose of each COBOL division
- Identify valid COBOL words
- Describe the format of a line of COBOL source code