CST8283 Final Exam Winter 2020: COBOL Code Solutions and Examples
VerifiedAdded on 2022/09/26
|7
|948
|21
Homework Assignment
AI Summary
This document presents the solutions to a CST8283 final exam, focusing on COBOL programming. The solutions cover several key areas, including the Data Division and Procedure Division. Question 1 requires the creation of a subscripted table for course records and the associated code for loading data from a file (CRS-FILE), including both the data division and procedure division code. Question 2 involves drafting Data Division Screen Section code for keyboard data entry. Question 3 requires the use of conditional statements to evaluate gas consumption. Question 4 involves validating data in a file and handling errors. Finally, Question 5 addresses modifying code to read from an indexed file using an alternate key (STUDENT-EMAIL) in addition to the primary key (STUDENT-NUMBER). The solutions provided include data structures, file handling techniques, and conditional logic, demonstrating a comprehensive understanding of COBOL programming principles.

CST8283 FINAL EXAM WINTER 2020
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
INSTRUCTIONS
Draft your code responses to these questions directly in this WORD document. You do not need to use
Eclipse or the COBOL software. This document is a WORD document so code your responses in text.
=====================================================================================
Question 1
Write the Data Division code that would declare a subscripted Table for 300 courses where each record
has the structure described below.
a) Draft the Procedure Division code that would load the table from the file called CRS-FILE. The
module that would load the individual record into the table will be called LOAD-CRS-RECORD. Code both
that module and the statements controlling (performing) that module.
b) Code the search module and the code that would control (perform) the search module given a search
argument (value) that is already in the field called CRS-ID.
The description of the record on the file (CRS-FILE)
01 COURSE-RECORD.
05 COURSE--ID PIC X(7).
05 COURSE-NAME PIX X(25).
05 PROGRAM-ID PIC X(5).
Program:
DATA DIVISION.
FILE SECTION.
FD CRS-FILE.
RECORD CONTAINS 37 CHARACTERS
DATA RECORD IS LOAD-CRS-RECORD.
01 LOAD-CRS-RECORD.
05 COURSE--ID PIC X(07).
05 COURSE-NAME PIC X(25).
05 PROGRAM-ID PIC X(5).
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
INSTRUCTIONS
Draft your code responses to these questions directly in this WORD document. You do not need to use
Eclipse or the COBOL software. This document is a WORD document so code your responses in text.
=====================================================================================
Question 1
Write the Data Division code that would declare a subscripted Table for 300 courses where each record
has the structure described below.
a) Draft the Procedure Division code that would load the table from the file called CRS-FILE. The
module that would load the individual record into the table will be called LOAD-CRS-RECORD. Code both
that module and the statements controlling (performing) that module.
b) Code the search module and the code that would control (perform) the search module given a search
argument (value) that is already in the field called CRS-ID.
The description of the record on the file (CRS-FILE)
01 COURSE-RECORD.
05 COURSE--ID PIC X(7).
05 COURSE-NAME PIX X(25).
05 PROGRAM-ID PIC X(5).
Program:
DATA DIVISION.
FILE SECTION.
FD CRS-FILE.
RECORD CONTAINS 37 CHARACTERS
DATA RECORD IS LOAD-CRS-RECORD.
01 LOAD-CRS-RECORD.
05 COURSE--ID PIC X(07).
05 COURSE-NAME PIC X(25).
05 PROGRAM-ID PIC X(5).
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

CST8283 FINAL EXAM WINTER 2020
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
PROCEDURE DIVISION.
Begin.
OPEN INPUT CRS-FILE.
READ CRS-FILE
AT END MOVE HIGH-VALUES TO LOAD-CRS-RECORD
END-READ
PERFORM UNTIL LOAD-CRS-RECORD = HIGH-VALUES
IF COURSE—ID= CRS-ID
DISPLAY “RECORD FOUND”
END-IF
READ CRS-FILE
AT END MOVE HIGH-VALUES TO LOAD-CRS-RECORD
END-READ
END-PERFORM
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
PROCEDURE DIVISION.
Begin.
OPEN INPUT CRS-FILE.
READ CRS-FILE
AT END MOVE HIGH-VALUES TO LOAD-CRS-RECORD
END-READ
PERFORM UNTIL LOAD-CRS-RECORD = HIGH-VALUES
IF COURSE—ID= CRS-ID
DISPLAY “RECORD FOUND”
END-IF
READ CRS-FILE
AT END MOVE HIGH-VALUES TO LOAD-CRS-RECORD
END-READ
END-PERFORM

