31 0 2MB
EXERCISE SOLUTIONS
COBOL Programming for Business Success Micro Focus Education Services
EDUCATION IS PROGRESSIVE LEARNING WITH EXPERIENCE
Micro Focus Education Services The Lawn 22-30 Old Bath Rd Newbury Berkshire RG 14 1QN
This publication is protected by international copyright law. All rights reserved. No part of this publication may be reproduced, translated, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior permission of Micro Focus. Micro Focus and all Micro Focus products are either trademarks or registered trademarks of Micro Focus. Other product or company names mentioned herein may be the trademarks of their respective owners. © Copyright Micro Focus 2009 All rights reserved
Education Services
CBS-01-Introduction: Exercise 1 Solution The Code 1. The source code was supplied in the module exercise guide. Type the answer in or cut’n’paste if you can. The objective of the exercise was to get the Participant into COBOL mode and show some code early 2. The program name is PRG01. 3. There are – 5 sections.
Micro Focus
CBS-01-Introduction
3
1
Education Services
CBS-02-Program-Structure-: Exercise 1 Solution 1.
Sample program
IDENTIFICATION DIVISION . ENVIRONMENT DIVISION . CONFIGURATION SECTION . DATA DIVISION . FILE SECTION. WORKING-STORAGE SECTION. LINKAGE SECTION. PROCEDURE DIVISION .
Micro Focus
CBS-02-Program-Structure
4
1
Education Services
CBS-03-Data-Representation: Exercise 1 The Employee record 01
EMPLOYEE-RECORD. 03
EMPLOYEE-NAME. 05
EMPLOYEE-TITLE
PIC X(3).
05
EMPLOYEE-INITIALS
PIC X(4).
05
EMPLOYEE-SURNAME
PIC X(30).
03
EMPLOYEE-GENDER
03
EMPLOYEE-ADDRESS.
03
PIC X.
05
EMPLOYEE-ADDRESS-LINE1
PIC X(30).
05
EMPLOYEE-ADDRESS-LINE2
PIC X(30).
05
EMPLOYEE-ADDRESS-LINE3
PIC X(30).
05
EMPLOYEE-ADDRESS-LINE4
PIC X(30).
05
EMPLOYEE-POST-CODE
PIC X(8).
EMPLOYEE-SALARY PIC S9(5)V99.
Total length = 173 bytes
Micro Focus
CBS-03-Data-Representation
5
1
Education Services
CBS-03-Data-Representation: Exercise 2 Copyfile and COPY REPLACING statements exercises (WS.CPY) 01
TAG-NUMBERS . 03 TAG-NUM-1 03 TAG-NUM-2 03 TAG-NUM-3
PIC 9(4). PIC 9(6). PIC 9(5).
COPY WS.CPY REPLACING ==TAG== BY ==WS01==. 01
WS01-NUMBERS . 03 WS01-NUM-1 03 WS01-NUM-2 03 WS01-NUM-3
PIC 9(4). PIC 9(6). PIC 9(5).
COPY WS.CPY REPLACING ==TAG== BY ==INF==. 01
2
INF-NUMBERS . 03 INF-NUM-1 03 INF-NUM-2 03 INF-NUM-3
PIC 9(4). PIC 9(6). PIC 9(5).
CBS-03-Data-Representation
6
Micro Focus
Education Services
CBS-03-Data-Representation: Exercise 3 Initializing to Zero Initialization options are: a) Option would be MOVE ZEROES TO TAG-NUMBERS, WS01-NUMBERS, INF-NUMBERS.
b) Option could be each individual item could have a VALUE clause 03
WS01-NUM-1 PIC 9(4) VALUE ZEROES.
c) What must not be done is to move zeroes to the group field!
The result of using LOW-VALUES would be to place binary zeroes through a display field.
Micro Focus
CBS-03-Data-Representation
7
3
Education Services
CBS-04-Basic-Verbs: Exercise 1 Demonstration of PERFORM using Sections Source has been provided in Exercise Guide for comment and practice by participants.
CBS-04-Basic-Verbs: Exercise 2 Demonstration of PERFORM using Paragraphs Source has been provided in Exercise Guide for comment and practice by participants.
CBS-04-Basic-Verbs: Exercise 3 Demonstration of PERFORM using THRU syntax Source has been provided in Exercise Guide for comment and practice by participants. This is where multiple sections / paragraphs are used.
CBS-04-Basic-Verbs: Exercise 4 Demonstration of PERFORM using Embedded sentences Source has been provided in Exercise Guide for comment and practice by participants.
Micro Focus
CBS-04-Basic-Verbs
8
1
Education Services
CBS-04-Basic-Verbs: Exercise 5 Write a program to use PERFORM Source has been provided in Exercise Guide for comment and practice by participants.
WORKING-STORAGE SECTION . 01
WS-TIMES
PIC 99 .
01
WS-FIRST-NUMBER
PIC 9(4)V99 .
01
WS-SECOND-NUMBER
PIC 99V99 .
01
WS-RESULT
PIC 9(4).
PROCEDURE DIVISION . PROG . PERFORM INIT-PARA . PERFORM LOOP-PARA WS-TIMES TIMES . PERFORM END-PARA . INIT-PARA . DISPLAY "A simple dividing program" . DISPLAY "How many times shall we go round the loop?". ACCEPT WS-TIMES . IF WS-TIMES < 0 OR > 16 MOVE 5 TO WS-TIMES .
2
CBS-04-Basic-Verbs
9
Micro Focus
Education Services
LOOP-PARA . DISPLAY "First number?" . ACCEPT WS-FIRST-NUMBER . DISPLAY "Second number?" . ACCEPT WS-SECOND-NUMBER . IF WS-SECOND-NUMBER = 0 MOVE .01 TO WS-SECOND-NUMBER DISPLAY "Second number zero - replaced with .01". DIVIDE WS-FIRST-NUMBER BY WS-SECOND-NUMBER GIVING WS-RESULT ROUNDED . DISPLAY "Result is " WS-RESULT . END-PARA . DISPLAY "Division done " WS-TIMES " times" . DISPLAY "Many thanks!" . STOP RUN .
Micro Focus
CBS-04-Basic-Verbs
10
3
Education Services
CBS-05-Best-Practice: Exercise 1 1.
Organize the steps listed into a sequence similar to the following and adjusting where necessary: a. OPEN FILES b. INITIALIZE THE COUNTERS c.
READ FILE
d. IDENTIFY RECORD A e. SET UP OUTPUT RECORD - A f.
WRITE OUTPUT RECORD - A
g. IDENTIFY RECORD B h. INCREMENT TYPE B COUNTER
2.
i.
DISPLAY TYPE B COUNTER
j.
CLOSE FILES
k.
STOP RUN
Group each action as follows for structuring the PROG solution: PROG
INITIAL
MAIN
END
Process Record
Type “A”
Micro Focus
Type “B”
CBS-05-Best-Practice
11
1
Education Services
a. INITIAL will contain OPEN FILES, INITIALIZE THE COUNTERS, READ FILE b. MAIN will contain PROCESS RECORD processing c.
END will contain DISPLAY TYPE B COUNTER message, CLOSE FILES, STOP RUN
d. PROCESS RECORD will contain IDENTIFY RECORD A and IDENTIFY RECORD B types e. TYPE “A” will contain SET UP OUTPUT RECORD - A, WRITE OUTPUT RECORD – A, READ FILE for next record f.
TYPE “B” will contain INCREMENT TYPE “B” COUNTER, READ FILE for next record
3.
Once completed ensure that PROCESS RECORD is identified with an “*” for iteration.
4.
Once completed ensure that TYPE “A” and TYPE “B” are identified with an “” sequence.
2
CBS-05-Best-Practice
12
Micro Focus
Education Services
CBS-06-Handling-Sequential-Files: Exercise 1 Just comments and observations to be made on first exercise!
CBS-06-Handling-Sequential-Files: Exercise 2 Definition Overview. This is to be an exercise where the resolution of a problem is a program. The participants have been provided with a specification and can design and develop the application independently. Best practice, code structure and design, file handling techniques, data manipulation and general programming are the points to be considered. Solution Code ENVIRONMENT DIVISION . INPUT-OUTPUT SECTION . FILE-CONTROL . SELECT INFILE ASSIGN "INFILE.DAT" . SELECT OUTFILE-N ASSIGN "OUTFILEN.DAT" . SELECT OUTFILE-X ASSIGN "OUTFILEX.DAT" . DATA DIVISION . FILE SECTION . FD INFILE . 01 INREC-N . 03 INREC-TYPE 88 TYPE-N-RECORD 03 INREC-NAME 03 INREC-SALARY 03 INREC-EMP-NO-N 01 INREC-X . 03 03 INREC-EMP-NO-X 03 INREC-LEAVING-DATE
Micro Focus
PIC X . VALUE "N" . PIC X(20) . PIC 9(5)V99 . PIC 9(6) . PIC X . PIC 9(6) . PIC 9(8) .
CBS-06-Handling-Sequential-Files
13
1
Education Services FD 01
OUTFILE-N . OUTREC-N . 03 OUTREC-NUMBER 03 OUTREC-NAME 03 OUTREC-SALARY 03 OUTREC-EMP-NO-N FD OUTFILE-X . 01 OUTREC-X . 03 OUTREC-EMP-NO-X 03 OUTREC-LEAVING-DATE 01 OUTREC-X-LAST-REC . 03 OUTREC-X-REC-NUMBER WORKING-STORAGE SECTION .
PIC PIC PIC PIC
9(4) . X(20) . 9(5)V99 . 9(6) .
PIC 9(6) . PIC 9(8) . PIC 9(4) .
01
WS-NUMERICS COMP VALUE 03 WS-EOF-FLAG PIC 88 EOF VALUE 1 . 03 WS-N-REC-NUMBER PIC 03 WS-X-REC-NUMBER PIC PROCEDURE DIVISION . PROG . PERFORM INIT-PARA . PERFORM BOD-PARA . PERFORM END-PARA .
LOW-VALUES . 9 . 9(4) . 9(4) .
INIT-PARA . OPEN INPUT INFILE OUTPUT OUTFILE-N OUTFILE-X . DISPLAY "Program starting" . READ INFILE AT END SET EOF TO TRUE . BOD-PARA . PERFORM PROCESS-REC UNTIL EOF . END-PARA . MOVE WS-X-REC-NUMBER TO OUTREC-X-REC-NUMBER . *` WRITE OUTREC-X-LAST-REC . DISPLAY "All done!" . DISPLAY "Number of 'N' records processed: " WS-N-REC-NUMBER . DISPLAY "Number of 'X' records processed: " WS-X-REC-NUMBER . CLOSE INFILE OUTFILE-N OUTFILE-X . STOP RUN .
2
CBS-06-Handling-Sequential-Files
14
Micro Focus
Education Services
PROCESS-REC . IF TYPE-N-RECORD PERFORM N-REC-ACTIONS ELSE PERFORM X-REC-ACTIONS END-IF . N-REC-ACTIONS . ADD 1 TO WS-N-REC-NUMBER . MOVE WS-N-REC-NUMBER TO OUTREC-NUMBER . MOVE INREC-NAME TO OUTREC-NAME . MOVE INREC-SALARY TO OUTREC-SALARY . MOVE INREC-EMP-NO-N TO OUTREC-EMP-NO-N . WRITE OUTREC-N . READ INFILE AT END SET EOF TO TRUE . X-REC-ACTIONS . ADD 1 TO WS-X-REC-NUMBER . MOVE INREC-EMP-NO-X TO OUTREC-EMP-NO-X . MOVE INREC-LEAVING-DATE TO OUTREC-LEAVING-DATE . WRITE OUTREC-X . READ INFILE AT END SET EOF TO TRUE .
Micro Focus
CBS-06-Handling-Sequential-Files
15
3
Education Services
CBS-07-Decision-Logic: Exercise 2 ENVIRONMENT DIVISION . INPUT-OUTPUT SECTION . FILE-CONTROL . SELECT INFILE ASSIGN "INFILE.DAT" . SELECT OUTFILE-LOW ASSIGN "LOWSAL.DAT" . SELECT OUTFILE-MED ASSIGN "MEDSAL.DAT" . SELECT OUTFILE-RICH ASSIGN "BIGSALOUT.DAT" . DATA DIVISION . FILE SECTION . FD INFILE . 01 INREC . 03 IN-TYPE PIC X . 88 VALID-REC VALUE "A" THRU "C" "E" "J" "T" . 03 IN-NAME PIC X(20) . 03 IN-START-DATE PIC 9(8) . 03 IN-SALARY PIC 9(6)V99 . 88 LOW-SAL VALUE 0 THRU 24999.99 . 88 MED-SAL VALUE 25000 THRU 64999.99 . 88 RICH-DUDE VALUE 65000 THRU 999999.99 . FD OUTFILE-LOW . 01 OUTREC-LOW PIC X(37) . 01 OUTREC-LOW-SPECIAL PIC 9(04) . FD OUTFILE-MED . 01 OUTREC-MED PIC X(37) . 01 OUTREC-MED-SPECIAL PIC 9(04) . FD OUTFILE-RICH . 01 OUTREC-RICH PIC X(37) . 01 OUTREC-RICH-SPECIAL PIC 9(04) . WORKING-STORAGE SECTION . 01 WS-EOF PIC X VALUE "N" . 88 END-OF-FILE VALUE "Y" . 01 COUNTS COMP VALUE LOW-VALUES . 03 WS-LOW-COUNT PIC 9(4) . 03 WS-MED-COUNT PIC 9(4) . 03 WS-RICH-COUNT PIC 9(4) . 03 WS-INVALID-COUNT PIC 9(4) . PROCEDURE DIVISION . PROG .
Micro Focus
CBS-07-Decision-Logic
16
1
Decision Logic PERFORM INIT-PARA . PERFORM BOD-PARA . PERFORM END-PARA . INIT-PARA . DISPLAY "STARTING" . OPEN INPUT INFILE OUTPUT OUTFILE-LOW OUTFILE-MED OUTFILE-RICH . READ INFILE AT END SET END-OF-FILE TO TRUE . BOD-PARA . PERFORM PROCESS-REC UNTIL END-OF-FILE . END-PARA . DISPLAY "FINISHED" . DISPLAY "NUMBER OF LOW SALARIES: " WS-LOW-COUNT . DISPLAY "NUMBER OF MEDIUM SALARIES: " WS-MED-COUNT. DISPLAY "NUMBER OF HIGH SALARIES: " WS-RICH-COUNT . DISPLAY "NUMBER OF INVALID RECORDS: " WS-INVALID-COUNT . WRITE OUTREC-LOW-SPECIAL FROM WS-LOW-COUNT . WRITE OUTREC-MED-SPECIAL FROM WS-MED-COUNT . WRITE OUTREC-RICH-SPECIAL FROM WS-RICH-COUNT . CLOSE INFILE OUTFILE-LOW OUTFILE-MED OUTFILE-RICH . STOP RUN . PROCESS-REC . PERFORM REC-BOD . PERFORM REC-END . REC-BOD . IF VALID-REC AND IN-NAME UNEQUAL SPACES PERFORM VALID-RECORD ELSE PERFORM INVALID-RECORD END-IF . REC-END . READ INFILE AT END SET END-OF-FILE TO TRUE . VALID-RECORD . EVALUATE TRUE
2
CBS-07-Decision-Logic
17
Micro Focus
Education Services WHEN LOW-SAL ADD 1 TO WS-LOW-COUNT WRITE OUTREC-LOW FROM INREC WHEN MED-SAL ADD 1 TO WS-MED-COUNT WRITE OUTREC-MED FROM INREC WHEN RICH-DUDE ADD 1 TO WS-RICH-COUNT WRITE OUTREC-RICH FROM INREC END-EVALUATE . INVALID-RECORD . DISPLAY "THE FOLLOWING INPUT RECORD IS INVALID:" . DISPLAY INREC . ADD 1 TO WS-INVALID-COUNT .
Micro Focus
CBS-07-Decision-Logic
18
3
Education Services
CBS-08-Data-Manipulation: Exercise 3 ENVIRONMENT DIVISION . INPUT-OUTPUT SECTION . FILE-CONTROL . SELECT INFILE ASSIGN "INFILE.DAT" . DATA DIVISION . FD INFILE . 01 INREC . 03 REGION 88 VALID-REGION 88 88 88 88 03
PIC X . VALUE "N" "S" "E" "W" . VALUE "N" . VALUE "S" . VALUE "E" . VALUE "W" . PIC 9(6)V99 .
NORTH SOUTH EAST WEST IN-TOTAL
WORKING-STORAGE SECTION . 01 88 01
WS-EOF PIC 9 VALUE 0 . END-OF-FILE VALUE 1 . WS-NUMERICS VALUE ZERO . 03 WS-ALL-RECORDS PIC 9(5) . 03 WS-VALID-RECORDS PIC 9(5) . 03 WS-N-RECORDS PIC 9(4) . 03 WS-S-RECORDS PIC 9(4) . 03 WS-E-RECORDS PIC 9(4) . 03 WS-W-RECORDS PIC 9(4) . 03 WS-INVALID-RECORDS PIC 9(4) . 03 WS-GRAND-TOTAL PIC 9(11)V99 . 03 WS-N-TOTALPIC 9(10)V99 . 03 WS-S-TOTALPIC 9(10)V99 . 03 WS-E-TOTALPIC 9(10)V99 . 03 WS-W-TOTALPIC 9(10)V99 . 03 WS-OVERALL-AVERAGE PIC 9(6)V99 . 03 WS-N-AVERAGE PIC 9(6)V99 . 03 WS-S-AVERAGE PIC 9(6)V99 . 03 WS-E-AVERAGE PIC 9(6)V99 .
Micro Focus
CBS-08-Data-Manipulation
19
1
Data Manipulation
01
01
03 WS-W-AVERAGE PIC 03 WS-N-PERCENT PIC 03 WS-S-PERCENT PIC 03 WS-E-PERCENT PIC 03 WS-W-PERCENT PIC WS-EDITED-FIELDS . 03 WS-EDITED-GRAND-TOT PIC 03 WS-EDITED-N-TOT PIC 03 WS-EDITED-S-TOT PIC 03 WS-EDITED-E-TOT PIC 03 WS-EDITED-W-TOT PIC 03 WS-EDITED-OVERALLPIC 03 WS-EDITED-N PIC 03 WS-EDITED-S PIC 03 WS-EDITED-E PIC 03 WS-EDITED-W PIC 03 WS-EDITED-N-PERCENT PIC 03 WS-EDITED-S-PERCENT PIC 03 WS-EDITED-E-PERCENT PIC 03 WS-EDITED-W-PERCENT PIC WS-MESSAGE PIC
9(6)V99 . 99V99 . 99V99 . 99V99 . 99V99 .
Z(10)9.99 . Z(9)9.99 . Z(9)9.99 . Z(9)9.99 . Z(9)9.99 . Z(5)9.99 . Z(5)9.99 . Z(5)9.99 . Z(5)9.99 . Z(5)9.99 . Z9.99 . Z9.99 . Z9.99 . Z9.99 . X(80) .
PROCEDURE DIVISION . PROG-PARA . PERFORM INIT-PARA . PERFORM BOD-PARA . PERFORM END-PARA . INIT-PARA . DISPLAY "STARTING CALCULATION PROGRAM" . OPEN INPUT INFILE . READ INFILE AT END MOVE 1 TO WS-EOF . BOD-PARA . PERFORM PROCESS-REC UNTIL END-OF-FILE . END-PARA . MOVE WS-GRAND-TOTAL TO WS-EDITED-GRAND-TOT .
2
CBS-08-Data-Manipulation
20
Micro Focus
Education Services MOVE WS-N-TOTAL TO WS-EDITED-N-TOT . MOVE WS-S-TOTAL TO WS-EDITED-S-TOT . MOVE WS-E-TOTAL TO WS-EDITED-E-TOT . MOVE WS-W-TOTAL TO WS-EDITED-W-TOT . IF WS-VALID-RECORDS > 0 DIVIDE WS-GRAND-TOTAL BY WS-VALID-RECORDS GIVING WS-OVERALL-AVERAGE ROUNDED END-IF IF WS-N-RECORDS > 0 DIVIDE WS-N-TOTAL BY WS-N-RECORDS GIVING WS-N-AVERAGE ROUNDED END-IF IF WS-S-RECORDS > 0 DIVIDE WS-S-TOTAL BY WS-S-RECORDS GIVING WS-S-AVERAGE ROUNDED END-IF IF WS-E-RECORDS > 0 DIVIDE WS-E-TOTAL BY WS-E-RECORDS GIVING WS-E-AVERAGE ROUNDED END-IF IF WS-W-RECORDS > 0 DIVIDE WS-W-TOTAL BY WS-W-RECORDS GIVING WS-W-AVERAGE ROUNDED END-IF DISPLAY "TOTAL RECORDS READ: " WS-ALL-RECORDS . MOVE SPACES TO WS-MESSAGE . STRING "THESE COMPRISE " WS-N-RECORDS " N, " WS-S-RECORDS " S, " WS-E-RECORDS " E, " WS-W-RECORDS " W, " WS-INVALID-RECORDS " INVALID" INTO WS-MESSAGE . DISPLAY WS-MESSAGE . DISPLAY "GRAND SALES TOTAL: " WS-EDITED-GRAND-TOT . DISPLAY "NORTH SALES TOTAL: " WS-EDITED-N-TOT . DISPLAY "SOUTH SALES TOTAL: " WS-EDITED-S-TOT . DISPLAY "EAST SALES TOTAL: " WS-EDITED-E-TOT . DISPLAY "WEST SALES TOTAL: " WS-EDITED-W-TOT . MOVE WS-OVERALL-AVERAGE TO WS-EDITED-OVERALL . MOVE WS-N-AVERAGE TO WS-EDITED-N . MOVE WS-S-AVERAGE TO WS-EDITED-S .
Micro Focus
CBS-08-Data-Manipulation
21
3
Data Manipulation MOVE WS-E-AVERAGE TO WS-EDITED-E . MOVE WS-W-AVERAGE TO WS-EDITED-W . MOVE SPACES TO WS-MESSAGE . DISPLAY "OVERALL AVERAGE " WS-EDITED-OVERALL . DISPLAY "NORTH AVERAGE " WS-EDITED-N . DISPLAY "SOUTH AVERAGE " WS-EDITED-S . DISPLAY "EAST AVERAGE " WS-EDITED-E . DISPLAY "WEST AVERAGE " WS-EDITED-W . COMPUTE WS-N-PERCENT = WS-N-TOTAL / WS-GRAND-TOTAL * 100 . COMPUTE WS-S-PERCENT = WS-S-TOTAL / WS-GRAND-TOTAL * 100 . COMPUTE WS-E-PERCENT = WS-E-TOTAL / WS-GRAND-TOTAL * 100 . COMPUTE WS-W-PERCENT = WS-W-TOTAL / WS-GRAND-TOTAL * 100 . MOVE WS-N-PERCENT TO WS-EDITED-N-PERCENT . MOVE WS-S-PERCENT TO WS-EDITED-S-PERCENT . MOVE WS-E-PERCENT TO WS-EDITED-E-PERCENT . MOVE WS-W-PERCENT TO WS-EDITED-W-PERCENT . DISPLAY "NORTH PERCENTAGE OF TOTAL: " WS-EDITED-N-PERCENT "%" . DISPLAY "SOUTH PERCENTAGE OF TOTAL: " WS-EDITED-S-PERCENT "%" . DISPLAY "EAST PERCENTAGE OF TOTAL: " WS-EDITED-E-PERCENT "%" . DISPLAY "WEST PERCENTAGE OF TOTAL: " WS-EDITED-W-PERCENT "%" . CLOSE INFILE . STOP RUN . PROCESS-REC . PERFORM REC-STA . PERFORM REC-BOD . PERFORM REC-FIN . REC-STA . ADD 1 TO WS-ALL-RECORDS . REC-BOD . IF NOT VALID-REGION PERFORM INVALID-RECS ELSE PERFORM VALID-RECS . REC-FIN .
4
CBS-08-Data-Manipulation
22
Micro Focus
Education Services READ INFILE AT END MOVE 1 TO WS-EOF . INVALID-RECS . DISPLAY "INVALID RECORD " INREC . ADD 1 TO WS-INVALID-RECORDS . VALID-RECS . EVALUATE TRUE WHEN NORTH ADD 1 TO WS-N-RECORDS ADD IN-TOTAL TO WS-N-TOTAL WS-GRAND-TOTAL WHEN SOUTH ADD 1 TO WS-S-RECORDS ADD IN-TOTAL TO WS-S-TOTAL WS-GRAND-TOTAL WHEN EAST ADD 1 TO WS-E-RECORDS ADD IN-TOTAL TO WS-E-TOTAL WS-GRAND-TOTAL WHEN WEST ADD 1 TO WS-W-RECORDS ADD IN-TOTAL TO WS-W-TOTAL WS-GRAND-TOTAL END-EVALUATE . ADD 1 TO WS-VALID-RECORDS .
Micro Focus
CBS-08-Data-Manipulation
23
5
Data Manipulation
6
CBS-08-Data-Manipulation
24
Micro Focus
Education Services
CBS-09-Repeating-Data-: Exercise 4
ENVIRONMENT DIVISION . INPUT-OUTPUT SECTION . FILE-CONTROL . SELECT INFILE ASSIGN "INFILE.DAT" . DATA DIVISION . FILE SECTION . FD INFILE . 01 INREC . 03 IN-TYPE PIC X . 88 VALID-TYPE VALUE "A" "B" "C" "E" "J" "T" . 88 A-C VALUE "A" "C" . 88 B-E-T VALUE "B" "E" "T" . 88 J VALUE "J" . 03 IN-NAME PIC X(20) . 03 IN-START-DATE PIC 9(8) . 03 IN-SALES-DETS . 05 IN-SALES PIC 9(6)V99 OCCURS 12 . WORKING-STORAGE SECTION . 01 WS-DUMMY PIC X . 01 WS-EOF PIC 9 VALUE 0 . 88 NO-MORE-RECORDS VALUE 1. 01 WS-VALID-COUNTS COMP VALUE LOW-VALUES . 03 WS-A-C-COUNT PIC 9(4) . 03 WS-B-E-T-COUNT PIC 9(4) . 03 WS-J-COUNT PIC 9(4) . 01 WS-SALES-SUB PIC 99 . 01 WS-VALID-COUNT PIC 9(4) VALUE 0 . 01 WS-VALID-SUB PIC 9(4) VALUE 0 . 01 WS-VALID-RECS VALUE SPACES . 03 WS-VALID-DETS OCCURS 100 . 05 WS-TYPE PIC X . 05 WS-NAME PIC X(20) . 05 WS-START-DATE PIC 9(8) . 05 WS-SALES PIC 9(8)V99 .
Micro Focus
CBS-09-Repeating-Data
25
1
Handling Repeating Data PROCEDURE DIVISION . PROG . PERFORM INIT-PARA . PERFORM BOD-PARA . PERFORM END-PARA . INIT-PARA . DISPLAY "TABLE HANDLING PROGRAM STARTING" . OPEN INPUT INFILE . READ INFILE AT END MOVE 1 TO WS-EOF . BOD-PARA . PERFORM PROCESS-REC UNTIL NO-MORE-RECORDS . END-PARA . CLOSE INFILE . DISPLAY "END OF PROGRAM" . DISPLAY "NUMBER OF VALID A/C RECORDS " WS-A-C-COUNT . DISPLAY "NUMBER OF VALID B/E/T RECORDS " WS-B-E-T-COUNT . DISPLAY "NUMBER OF VALID J RECORDS " WS-J-COUNT . IF WS-VALID-SUB > 0 PERFORM DISPLAY-VALID-RECORDS END-IF STOP RUN . PROCESS-REC . PERFORM RECORD-BOD . PERFORM RECORD-FIN . RECORD-BOD . IF VALID-TYPE AND IN-NAME UNEQUAL SPACES PERFORM VALID-RECORD ELSE PERFORM INVALID-RECORD . RECORD-FIN . READ INFILE AT END MOVE 1 TO WS-EOF . VALID-RECORD . ADD 1 TO WS-VALID-SUB . IF WS-VALID-SUB > 100 DISPLAY "TOO MANY RECORDS TO PROCESS" CLOSE INFILE STOP RUN
2
CBS-09-Repeating-Data
26
Micro Focus
Education Services END-IF EVALUATE TRUE WHEN A-C ADD 1 TO WS-A-C-COUNT WHEN B-E-T ADD 1 TO WS-B-E-T-COUNT WHEN J ADD 1 TO WS-J-COUNT END-EVALUATE MOVE IN-TYPE TO WS-TYPE(WS-VALID-SUB) . MOVE IN-NAME TO WS-NAME(WS-VALID-SUB) . MOVE IN-START-DATE TO WS-START-DATE(WS-VALID-SUB) . MOVE 0 TO WS-SALES(WS-VALID-SUB) . PERFORM VARYING WS-SALES-SUB FROM 1 BY 1 UNTIL WS-SALES-SUB > 12 ADD IN-SALES(WS-SALES-SUB) TO WS-SALES(WS-VALID-SUB) END-PERFORM . INVALID-RECORD . DISPLAY "THE FOLLOWING RECORD IS INVALID:" . DISPLAY INREC . ACCEPT WS-DUMMY . DISPLAY-VALID-RECORDS . MOVE WS-VALID-SUB TO WS-VALID-COUNT . DISPLAY "NUMBER OF VALID RECORDS FOUND: " WS-VALID-SUB . DISPLAY "DETAILS:" . PERFORM VARYING WS-VALID-SUB FROM 1 BY 1 UNTIL WS-VALID-SUB > WS-VALID-COUNT DISPLAY WS-VALID-DETS(WS-VALID-SUB) END-PERFORM .
Micro Focus
CBS-09-Repeating-Data
27
3
Education Services
CBS-10-Printing-and Reports: Exercise 2 ENVIRONMENT DIVISION INPUT-OUTPUT SECTION FILE-CONTROL . SELECT INFILE SELECT PRINTFILE
. . ASSIGN "INFILE.DAT" . ASSIGN "OUTPRINT.TXT" ORGANIZATION IS LINE SEQUENTIAL .
DATA DIVISION . FILE SECTION . FD INFILE . 01 INREC . 03 IN-REGION PIC X . 03 IN-NAME PIC X(20) . 03 IN-SALES PIC 9(6)V99 . FD PRINTFILE . 01 PRINTREC PIC X(132) . WORKING-STORAGE SECTION . 01 WS-EDITED-DATE PIC 9999/99/99 . 01 WS-EOF PIC X(3) VALUE "NO" . 88 END-OF-FILE VALUE "YES" . 01 WS-REGION-TABLE . 03 PIC X(18) VALUE "EEASTERN NNORTHERN" . 03 PIC X(18) VALUE "SSOUTHERNWWESTERN " . 01 WS-REGION-TABLE-REDEF REDEFINES WS-REGION-TABLE . 03 WS-REG OCCURS 4 INDEXED BY REGION-IX ASCENDING KEY WS-LETTER . 05 WS-LETTER PIC X . 05 WS-REGION PIC X(8) . 01 WS-REGN VALUE LOW-VALUES . 03 WS-RG PIC X . 03 PIC X(7) . 01 WS-DATE PIC 9(8) . 01 WS-LINE-CNT PIC 99 VALUE 99 . 01 WS-PAGE-CNT PIC 99 VALUE 0 . 01 WS-RECORD-CNT PIC 9(4) VALUE 0 . 01 WS-TOTALS COMP VALUE LOW-VALUES . 03 WS-REGION-TOT PIC 9(8)V99 . 03 WS-GRAND-TOT
Micro Focus
CBS-10-Printing-and Reports
28
1
Printing and Report Programs PIC 9(10)V99 . WS-REGION-PERSON-CNT PIC 99 . 03 WS-TOTAL-PERSON-CNT PIC 99 . 03 WS-REGION-AVERAGE PIC 9(8)V99 . 03 WS-TOTAL-AVERAGE PIC 9(8)V99 . WS-HEADING-LINE . 03 PIC X(20) VALUE " REPORT DATED " . 03 WS-PRINT-DATE PIC 9999/99/99 . 03 PIC X(60) VALUE SPACES . 03 WS-PRINT-PAGE-CNT PIC Z9 . WS-REGION-START-LINE . 03 PIC X(8) VALUE "REGION:" . 03 WS-PRINT-REGION PIC X(8) . WS-DETAIL . 03 PIC X(20) VALUE SPACES . 03 WS-PRINT-NAME PIC X(40) . 03 WS-PRINT-SALES PIC ZZZ,ZZ9.99 . WS-SPACES PIC X(132) VALUE SPACES . WS-REGION-END-LINE . 03 PIC X(20) VALUE SPACES . 03 PIC X(37) VALUE "TOTALS FOR THIS REGION ARE " . 03 WS-PRINT-REGION-TOTAL PIC ZZ,ZZZ,ZZ9.99 . WS-REGION-END-LINE-2 . 03 PIC X(21) VALUE "REPS IN THIS REGION:" . 03 WS-PRINT-REGION-NO PIC Z9 . 03 PIC X(10) VALUE SPACES . 03 PIC X(24) VALUE "AVERAGE SALES PER REP:" . 03 WS-PRINT-REGION-AVERAGE PIC ZZ,ZZZ,ZZ9.99 . WS-FINAL-LINE . 03 PIC X(20) VALUE SPACES . 03
01
01
01
01 01
01
01
2
CBS-10-Printing-and Reports
29
Micro Focus
Education Services 03 03
PIC X(34) VALUE "GRAND TOTAL " . WS-PRINT-GRAND-TOTAL PIC Z,ZZZ,ZZZ,ZZ9.99 . 01 WS-FINAL-LINE-2 . 03 PIC X(22) VALUE "TOTAL NUMBER OF REPS:" . 03 WS-PRINT-TOTAL-NO PIC Z9 . 03 PIC X(9) VALUE SPACES . 03 PIC X(24) VALUE "AVERAGE SALES PER REP:" . 03 WS-PRINT-TOTAL-AVERAGE PIC ZZ,ZZZ,ZZ9.99 . PROCEDURE DIVISION . PROG . PERFORM INIT-PARA . PERFORM BOD-PARA . PERFORM END-PARA . INIT-PARA . DISPLAY "PRINT PROGRAM STARTING" . OPEN INPUT INFILE OUTPUT PRINTFILE . ACCEPT WS-DATE FROM DATE YYYYMMDD. MOVE WS-DATE TO WS-EDITED-DATE . DISPLAY "DATE IS " WS-EDITED-DATE . MOVE WS-DATE TO WS-PRINT-DATE . READ INFILE AT END MOVE "YES" TO WS-EOF . BOD-PARA . PERFORM PROCESS-REC UNTIL END-OF-FILE . END-PARA . IF WS-TOTAL-PERSON-CNT = 0 DISPLAY "NO RECORDS ON INPUT FILE!" . PERFORM END-OF-REGION . MOVE WS-GRAND-TOT TO WS-PRINT-GRAND-TOTAL . WRITE PRINTREC FROM WS-FINAL-LINE AFTER 4 . MOVE WS-TOTAL-PERSON-CNT TO WS-PRINT-TOTAL-NO . DIVIDE WS-GRAND-TOT BY WS-TOTAL-PERSON-CNT GIVING WS-TOTAL-AVERAGE . MOVE WS-TOTAL-AVERAGE TO WS-PRINT-TOTAL-AVERAGE . WRITE PRINTREC FROM WS-FINAL-LINE-2 AFTER 2 . CLOSE INFILE
Micro Focus
CBS-10-Printing-and Reports
30
3
Printing and Report Programs PRINTFILE . DISPLAY "PRINT PROGRAM ENDS" . STOP RUN . PROCESS-REC . IF WS-LINE-CNT > 45 PERFORM WRITE-HEADINGS . IF IN-REGION UNEQUAL WS-RG AND WS-REGN UNEQUAL LOW-VALUES PERFORM END-OF-REGION . IF IN-REGION UNEQUAL WS-RG PERFORM START-OF-REGION . ADD 1 TO WS-REGION-PERSON-CNT WS-TOTAL-PERSON-CNT . PERFORM WRITE-DETAIL . READ INFILE AT END MOVE "YES" TO WS-EOF . WRITE-HEADINGS . WRITE PRINTREC FROM WS-SPACES AFTER PAGE . ADD 1 TO WS-PAGE-CNT . MOVE WS-PAGE-CNT TO WS-PRINT-PAGE-CNT . WRITE PRINTREC FROM WS-HEADING-LINE AFTER 2 . MOVE 2 TO WS-LINE-CNT . IF WS-PAGE-CNT > 1 PERFORM START-OF-REGION . END-OF-REGION . MOVE WS-REGION-TOT TO WS-PRINT-REGION-TOTAL . WRITE PRINTREC FROM WS-REGION-END-LINE AFTER 3 . ADD 3 TO WS-LINE-CNT . MOVE WS-REGION-PERSON-CNT TO WS-PRINT-REGION-NO . DIVIDE WS-REGION-TOT BY WS-REGION-PERSON-CNT GIVING WS-REGION-AVERAGE ROUNDED . MOVE WS-REGION-AVERAGE TO WS-PRINT-REGION-AVERAGE . WRITE PRINTREC FROM WS-REGION-END-LINE-2 AFTER 2 . ADD 1 TO WS-LINE-CNT . MOVE 0 TO WS-REGION-TOT WS-REGION-PERSON-CNT . START-OF-REGION . SEARCH ALL WS-REG AT END DISPLAY "UNKNOWN REGION " IN-REGION CLOSE INFILE PRINTFILE STOP RUN
4
CBS-10-Printing-and Reports
31
Micro Focus
Education Services WHEN IN-REGION = WS-LETTER(REGION-IX) MOVE WS-REGION(REGION-IX) TO WS-PRINT-REGION . MOVE IN-REGION TO WS-REGN . WRITE PRINTREC FROM WS-REGION-START-LINE AFTER 4 . ADD 4 TO WS-LINE-CNT . WRITE-DETAIL . MOVE IN-NAME TO WS-PRINT-NAME . MOVE IN-SALES TO WS-PRINT-SALES . ADD IN-SALES TO WS-REGION-TOT WS-GRAND-TOT . WRITE PRINTREC FROM WS-DETAIL AFTER 1 . ADD 1 TO WS-LINE-CNT .
Micro Focus
CBS-10-Printing-and Reports
32
5
Education Services
CBS-11-Using Indexed files: Exercise 2 Notes The program separates each of the three tasks as much as possible. In the alternate key phase, the logic in ALT-KEY-BOD checks to make sure that we have not hit the end of the file while looking for ‘MILNE’ records. Even if we have, SEQ-STA will take ua back to the beginning of the file.
ENVIRONMENT DIVISION . INPUT-OUTPUT SECTION . FILE-CONTROL . SELECT CHANGES-FILE ASSIGN "CHANGES.DAT" . SELECT EMPLOYEE-FILE ASSIGN "ALTEMP.DAT" ORGANIZATION IS INDEXED ACCESS IS DYNAMIC RECORD KEY EMPLOYEE-NO ALTERNATE RECORD KEY EMPLOYEE-SURNAME WITH DUPLICATES . DATA DIVISION . FILE SECTION . FD CHANGES-FILE . 01 CHANGES-REC . 03 CHANGE-TYPE PIC X . 88 ADD-A-RECORD VALUE "A" . 88 CHANGE-A-RECORD VALUE "C" . 88 DELETE-A-RECORD VALUE "D" . 03 EMP-NO PIC X(8) . 03 EMP-INITS PIC X(4) . 03 EMP-SURNAME PIC X(16) . 03 EMP-SALARY PIC 9(6)V99 . 03 EMP-ADDRESS PIC X(40) . 03 EMP-DEPT PIC X(10) . FD EMPLOYEE-FILE . 01 EMPLOYEE-REC . 03 EMPLOYEE-NO PIC X(8) . 03 EMPLOYEE-INITS PIC X(4) . 03 EMPLOYEE-SURNAME PIC X(16) .
Micro Focus
CBS-11-Using Indexed files
33
1
Using Indexed Files 03 EMPLOYEE-SALARY PIC 9(6)V99 . 03 EMPLOYEE-ADDRESS PIC X(40) . 03 EMPLOYEE-DEPT PIC X(10) . WORKING-STORAGE SECTION . 01 WS-EOF-CHANGE PIC 9 VALUE 0 . 88 NO-MORE-CHANGES VALUE 1 . 01 WS-EOF-EMPLOYEE PIC 9 VALUE 0 . 88 NO-MORE-EMPLOYEES VALUE 1 . 01 WS-NO-RECORD-FOUND-FLAG PIC 9 . 88 RECORD-FOUND VALUE 0 . 01 WS-COUNTERS COMP VALUE LOW-VALUES . 03 WS-CHGES-REC-CNT PIC 9(4) . 03 WS-RECS-ADDED PIC 9(4) . 03 WS-RECS-CHANGED PIC 9(4) . 03 WS-RECS-DELETED PIC 9(4) . 03 WS-ALT-KEY-CNT PIC 9(4) . 03 WS-EMPLOYEE-CNT PIC 9(4) . 01
WS-KEY
PIC X .
PROCEDURE DIVISION . PROG . INIT-PARA . DISPLAY "COMPLEX INDEXED FILE PROGRAM STARTING" . OPEN INPUT CHANGES-FILE I-O EMPLOYEE-FILE . BOD-PARA . PERFORM RANDOM-ACTIONS . ACCEPT WS-KEY . PERFORM ALT-KEY-ACTIONS . ACCEPT WS-KEY . PERFORM SEQ-ACTIONS . ACCEPT WS-KEY . END-PARA . DISPLAY "PROGRAM CONCLUDES" . CLOSE CHANGES-FILE EMPLOYEE-FILE . STOP RUN . RANDOM-ACTIONS . PERFORM RANDOM-STA . PERFORM RANDOM-BOD .
2
CBS-11-Using Indexed files
34
Micro Focus
Education Services PERFORM RANDOM-FIN . RANDOM-STA . READ CHANGES-FILE AT END MOVE 1 TO WS-EOF-CHANGE . RANDOM-BOD . PERFORM PROCESS-CHANGES-REC UNTIL NO-MORE-CHANGES . RANDOM-FIN . DISPLAY "CHANGE RECORDS READ: " WS-CHGES-REC-CNT . DISPLAY "RECORDS ADDED: " WS-RECS-ADDED . DISPLAY "RECORDS CHANGED: " WS-RECS-CHANGED . DISPLAY "RECORDS DELETED: " WS-RECS-DELETED . PROCESS-CHANGES-REC . PERFORM RANDOM-REC-STA . PERFORM RANDOM-REC-BOD . PERFORM RANDOM-REC-FIN . RANDOM-REC-STA . ADD 1 TO WS-CHGES-REC-CNT . MOVE 0 TO WS-NO-RECORD-FOUND-FLAG . MOVE EMP-NO TO EMPLOYEE-NO . READ EMPLOYEE-FILE INVALID KEY MOVE 1 TO WS-NO-RECORD-FOUND-FLAG . RANDOM-REC-BOD . IF RECORD-FOUND PERFORM RANDOM-REC-FOUND ELSE PERFORM RANDOM-REC-NOT-FOUND . RANDOM-REC-FIN . READ CHANGES-FILE AT END MOVE 1 TO WS-EOF-CHANGE . RANDOM-REC-FOUND . EVALUATE TRUE WHEN ADD-A-RECORD PERFORM INVALID-ADD WHEN CHANGE-A-RECORD PERFORM VALID-CHANGE WHEN DELETE-A-RECORD PERFORM VALID-DELETE WHEN OTHER DISPLAY "INVALID TYPE " CHANGE-TYPE STOP RUN END-EVALUATE .
Micro Focus
CBS-11-Using Indexed files
35
3
Using Indexed Files RANDOM-REC-NOT-FOUND . EVALUATE TRUE WHEN ADD-A-RECORD PERFORM VALID-ADD WHEN CHANGE-A-RECORD PERFORM INVALID-CHANGE WHEN DELETE-A-RECORD PERFORM INVALID-DELETE WHEN OTHER DISPLAY "INVALID TYPE " CHANGE-TYPE STOP RUN END-EVALUATE . INVALID-ADD . DISPLAY "CANNOT ADD EXISTING RECORD " EMP-NO . DISPLAY CHANGES-REC . VALID-CHANGE . IF EMP-SALARY UNEQUAL ZERO MOVE EMP-SALARY TO EMPLOYEE-SALARY . IF EMP-ADDRESS UNEQUAL SPACES MOVE EMP-ADDRESS TO EMPLOYEE-ADDRESS . IF EMP-DEPT UNEQUAL SPACES MOVE EMP-DEPT TO EMPLOYEE-DEPT . REWRITE EMPLOYEE-REC . ADD 1 TO WS-RECS-CHANGED . VALID-DELETE . DELETE EMPLOYEE-FILE . ADD 1 TO WS-RECS-DELETED . VALID-ADD . MOVE EMP-INITS TO EMPLOYEE-INITS . MOVE EMP-SURNAME TO EMPLOYEE-SURNAME . MOVE EMP-SALARY TO EMPLOYEE-SALARY . MOVE EMP-ADDRESS TO EMPLOYEE-ADDRESS . MOVE EMP-DEPT TO EMPLOYEE-DEPT . WRITE EMPLOYEE-REC . ADD 1 TO WS-RECS-ADDED . INVALID-CHANGE . DISPLAY "CANNOT AMEND NON-EXISTENT RECORD " EMP-NO . DISPLAY CHANGES-REC . INVALID-DELETE . DISPLAY "CANNOT DELETE NON-EXISTENT RECORD " EMPLOYEE-NO .
4
CBS-11-Using Indexed files
36
Micro Focus
Education Services DISPLAY CHANGES-REC . ALT-KEY-ACTIONS . PERFORM ALT-KEY-STA . PERFORM ALT-KEY-BOD . PERFORM ALT-KEY-FIN . ALT-KEY-STA . MOVE "MILNE" TO EMPLOYEE-SURNAME . READ EMPLOYEE-FILE KEY IS EMPLOYEE-SURNAME INVALID KEY MOVE 1 TO WS-EOF-EMPLOYEE . ALT-KEY-BOD . PERFORM PROCESS-ALT-KEY-REC UNTIL NO-MORE-EMPLOYEES OR EMPLOYEE-SURNAME UNEQUAL "MILNE" . ALT-KEY-FIN. DISPLAY "NUMBER OF 'MILNE' RECORDS FOUND: " WS-ALT-KEY-CNT . PROCESS-ALT-KEY-REC . ADD 1 TO WS-ALT-KEY-CNT . DISPLAY EMPLOYEE-REC . READ EMPLOYEE-FILE NEXT AT END MOVE 1 TO WS-EOF-EMPLOYEE . SEQ-ACTIONS . PERFORM SEQ-STA . PERFORM SEQ-BOD. PERFORM SEQ-FIN . SEQ-STA . MOVE 0 TO WS-EOF-EMPLOYEE . MOVE LOW-VALUES TO EMPLOYEE-NO . START EMPLOYEE-FILE KEY NOT < EMPLOYEE-NO . READ EMPLOYEE-FILE NEXT AT END MOVE 1 TO WS-EOF-EMPLOYEE . SEQ-BOD . PERFORM PROCESS-SEQ-REC UNTIL NO-MORE-EMPLOYEES . SEQ-FIN . DISPLAY "TOTAL NUMBER OF RECORDS ON FILE: " WS-EMPLOYEE-CNT . PROCESS-SEQ-REC . ADD 1 TO WS-EMPLOYEE-CNT . DISPLAY EMPLOYEE-REC . READ EMPLOYEE-FILE NEXT AT END MOVE 1 TO WS-EOF-EMPLOYEE .
Micro Focus
CBS-11-Using Indexed files
37
5
Education Services
CBS-12-Modular-Programming: Exercise 2 Notes This is a calculator application, where the top level program ACCEPTs in two numbers, and an arithmetic symbol. The top program validates the symbol, and if it passes, the values go down to the subprogram. The subprogram attempts the calculation, returning one of three values depending on what happens. The top level program: WORKING-STORAGE SECTION . 01 WS-NUM-1 01 WS-NUM-2 01 WS-RESULT 01 WS-SYMBOL 88 VALID-SYMBOL 01 WS-FLAG 88 IT-DIDNT-WORK-MULTIPLY 88 IT-DIDNT-WORK-DIVIDE *> FLAG PRESET
PIC 9(4)V99 . PIC 9(4)V99 . PIC S9(7)V99 . PIC X . VALUE "+" "-" "/" "*" . PIC 9 . VALUE 1 . VALUE 2 . TO 0 IN CALC2
PROCEDURE DIVISION . DISPLAY "A FEEBLE CALCULATOR" . DISPLAY "FIRST NUMBER?" . ACCEPT WS-NUM-1 . DISPLAY "SECOND NUMBER?" . ACCEPT WS-NUM-2 . DISPLAY "SYMBOL ('+', '-', '/', '*')?" . ACCEPT WS-SYMBOL . IF NOT VALID-SYMBOL DISPLAY "WHAT AM I SUPPOSED TO DO WITH " WS-SYMBOL "?!" STOP RUN END-IF CALL "CALC2" USING WS-NUM-1 WS-NUM-2 WS-RESULT WS-SYMBOL WS-FLAG . EVALUATE TRUE
Micro Focus
CBS-12-Modular-Programming
38
1
Modular Programming WHEN IT-DIDNT-WORK-MULTIPLY DISPLAY "CAN'T MULTIPLY " WS-NUM-1 " AND " WS-NUM-2 WHEN IT-DIDNT-WORK-DIVIDE DISPLAY "CAN'T DIVIDE USING " WS-NUM-1 " AND " WS-NUM-2 WHEN OTHER DISPLAY WS-NUM-1 WS-SYMBOL WS-NUM-2 " = " WS-RESULT END-EVALUATE STOP RUN . The subprogram: LINKAGE SECTION . 01 LS-NUM-1 01 LS-NUM-2 01 LS-RESULT 01 LS-SYMBOL 88 MULTIPLIE 88 ADDD 88 SUBTRAKT 88 DIVYDE 01 LS-FLAG
PIC 9(4)V99 . PIC 9(4)V99 . PIC S9(7)V99 . PIC X . VALUE "*" . VALUE "+" . VALUE "-" . VALUE "/" . PIC 9 .
PROCEDURE DIVISION USING LS-NUM-1 LS-NUM-2 LS-RESULT LS-SYMBOL LS-FLAG . PARA . MOVE 0 TO LS-FLAG . EVALUATE TRUE WHEN ADDD COMPUTE LS-RESULT WHEN SUBTRAKT COMPUTE LS-RESULT WHEN MULTIPLIE COMPUTE LS-RESULT ON SIZE ERROR
2
= LS-NUM-1 + LS-NUM-2 = LS-NUM-1 - LS-NUM-2 = LS-NUM-1 * LS-NUM-2 MOVE 1 TO LS-FLAG
CBS-12-Modular-Programming
39
Micro Focus
Education Services END-COMPUTE WHEN DIVYDE COMPUTE LS-RESULT = LS-NUM-1 / LS-NUM-2 ON SIZE ERROR MOVE 2 TO LS-FLAG END-COMPUTE END-EVALUATE EXIT PROGRAM .
Micro Focus
CBS-12-Modular-Programming
40
3