Skip to content

Commit 521f217

Browse files
committed
Add Additional Exercise to Lab 8.6: Count Clients from a Different State
Signed-off-by: Athar Ramzan <atharramzan.ofi@gmail.com>
1 parent 45ddbbb commit 521f217

File tree

3 files changed

+218
-0
lines changed

3 files changed

+218
-0
lines changed

COBOL Programming Course #2 - Learning COBOL/COBOL Programming Course #2 - Learning COBOL.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,6 +2726,53 @@ This lab requires two COBOL programs, CBL0006 and CBL0007, and two respective JC
27262726

27272727
![](Images/image155.png)
27282728

2729+
2730+
## Additional Exercise: Modify the Program to Count Clients from Another State
2731+
2732+
This exercise builds upon the existing COBOL program `CBL0006` and its corresponding JCL job `CBL0006J`. In the original program, logic was implemented to count clients from **Virginia** and display the total at the end of the report.
2733+
2734+
This exercise challenges you to modify the program to count clients from a different state instead of Virginia.
2735+
2736+
#### Objective
2737+
2738+
Your task is to understand how the current logic works in `CBL0006` to count clients from Virginia, and then modify the program to count clients from another state, such as **New York**.
2739+
2740+
**Prerequisites:** First examine `id.DATA` to identify available states. Use exact spelling and formatting.
2741+
2742+
#### Instructions
2743+
2744+
1. **Analyze the current implementation**
2745+
- Locate the Virginia state-checking condition in `CBL0006`
2746+
- Find where the client count is updated and displayed
2747+
2748+
2. **Modify `CBL0006`**
2749+
- Replace Virginia logic with your chosen state
2750+
- Update paragraph names, variables, and output display
2751+
2752+
**Note:** Multiple program sections require updates, not just the state name.
2753+
2754+
3. **Test your changes**
2755+
- Save and submit `CBL0006J`
2756+
- Verify successful compilation and correct output count
2757+
2758+
**Expected Output:** If you chose New York, the final line of your report should display:
2759+
2760+
![](Images/image0153.png)
2761+
2762+
2763+
#### Lab Hints
2764+
2765+
- Update WORKING-STORAGE variables, paragraph names, and output formatting
2766+
- Follow COBOL naming conventions
2767+
- Verify your chosen state exists in `id.DATA`
2768+
- Consider state name length for proper output formatting
2769+
2770+
#### Learning Objectives
2771+
2772+
This exercise develops skills in COBOL conditional processing, program structure analysis, and consistent code modification. The goal is building analytical abilities for reading and modifying existing COBOL programs, essential for legacy system maintenance.
2773+
2774+
**Need Help?** If you encounter difficulties, you can refer to the complete solution code `CBL0006C` available on the project’s [GitHub](https://github.com/openmainframeproject/cobol-programming-course/tree/master/COBOL%20Programming%20Course%20%233%20-%20Advanced%20Topics/Challenges/Debugging/cbl) repository.
2775+
27292776
\newpage
27302777

27312778
# Arithmetic expressions
81.5 KB
Loading
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
*-----------------------
2+
IDENTIFICATION DIVISION.
3+
*-----------------------
4+
PROGRAM-ID. CBL0006
5+
AUTHOR. Otto B. Boolean.
6+
*--------------------
7+
ENVIRONMENT DIVISION.
8+
*--------------------
9+
INPUT-OUTPUT SECTION.
10+
FILE-CONTROL.
11+
SELECT PRINT-LINE ASSIGN TO PRTLINE.
12+
SELECT ACCT-REC ASSIGN TO ACCTREC.
13+
*-------------
14+
DATA DIVISION.
15+
*-------------
16+
FILE SECTION.
17+
FD PRINT-LINE RECORDING MODE F.
18+
01 PRINT-REC.
19+
05 ACCT-NO-O PIC X(8).
20+
05 FILLER PIC X(02) VALUE SPACES.
21+
05 LAST-NAME-O PIC X(20).
22+
05 FILLER PIC X(02) VALUE SPACES.
23+
05 ACCT-LIMIT-O PIC $$,$$$,$$9.99.
24+
05 FILLER PIC X(02) VALUE SPACES.
25+
05 ACCT-BALANCE-O PIC $$,$$$,$$9.99.
26+
05 FILLER PIC X(02) VALUE SPACES.
27+
*
28+
FD ACCT-REC RECORDING MODE F.
29+
01 ACCT-FIELDS.
30+
05 ACCT-NO PIC X(8).
31+
05 ACCT-LIMIT PIC S9(7)V99 COMP-3.
32+
05 ACCT-BALANCE PIC S9(7)V99 COMP-3.
33+
05 LAST-NAME PIC X(20).
34+
05 FIRST-NAME PIC X(15).
35+
05 CLIENT-ADDR.
36+
10 STREET-ADDR PIC X(25).
37+
10 CITY-COUNTY PIC X(20).
38+
10 USA-STATE PIC X(15).
39+
05 RESERVED PIC X(7).
40+
05 COMMENTS PIC X(50).
41+
*
42+
WORKING-STORAGE SECTION.
43+
01 FLAGS.
44+
05 LASTREC PIC X VALUE SPACE.
45+
*
46+
* CHANGE 1: Modified variable structure to count New York clients
47+
* Original counted Virginia clients - now counts New York clients
48+
01 CLIENTS-PER-STATE.
49+
05 FILLER PIC X(19) VALUE
50+
'New York Clients = '.
51+
05 NEWYORK-CLIENTS PIC 9(3) VALUE ZERO.
52+
05 FILLER PIC X(59) VALUE SPACES.
53+
*
54+
01 HEADER-1.
55+
05 FILLER PIC X(20) VALUE 'Financial Report for'.
56+
05 FILLER PIC X(60) VALUE SPACES.
57+
*
58+
01 HEADER-2.
59+
05 FILLER PIC X(05) VALUE 'Year '.
60+
05 HDR-YR PIC 9(04).
61+
05 FILLER PIC X(02) VALUE SPACES.
62+
05 FILLER PIC X(06) VALUE 'Month '.
63+
05 HDR-MO PIC X(02).
64+
05 FILLER PIC X(02) VALUE SPACES.
65+
05 FILLER PIC X(04) VALUE 'Day '.
66+
05 HDR-DAY PIC X(02).
67+
05 FILLER PIC X(56) VALUE SPACES.
68+
*
69+
01 HEADER-3.
70+
05 FILLER PIC X(08) VALUE 'Account '.
71+
05 FILLER PIC X(02) VALUE SPACES.
72+
05 FILLER PIC X(10) VALUE 'Last Name '.
73+
05 FILLER PIC X(15) VALUE SPACES.
74+
05 FILLER PIC X(06) VALUE 'Limit '.
75+
05 FILLER PIC X(06) VALUE SPACES.
76+
05 FILLER PIC X(08) VALUE 'Balance '.
77+
05 FILLER PIC X(40) VALUE SPACES.
78+
*
79+
01 HEADER-4.
80+
05 FILLER PIC X(08) VALUE '--------'.
81+
05 FILLER PIC X(02) VALUE SPACES.
82+
05 FILLER PIC X(10) VALUE '----------'.
83+
05 FILLER PIC X(15) VALUE SPACES.
84+
05 FILLER PIC X(10) VALUE '----------'.
85+
05 FILLER PIC X(02) VALUE SPACES.
86+
05 FILLER PIC X(13) VALUE '-------------'.
87+
05 FILLER PIC X(40) VALUE SPACES.
88+
*
89+
01 WS-CURRENT-DATE-DATA.
90+
05 WS-CURRENT-DATE.
91+
10 WS-CURRENT-YEAR PIC 9(04).
92+
10 WS-CURRENT-MONTH PIC 9(02).
93+
10 WS-CURRENT-DAY PIC 9(02).
94+
05 WS-CURRENT-TIME.
95+
10 WS-CURRENT-HOUR PIC 9(02).
96+
10 WS-CURRENT-MINUTE PIC 9(02).
97+
10 WS-CURRENT-SECOND PIC 9(02).
98+
10 WS-CURRENT-CENTISECOND PIC 9(02).
99+
* This data layout is organized according to the ouput
100+
* format of the FUNCTION CURRENT-DATE.
101+
*
102+
*------------------
103+
PROCEDURE DIVISION.
104+
*------------------
105+
OPEN-FILES.
106+
OPEN INPUT ACCT-REC.
107+
OPEN OUTPUT PRINT-LINE.
108+
*
109+
WRITE-HEADERS.
110+
MOVE FUNCTION CURRENT-DATE TO WS-CURRENT-DATE-DATA.
111+
* The CURRENT-DATE function returns an alphanumeric value
112+
* that represents the calendar date and time of day
113+
* provided by the system on which the function is
114+
* evaluated.
115+
MOVE WS-CURRENT-YEAR TO HDR-YR.
116+
MOVE WS-CURRENT-MONTH TO HDR-MO.
117+
MOVE WS-CURRENT-DAY TO HDR-DAY.
118+
WRITE PRINT-REC FROM HEADER-1.
119+
WRITE PRINT-REC FROM HEADER-2.
120+
MOVE SPACES TO PRINT-REC.
121+
WRITE PRINT-REC AFTER ADVANCING 1 LINES.
122+
WRITE PRINT-REC FROM HEADER-3.
123+
WRITE PRINT-REC FROM HEADER-4.
124+
MOVE SPACES TO PRINT-REC.
125+
*
126+
READ-NEXT-RECORD.
127+
PERFORM READ-RECORD
128+
PERFORM UNTIL LASTREC = 'Y'
129+
* CHANGE 2: Updated paragraph name to reflect New York processing
130+
* Original was IS-STATE-VIRGINIA, now IS-STATE-NEWYORK
131+
PERFORM IS-STATE-NEWYORK
132+
PERFORM WRITE-RECORD
133+
PERFORM READ-RECORD
134+
END-PERFORM
135+
.
136+
*
137+
CLOSE-STOP.
138+
WRITE PRINT-REC FROM CLIENTS-PER-STATE.
139+
CLOSE ACCT-REC.
140+
CLOSE PRINT-LINE.
141+
GOBACK.
142+
*
143+
READ-RECORD.
144+
READ ACCT-REC
145+
AT END MOVE 'Y' TO LASTREC
146+
END-READ.
147+
*
148+
* CHANGE 3: Updated paragraph name and logic to check for New York
149+
* Original paragraph: IS-STATE-VIRGINIA
150+
* - Checked for 'Virginia' state
151+
* - Added to VIRGINIA-CLIENTS counter
152+
* Modified paragraph: IS-STATE-NEWYORK
153+
* - Now checks for 'New York' state
154+
* - Adds to NEWYORK-CLIENTS counter
155+
IS-STATE-NEWYORK.
156+
IF USA-STATE = 'New York' THEN
157+
ADD 1 TO NEWYORK-CLIENTS
158+
END-IF.
159+
* Boolean logic -- when the conditional expression
160+
* USA-STATE = 'New York' is true, the program
161+
* counts one more client from New York
162+
* Note -- the inclusion of the word THEN is optional
163+
* END-IF -- explicitly terminates the IF statement
164+
*
165+
WRITE-RECORD.
166+
MOVE ACCT-NO TO ACCT-NO-O.
167+
MOVE ACCT-LIMIT TO ACCT-LIMIT-O.
168+
MOVE ACCT-BALANCE TO ACCT-BALANCE-O.
169+
MOVE LAST-NAME TO LAST-NAME-O.
170+
WRITE PRINT-REC.
171+
*

0 commit comments

Comments
 (0)