CST8283 FINAL EXAM WINTER 2020
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
Question 2
Draft the Data Division Screen Section code that will allow the entry of data at the keyboard for two
fields (Student Number and a Student Course). Code an appropriate prompt message for each field.
The data on the screen needs to be stored in fields already described in Working-Storage as
STUDENT-NUMBER PIC 9(9) and STUDENT-COURSE PIC X(7).
Program:
DATA DIVISION.
FILE SECTION.
FD STUDENT-RECORD.
RECORD CONTAINS 16 CHARACTERS
DATA RECORD IS LOAD-STUDENT-RECORD.
01 LOAD-STUDENT-RECORD.
05 STUDENT-NUMBER-IN PIC 9(09).
05 STUDENT-COURSE-IN PIC X(7).
WORKING-STORAGE SECTION.
01 STUDENT-NUMBER PIC 9(9).
01 STUDENT-COURSE PIC X(7).
PROCEDURE DIVISION.
DISPLAY “ENTER STUDENT ID”
ACCEPT STUDENT-NUMBER
DISPLAY “ENTER STUDENT COURSE”
ACCEPT STUDENT-COURSE
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
Question 2
Draft the Data Division Screen Section code that will allow the entry of data at the keyboard for two
fields (Student Number and a Student Course). Code an appropriate prompt message for each field.
The data on the screen needs to be stored in fields already described in Working-Storage as
STUDENT-NUMBER PIC 9(9) and STUDENT-COURSE PIC X(7).
Program:
DATA DIVISION.
FILE SECTION.
FD STUDENT-RECORD.
RECORD CONTAINS 16 CHARACTERS
DATA RECORD IS LOAD-STUDENT-RECORD.
01 LOAD-STUDENT-RECORD.
05 STUDENT-NUMBER-IN PIC 9(09).
05 STUDENT-COURSE-IN PIC X(7).
WORKING-STORAGE SECTION.
01 STUDENT-NUMBER PIC 9(9).
01 STUDENT-COURSE PIC X(7).
PROCEDURE DIVISION.
DISPLAY “ENTER STUDENT ID”
ACCEPT STUDENT-NUMBER
DISPLAY “ENTER STUDENT COURSE”
ACCEPT STUDENT-COURSE
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

CST8283 FINAL EXAM WINTER 2020
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
MOVE STUDENT-NUMBER TO STUDENT-NUMBER-IN
MOVE STUDENT-COURSE TO STUDENT-COURSE-IN
STOP.
Question 3
Using the record structure below, draft the Condition Names that would apply given the ranges
described.
01 CAR-RECORD.
05 CAR-ID PIC X(5).
05 GAS-CONSUMPTION PIC 9(2).
If the GAS-CONSUMPTION is between 1 and 5 gas consumption is GOOD. If GAS-CONSUMPTION is
greater than 5, then gas consumption is POOR.
Draft three different conditional statement structures that would display on the monitor the phrase
GOOD or POOR depending on the ranges given above. One of the three must use a Case Structure.
PROGRAM:
PROCEDURE DIVISION.
MAIN PARA.
EVALUATE TRUE ALSO TRUE
WHEN GAS-CONSUMPTION >0 ALSO GAS-CONSUMPTION<6
DISPLAY “GOOD”
WHEN GAS-CONSUMPTION >0 ALSO GAS-CONSUMPTION>5
DISPLAY “POOR”
WHEN GAS-CONSUMPTION <0
DISPLAY “WRONG INPUT”
END-EVALUATE.
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
MOVE STUDENT-NUMBER TO STUDENT-NUMBER-IN
MOVE STUDENT-COURSE TO STUDENT-COURSE-IN
STOP.
Question 3
Using the record structure below, draft the Condition Names that would apply given the ranges
described.
01 CAR-RECORD.
05 CAR-ID PIC X(5).
05 GAS-CONSUMPTION PIC 9(2).
If the GAS-CONSUMPTION is between 1 and 5 gas consumption is GOOD. If GAS-CONSUMPTION is
greater than 5, then gas consumption is POOR.
Draft three different conditional statement structures that would display on the monitor the phrase
GOOD or POOR depending on the ranges given above. One of the three must use a Case Structure.
PROGRAM:
PROCEDURE DIVISION.
MAIN PARA.
EVALUATE TRUE ALSO TRUE
WHEN GAS-CONSUMPTION >0 ALSO GAS-CONSUMPTION<6
DISPLAY “GOOD”
WHEN GAS-CONSUMPTION >0 ALSO GAS-CONSUMPTION>5
DISPLAY “POOR”
WHEN GAS-CONSUMPTION <0
DISPLAY “WRONG INPUT”
END-EVALUATE.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

