Reading Sequential Files


READ, PERFORM .. UNTIL, DISPLAY

Introduction

The program SeqRead.Cbl reads a sequential file and displays the StudentId, StudentName and the CourseCode of each record in the file on the screen.   In this exercise you will re-write this program so that it displays the Student Initials, Surname and DateOfBirth on the screen.

Download the SeqRead.Cbl program and save it to the WorkArea directory on drive D:.

Download the data file Students.Dat and save it to the same place.

Load SeqRead.Cbl into the NetExpress environment.
 

Examining SeqRead

Examine the program carefully, paying particular attention to the way the end of file is handled.  Note the use of  the condition name EndOfStudentFile.

Compile the program. 

Set a breakpoint at the first statement in the Procedure Division (move the cursor over the statement, right-click and select Set Breakpoint from the menu which appears).
Use the Animator to step through the program.

Assign the variables StudentDetails, StudentName, Initials, DateOfBirth and MOBirth to the watch list (Right-click on the variable, select Examine from menu and then Add to list from dialogue box).

As the program runs attempt to answer the following questions:-

  1. What is the size (in characters) of the StudentDetails record?
  2. What is the size of StudentName?
  3. What is the size of DateOfBirth?
  4. The level number for MOBirth is 03 and that of DateOfBirth is 02.  What is the significance of that?  Examine the values in DateOfBirth and MOBirth as the program runs to see if your answer makes sense.

Amending SeqRead

Change the program SeqRead.Cbl to produce a program which displays the student Initials, Surname and DateOfBirth on the computer screen. The Initials should be immediately followed by a full stop and a space (see example run below). The date should be displayed in the US month, day, year format. The parts of the date should be separated from one another by a hyphen. The year should be the full four digits.

The student record consists of the following items;
Field
Type
Length
Value
Student Id
9
7
0-9999999
Student Name
.
.
Group
Surname
X
8
-
Initials
X
2
-
DateOfBirth
.
.
Group
Year
9
4
00-9999
Month
9
2
01-12
Day
9
2
01-31
Course Code
X
4
-
Gender
X
1
M/F
 
 

 


Back to COBOL Exercises page To COBOL Exercises Please fill out our evaluation form Evaluation Form Search the CSIS Web Site Search CSIS Web Site
Selectable Site Contents


Last updated : March 1998
e-mail : CSISwebeditor@ul.ie