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 GnuCOBOL 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:
- What is the size (in characters) of the StudentDetails record?
- What is the size of StudentName?
- What is the size of DateOfBirth?
- 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 |
------ STUDENT REPORT ------ MS. COUGHLAN DOB = 10-08-1985 SR. SMITH DOB = 01-28-1989 JM. Ryan DOB = 09-25-1986 etc.