CST8283 FINAL EXAM WINTER 2020
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
Question 4
A record is read in from a file that has the following structure.
01 PAY-RECORD.
05 EMPLOYEE-NUMBER PIC 9(5).
05 WORK-HOURS PIC 9(2).
05 DEPARTMENT-ID PIC A(3).
Draft the Procedure Division code that would validate whether there are valid numeric or alphabetic
values in the declared fields. If values are not valid, a procedure (module) called ERROR-RTN should be
executed. That procedure has already been coded.
PROCEDURE DIVISION.
MAIN-PROCEDURE.
OPEN INPUT PAY-FILE.
READ PAY-FILE
AT END MOVE HIGH-VALUES TO PAY-RECORD
END-READ
PERFORM UNTIL PAY-RECORD = HIGH-VALUES
IF EMPLOYEE-NUMBER IS NUMERIC
DISPLAY “NUMERIC FIELD”
ELSE
PERFORM ERROR-RTN
END IF
IF WORK-HOURS IS NUMERIC
DISPLAY “NUMERIC FIELD”
ELSE
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
Question 4
A record is read in from a file that has the following structure.
01 PAY-RECORD.
05 EMPLOYEE-NUMBER PIC 9(5).
05 WORK-HOURS PIC 9(2).
05 DEPARTMENT-ID PIC A(3).
Draft the Procedure Division code that would validate whether there are valid numeric or alphabetic
values in the declared fields. If values are not valid, a procedure (module) called ERROR-RTN should be
executed. That procedure has already been coded.
PROCEDURE DIVISION.
MAIN-PROCEDURE.
OPEN INPUT PAY-FILE.
READ PAY-FILE
AT END MOVE HIGH-VALUES TO PAY-RECORD
END-READ
PERFORM UNTIL PAY-RECORD = HIGH-VALUES
IF EMPLOYEE-NUMBER IS NUMERIC
DISPLAY “NUMERIC FIELD”
ELSE
PERFORM ERROR-RTN
END IF
IF WORK-HOURS IS NUMERIC
DISPLAY “NUMERIC FIELD”
ELSE

CST8283 FINAL EXAM WINTER 2020
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
PERFORM ERROR-RTN
END IF
IF DEPARTMENT-ID IS NUMERIC
PERFORM ERROR-RTN
ELSE
DISPLAY “NUMERIC FIELD”
END IF
READ PAY-FILE
AT END MOVE HIGH-VALUES TO PAY-RECORD
END-READ
END-PERFORM
CLOSE PAY-FILE.
STOP RUN.
Question 5
Given the code below, modify the code to allow another key field, other than the primary key, by which
a record from the Indexed file can be read. The other key field is STUDENT-EMAIL and will have a unique
value for each of the records on the file.
Given your modification, code the Procedure Division instructions that will read a record from the file
using the STUDENT-EMAIL as the key field.
PROGRAM:
SELECT STUDENT-FILE
ASSIGN TO “C:\STU-FILE”
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS STUDENT-NUMBER.
ALTERNATE RECORD KEY IS STUDENT-EMAIL
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
PERFORM ERROR-RTN
END IF
IF DEPARTMENT-ID IS NUMERIC
PERFORM ERROR-RTN
ELSE
DISPLAY “NUMERIC FIELD”
END IF
READ PAY-FILE
AT END MOVE HIGH-VALUES TO PAY-RECORD
END-READ
END-PERFORM
CLOSE PAY-FILE.
STOP RUN.
Question 5
Given the code below, modify the code to allow another key field, other than the primary key, by which
a record from the Indexed file can be read. The other key field is STUDENT-EMAIL and will have a unique
value for each of the records on the file.
Given your modification, code the Procedure Division instructions that will read a record from the file
using the STUDENT-EMAIL as the key field.
PROGRAM:
SELECT STUDENT-FILE
ASSIGN TO “C:\STU-FILE”
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS STUDENT-NUMBER.
ALTERNATE RECORD KEY IS STUDENT-EMAIL
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

CST8283 FINAL EXAM WINTER 2020
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
DATA DIVISION.
FILE SECTION.
FD STUDENT-FILE.
01 STUDENT-RECORD.
05 STUDENT-NUMBER PIC 9(7).
05 STUDENT-NAME PIC X(30).
05 STUDENT-EMAIL PIC X(20).
PROCEDURE DIVISION.
MAIN-PROCEDURE.
DISPLAY “STUDENT EMAIL”
ACCEPT STUDENT-EMAIL
READ STUDENT-FILE
KEY IS STUDENT-EMAIL
DISPLAY STUDENT-NUMBER SPACE STUDENT-NAME SPACE STUDENT-EMAIL
INVALID KEY
DISPLAY ’NO RECORD FOUND’
STOP RUN
END-READ
STUDENT NAME ___________________________________ STUDENT NUMBER ____________
( type in your name and student number)
DATA DIVISION.
FILE SECTION.
FD STUDENT-FILE.
01 STUDENT-RECORD.
05 STUDENT-NUMBER PIC 9(7).
05 STUDENT-NAME PIC X(30).
05 STUDENT-EMAIL PIC X(20).
PROCEDURE DIVISION.
MAIN-PROCEDURE.
DISPLAY “STUDENT EMAIL”
ACCEPT STUDENT-EMAIL
READ STUDENT-FILE
KEY IS STUDENT-EMAIL
DISPLAY STUDENT-NUMBER SPACE STUDENT-NAME SPACE STUDENT-EMAIL
INVALID KEY
DISPLAY ’NO RECORD FOUND’
STOP RUN
END-READ
1 out of 7
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.

