I have tried looking this up online but I can't find anything that matches my situation. I need to suppress the leading zeros in the output but I can't get it working correctly. The number I need to suppress is the PR-PAY-RATE.
******************************************************************
ID DIVISION.
PROGRAM-ID. LAB5
AUTHOR. asdf.
DATE-WRITTEN. March 25, 2014.
DATE-COMPILED. CURRENT-DATE.
******************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PAYROLL-FILE ASSIGN TO PAYIN
ORGANIZATION IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD PAYROLL-FILE.
**** Payroll Record Length 360 characters ************************
01 PAYROLL-RECORD.
05 PR-EMPLOYEE-ID PIC X(07).
05 PR-LAST-NAME PIC X(26).
05 PR-FIRST-NAME PIC X(15).
05 PR-DIVISION PIC X(10).
05 PR-GROUP PIC X(10).
05 PR-DEPARTMENT PIC X(10).
05 PR-TITLE PIC X(20).
05 PR-ADDRESS1 PIC X(30).
05 PR-ADDRESS2 PIC X(30).
05 PR-CITY PIC X(30).
05 PR-STATE PIC X(2).
05 PR-PROVINCE PIC X(20).
05 PR-COUNTRY PIC X(20).
05 PR-ZIP-POSTAL PIC X(09).
05 PR-PAY1-STATUS PIC X(01).
88 PR-STAT-ACTIVE VALUE 'A'.
88 PR-STAT-TERMINATED VALUE 'T'.
88 PR-STAT-RETIRED VALUE 'R'.
88 PR-STAT-DISCHARGED VALUE 'D'.
05 PR-START-DT PIC 9(08).
05 PR-TERM-DT PIC 9(08).
05 PR-TERM-REASON PIC X(30).
05 PR-PAY-RATE PIC 9(9)V99.
05 PR-PAY-CYCLE PIC X(01).
88 PR-HOURLY VALUE 'H'.
88 PR-BIWEEKLY VALUE 'B'.
88 PR-YEARLY VALUE 'R'.
05 PR-LAST-INCREASE-DT PIC 9(08).
05 PR-LAST-EVAL-DT PIC 9(08).
05 PR-LAST-EVAL-RATING PIC X(01).
88 PR-RATE-A VALUE 'A'.
88 PR-RATE-B VALUE 'B'.
88 PR-RATE-C VALUE 'C'.
88 PR-RATE-D VALUE 'D'.
88 PR-RATE-N VALUE 'N'.
05 PR-BENEFIT-FLAG PIC X(01).
88 PR-BENEFIT-YES VALUE 'Y'.
88 PR-BENEFIT-NO VALUE 'N'.
05 PR-MEDICAL-FLAG PIC X(01).
88 PR-MEDICAL-YES VALUE 'Y'.
88 PR-MEDICAL-NO VALUE 'N'.
05 PR-DENTAL-FLAG PIC X(01).
88 PR-DENTAL-YES VALUE 'Y'.
88 PR-DENTAL-NO VALUE 'N'.
05 PR-VISION-FLAG PIC X(01).
88 PR-VISION-YES VALUE 'Y'.
88 PR-VISION-NO VALUE 'N'.
05 PR-BENEFIT-COST-YR PIC 9(9)V99.
05 PIC X(30).
**** End of Payroll Record ***************************************
WORKING-STORAGE SECTION.
01 WS-NAMED-MEMORY-LOCATIONS.
05 EOF-SWITCH PIC X VALUE 'N'.
88 EOF VALUE 'Y'.
88 NOT-EOF VALUE 'N'.
05 PAYROLL-COUNT PIC 9(5).
05 EMP-SELECTED PIC 9(9)V99.
05 TOTAL-PAY PIC 9(9)V99.
05 AVG-PAY PIC 9(9)V99.
******************************************************************
PROCEDURE DIVISION.
100-MAIN-PROGRAM.
PERFORM 200-DISPLAY-SPLASH-PAGE.
PERFORM 300-OPEN-FILES.
PERFORM 400-READ-PAYROLL-FILE UNTIL EOF.
PERFORM 700-END-PROGRAM.
STOP RUN.
200-DISPLAY-SPLASH-PAGE.
DISPLAY '**************************************************'.
DISPLAY '* asdf ENTERPRISE TECHNOLOGIES LAB5 *'.
DISPLAY '* asdf *'.
DISPLAY '* March 25, 2014 *'.
DISPLAY '**************************************************'.
300-OPEN-FILES.
OPEN INPUT PAYROLL-FILE.
400-READ-PAYROLL-FILE.
READ PAYROLL-FILE
AT END MOVE 'Y' TO EOF-SWITCH.
IF EOF
THEN PERFORM 700-END-PROGRAM.
IF NOT-EOF
PERFORM 500-PROCESS-PAYROLL-RECORDS
END-IF.
500-PROCESS-PAYROLL-RECORDS.
ADD 1 TO PAYROLL-COUNT.
IF PR-PAY1-STATUS = 'A' AND PR-PAY-CYCLE = 'B'
THEN PERFORM 600-DISPLAY-PAYROLL-DATA.
600-DISPLAY-PAYROLL-DATA.
DISPLAY 'Employee ID : ' PR-EMPLOYEE-ID.
DISPLAY 'Employee First Name: ' PR-FIRST-NAME.
DISPLAY 'Employee Last Name: ' PR-LAST-NAME.
DISPLAY 'Pay Status : ' PR-PAY1-STATUS.
DISPLAY 'Pay Cycle : ' PR-Pay-Cycle.
DISPLAY 'Pay Rate : ' PR-Pay-Rate.
DISPLAY '******************************************'.
ADD 1 TO EMP-SELECTED.
ADD PR-PAY-RATE TO TOTAL-PAY GIVING TOTAL-PAY.
COMPUTE AVG-PAY = TOTAL-PAY / EMP-SELECTED.
700-END-PROGRAM.
DISPLAY 'Total Payroll Recs : ' PAYROLL-COUNT.
DISPLAY 'Employees Selected : ' EMP-SELECTED.
DISPLAY 'Total Pay : ' TOTAL-PAY.
DISPLAY 'Average Pay : ' AVG-PAY.
DISPLAY '******************************************'.
DISPLAY '* End of LAB5 *'.
DISPLAY '******************************************'.
CLOSE PAYROLL-FILE.
STOP RUN.
In W-S
05 FORMATTED-INTEGER PIC Z(04)9.
05 FORMATTED-CURRENCY PIC Z(08)9.99.
in 700
DISPLAY 'Total Payroll Recs : ' PAYROLL-COUNT.
becomes
MOVE PAYROLL-COUNT TO FORMATTED-INTEGER.
DISPLAY 'Total Payroll Recs : ' FORMATTED-INTEGER.
and follow the bouncing ball for the other display items.
MOVE TO /DISPLAY FORMATTED-CURRENCY if that's appropriate.
(and of course, identifier names are your choice). Also your choice to use a PIC of Z(02),Z(03),Z(02)9.99. if you want thousand-separator commas.
BTW - you call 700 twice - once at end-of-file, then again from the mainline. This will give you the display twice and probably an error too, sice you will be attempting to close a closed file.
Related
I'm pretty new to Cobol, and got stuck trying to create something like a python dictionary, where we pass a key and the dictionary returns its value.
Python example:
>>> dict
{'AC': 'Acre', 'AL': 'Alagoas', 'AP': 'Amapa'}
>>> dict['AC']
'Acre'
I'm trying to do this in cobol, using redefines to create two arrays (one for the keys, other for the values).
I already created the arrays, but got stucked to associate these two arrays in a key-value function, once I can only access an array with integer values.
Here goes my data division, if someone can help with code samples.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 WRK-KEYS.
02 FILLER PIC X(2) VALUE "AC".
02 FILLER PIC X(2) VALUE "AL".
02 FILLER PIC X(2) VALUE "AP".
01 WRK-TABLE-KEYS REDEFINES WRK-KEYS.
02 WRK-KEY PIC X(2) OCCURS 3 TIMES.
01 WRK-VALUES.
02 FILLER PIC X(19) VALUE "Acre".
02 FILLER PIC X(19) VALUE "Alagoas".
02 FILLER PIC X(19) VALUE "Amapa".
01 WRK-TABLE-VALUES REDEFINES WRK-VALUES.
02 WRK-VALUE PIC X(10) OCCURS 3 TIMES.
You can use a table, as shown in the example below:
IDENTIFICATION DIVISION.
PROGRAM-ID. STATES.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 STATES-TABLE.
05 FILLER PIC X(2) VALUE "AC".
05 FILLER PIC X(7) VALUE "Acre ".
05 FILLER PIC X(2) VALUE "AL".
05 FILLER PIC X(7) VALUE "Alagoas".
05 FILLER PIC X(2) VALUE "AP".
05 FILLER PIC X(7) VALUE "Amapá ".
01 RDF-STATES-TABLE REDEFINES STATES-TABLE.
05 STATE-GROUP OCCURS 3 TIMES.
10 STATE-CODE PIC X(2).
10 STATE-NAME PIC X(7).
PROCEDURE DIVISION.
DISPLAY "STATES : "STATES-TABLE.
DISPLAY 'STATE-CODE(1) : ' STATE-CODE(1).
DISPLAY 'STATE-NAME(1) : ' STATE-NAME(1).
DISPLAY 'STATE-CODE(2) : ' STATE-CODE(2).
DISPLAY 'STATE-NAME(2) : ' STATE-NAME(2).
DISPLAY 'STATE-CODE(3) : ' STATE-CODE(3).
DISPLAY 'STATE-NAME(3) : ' STATE-NAME(3).
STOP RUN.
Resulting in:
$ ./states
STATES : ACAcre ALAlagoasAPAmapá
STATE-CODE(1) : AC
STATE-NAME(1) : Acre
STATE-CODE(2) : AL
STATE-NAME(2) : Alagoas
STATE-CODE(3) : AP
STATE-NAME(3) : Amapá
Remember that á uses two bytes in UTF-8.
My calculations are correct. But the output file's ONLY first calculated record becomes as BLANK and affects all the records.
In the output file [A5-SalaryReport-5A.out], you may see the first record's position comes BLANK.
THIS IS MY INPUT FILE [A5.dat]
030ALLDREN RUTH 21G202000002200000
185DONNEMAN THOMAS06G042300900460000
004ACHER WILLIAM 01N072600500720000
325HATFIELD MARK 01G112200201100000
730REEDE OWEN 09G055501000620000
111CARTOLER VIOLET02G099800701000000
590NEIL CLARENCE 07N006500900100000
801SCHEIBER HARRY 01N100000001000000
956WANGLEY THEO 01N099999101000000
999BAKER RON 03G300001403500000
181DELBERT EDWARD 12G065901300770000
311GROLER GRACE 23N064302000770000
318HANEY CAROL 09G500001405500000
487KING MILDRED 18N091996301000000
834TRAWLEY HARRIS 05N732600507700000
027ALHOUER ELAINE 01G257300202500000
171COSTA NAN 15N035600500400000
317HANBEE ALETA 03G500000305500000
739RIDEL ROBERT 05N019400800200000
806STOCKTON NORMAN06G250700704300000
122CENNA DICK 03N577700406000000
207EBERHARDT RON 05G400700904500000
308GLEASON JAMES 01G500000305000000
568LYNNF GERALD 09N448701304500000
909UDSON DORIS 01N449900304500000
100BATES TONY 08N106602001000000
179DAMSON ERIC 03N250201802500000
292EVERLEY DONNA 03G200001702500000
409ICK MICK 25G999999910500000
607ODELLE NICK 10G250701803000000
825TILLMAN DON 12N044401900500000
214EDMONSON RICK 02N100000001000000
310GORMALLY MARIE 03N302200603000000
332HELD ANNA 02G400000204000000
689OWNEY REED 04N317460303500000
802SHEA MICHAEL 06G203300802300000
102BELLSLEY ART 08G300000903500000
282ESTABAN JUAN 19G405500004500000
322HARLETON JEAN 07N089901201000000
505LAMBERT JERRY 01G400100404000000
921ULL GEORGE 18N229885102500000
105BOYLE RALPH 08N804401407800000
215EDSON WILBUR 06G705000808000000
315HALE ALAN 12N400001604500000
THIS IS MY COBOL PROJECT FILE .cbl [A5-SalaryReport-5A.cbl]
identification division.
program-id. A5-SalaryReport-5A.
author. Nirmal Patel.
date-written. 11 March 2021.
* NOTE: I could have finished this, I just had too much for
* this week so I couldn not give this enough time. And I
* started this assignment on the day it it was due, 5th
* March.
environment division.
input-output section.
file-control.
select input-file
assign to "../../../data/A5.dat"
organization is line sequential.
select output-file
assign to "../../../data/A5-SalaryReport-5A.out"
organization is line sequential.
*
select outputdat-file
assign to
"../../../data/A5-SalaryData-NonGrad.dat"
organization is line sequential.
data division.
file section.
fd input-file
data record is input-rec
record contains 36 characters.
01 input-rec.
05 in-emp-no pic 9(3).
05 in-name pic x(15).
05 in-yrs-serv pic 9(2).
05 in-edu-code pic x(1).
88 il-88-type-K value "N".
05 in-prsnt-sly pic 9(5)V99.
05 in-bgt-est pic 9(6)V99.
fd output-file
data record is output-file
record contains 120 characters.
*
01 output-line pic x(120).
fd outputdat-file
data record is outputdat-line
record contains 55 characters.
01 outputdat-line pic x(55).
working-storage section.
01 ws-eof-flag pic x value 'n'.
*
01 ws-heading-info-line.
05 filler pic x(26)
value "Nirmal Patel, Assignment 4".
* ----+----1----+----2----+-
05 filler pic x(15) value spaces.
05 filler pic x(8) value "20210411".
05 filler pic x(23) value spaces.
05 filler pic x(7) value "1951043".
01 ws-heading-line-1.
05 filler pic x(30) value spaces.
05 filler pic x(22)
value "EMPLOYEE SALARY REPORT".
05 filler pic x(14) value spaces.
05 filler pic x(6) value "PAGE ".
05 page-num pic 9 value 1.
01 ws-heading-line-2.
05 filler pic x(3) value "EMP".
05 filler pic x(2) value spaces.
05 filler pic x(3) value "EMP".
05 filler pic x(32) value spaces.
05 filler pic x(7) value "PRESENT".
05 filler pic x(2) value spaces.
05 filler pic x(8) value "INCREASE".
05 filler pic x(5) value spaces.
05 filler pic x(3) value "PAY".
05 filler pic x(11) value spaces.
05 filler pic x(3) value "NEW".
01 ws-heading-line-3.
05 filler pic x(3) value "NUM".
05 filler pic x(2) value spaces.
05 filler pic x(4) value "NAME".
05 filler pic x(10) value spaces.
05 filler pic x(5) value "YEARS".
05 filler pic x(1) value spaces.
05 filler pic x(8) value "POSITION".
05 filler pic x(8) value spaces.
05 filler pic x(6) value "SALARY".
05 filler pic x(5) value spaces.
05 filler pic x(1) value "%".
05 filler pic x(7) value spaces.
05 filler pic x(8) value "INCREASE".
05 filler pic x(7) value spaces.
05 filler pic x(6) value "SALARY".
01 ws-record-line.
05 ws-emp-num pic 9(3).
05 filler pic x(1) value spaces.
05 ws-emp-name pic 9(15).
05 filler pic x(2) value spaces.
05 ws-years pic Z9.
05 filler pic x(2) value spaces.
05 ws-position pic x(12).
05 filler pic x(2) value spaces.
05 ws-salary pic ZZ,ZZ9.99.
05 filler pic x(2) value spaces.
05 ws-inc-per pic 9(2).9.
05 filler pic x(1) value "%".
05 filler pic x(3) value spaces.
05 ws-pay-inc pic $ZZ,ZZ9.99.
05 filler pic x(1) value "+".
05 filler pic x(1) value spaces.
05 filler pic x(1) value "$".
05 filler pic x(1) value spaces.
05 ws-new-salary pic ZZ,ZZZ,ZZ9.99.
01 ws-blank-line.
05 ws-blank-position pic x(12).
01 ws-totals-line-1.
05 filler pic x(15) value "EMPLOYEE CLASS:".
05 filler pic x(8) value spaces.
05 filler pic x(7) value "Analyst".
05 filler pic x(4) value spaces.
05 filler pic x(8) value "Sen Prog".
05 filler pic x(4) value spaces.
05 filler pic x(4) value "Prog".
05 filler pic x(4) value spaces.
05 filler pic x(7) value "Jr Prog".
05 filler pic x(4) value spaces.
05 filler pic x(12) value "Unclassified".
01 ws-totals-line-2.
05 filler pic x(15) value "# ON THIS PAGE:".
05 filler pic x(14) value spaces.
05 ws-no-of-analyst pic 9.
05 filler pic x(11) value spaces.
05 ws-no-of-sen-prog pic 9.
05 filler pic x(7) value spaces.
05 ws-no-of-prog pic 9.
05 filler pic x(10) value spaces.
05 ws-no-of-jr-prog pic 9.
05 filler pic x(15) value spaces.
05 ws-no-of-unclassified
pic 9.
01 ws-sub-total-line-1.
05 filler pic x(18)
value "AVERAGE INCREASES:".
05 filler pic x(3) value spaces.
05 filler pic x(8) value "ANALYST=".
05 filler pic x(5) value spaces.
05 ws-analyst-avg-inc pic Z,ZZ9.99.
05 filler pic x(5) value spaces.
05 filler pic x(9) value "SEN PROG=".
05 filler pic x(3) value spaces.
05 ws-sen-prog-avg-inc pic Z,ZZ9.99.
01 ws-sub-total-line-2.
05 filler pic x(21) value spaces.
05 filler pic x(5) value "PROG=".
05 filler pic x(8) value spaces.
05 ws-prog-avg-inc pic Z,ZZ9.99.
05 filler pic x(5) value spaces.
05 filler pic x(8) value "JR PROG=".
05 filler pic x(4) value spaces.
05 ws-jr-prog-avg-inc pic Z,ZZ9.99.
01 ws-oth-line.
05 filler pic x(25)
value " Type NON-GRADS count = ".
05 ws-oth-staff-count pic zz9.
05 filler pic x(7)
value spaces.
05 filler pic x(26)
value " Type NON-GRADA Salary = ".
05 ws-oth-salary pic $$$,$$$,$$9.
05 filler pic x(38)
value spaces.
05 ws-calc-position pic x(12).
01 ws-const-calc.
05 ws-page-count pic 99 value 0.
05 ws-edu-code pic x(1).
05 ws-o-staff-count pic 999 value 0.
05 ws-o-salary pic 9(10) value 0.
05 ws-s-staff-count pic 999 value 0.
05 ws-s-salary pic 9(10) value 0.
77 ws-lines-per-page pic 99 value 20.
77 ws-line-count pic 99 value 0.
procedure division.
000-main.
open input input-file.
open output output-file
outputdat-file.
write output-line from ws-heading-info-line
*
read input-file
at end
move "y" to ws-eof-flag.
*
* Process each input record and read in next record
*
perform 100-process-pages
until ws-eof-flag equals "y".
write output-line from ws-sub-total-line-1
after advancing 1 line.
write output-line from ws-sub-total-line-2.
close input-file
output-file
outputdat-file.
goback.
100-process-pages.
*
* Initialize detail calculation variables for page
*
move 0 to ws-s-staff-count
ws-s-salary
ws-line-count.
perform 110-print-headings.
*
* process input and output results until
* current page has been filled
* OR EOF has been encountered
*
perform 120-process-lines
varying ws-line-count from 1 by 1
until (ws-line-count > ws-lines-per-page
OR ws-eof-flag = "y").
perform 150-print-page-totals.
*
110-print-headings.
* Increase page count by 1
add 1 to ws-page-count.
move ws-page-count to page-num.
*
* Write the report heading with a blank line before heading
* and blank line after heading
*
if (ws-page-count > 1) then
write output-line
after advancing page
write output-line from ws-heading-line-1
after advancing 1 line
write output-line from ws-heading-line-2
after advancing 2 line
write output-line from ws-heading-line-3
else
write output-line from ws-heading-line-1
after advancing 1 line
write output-line from ws-heading-line-2
after advancing 2 line
write output-line from ws-heading-line-3
end-if.
120-process-lines.
* Decide whether to output to report or data file
*
if il-88-type-K
perform 210-process-data-lines
else
add 1 to ws-line-count
* if ws-line-count = 1
* perform 120-print-headings
* end-if
perform 220-process-rpt-lines
if ws-line-count > ws-lines-per-page
or ws-eof-flag = "y"
perform 230-print-page-totals
end-if
end-if.
*
* Logic to calculate the POSITION based on years of xp..
*
if in-yrs-serv > 15
then
move "ANALYST" to ws-calc-position
else
**
if in-yrs-serv > 7 and in-yrs-serv < 15
then
move "SEN PROG" to ws-calc-position
else
***
if in-yrs-serv > 2 and in-yrs-serv < 7
then
move "PROG" to ws-calc-position
else
****
if in-yrs-serv < 2
then
move "UNCLASSIFIED"
to ws-calc-position
* ----+----1--
end-if
****
end-if
***
end-if
**
end-if
*
* Read next input record for the next iteration of perform loop
*
read input-file
at end
move "y" to ws-eof-flag.
*
*
150-print-page-totals.
*
* PRINT TOTAL LINES
write output-line from ws-totals-line-1
after advancing 2 line.
write output-line from ws-totals-line-2.
*
*
210-process-data-lines.
*
add 1 to ws-o-staff-count.
add in-prsnt-sly to ws-o-salary.
move ws-position to ws-blank-position.
*
write outputdat-line from input-rec.
220-process-rpt-lines.
*
*
* Count staff and accumulate salary for page subtotals
*
add 1 to ws-s-staff-count.
add in-prsnt-sly to ws-s-salary.
*
*
* Output Salesperson Detail Line
*
* Clear the detail line
move spaces to ws-record-line.
*
*
* Move input lines(sales-file) to output lines(report-line)
*
move in-emp-no to ws-emp-num.
move in-name to ws-emp-name.
move in-yrs-serv to ws-years.
move in-prsnt-sly to ws-salary.
move ws-page-count to page-num.
move ws-o-staff-count to ws-oth-staff-count.
move ws-calc-position to ws-position.
*
write output-line from ws-record-line.
230-print-page-totals.
* Move subtotals to subtotal line and write to output file
* with blank line after subtotal line
*
*
write outputdat-line from ws-record-line.
*
*
move 0 to ws-s-staff-count
ws-s-salary.
*
*
end program A5-SalaryReport-5A.
THIS IS MY OUTPUT FILE [A5-SalaryReport-5A.out]
Nirmal Patel, Assignment 4 20210411 1951043
EMPLOYEE SALARY REPORT PAGE 1
EMP EMP PRESENT INCREASE PAY NEW
NUM NAME YEARS POSITION SALARY % INCREASE SALARY
030 ALLDREN RUTH 21 20,200.00
185 DONNEMAN THOMAS 6 ANALYST 4,230.09
325 HATFIELD MARK 1 UNCLASSIFIED 11,220.02
730 REEDE OWEN 9 UNCLASSIFIED 5,550.10
111 CARTOLER VIOLET 2 SEN PROG 9,980.07
999 BAKER RON 3 UNCLASSIFIED 30,000.14
181 DELBERT EDWARD 12 PROG 6,590.13
318 HANEY CAROL 9 ANALYST 50,000.14
EMPLOYEE CLASS: Analyst Sen Prog Prog Jr Prog Unclassified
# ON THIS PAGE:
# ON THIS PAGE:
EMPLOYEE SALARY REPORT PAGE 2
EMP EMP PRESENT INCREASE PAY NEW
NUM NAME YEARS POSITION SALARY % INCREASE SALARY
027 ALHOUER ELAINE 1 PROG 25,730.02
317 HANBEE ALETA 3 UNCLASSIFIED 50,000.03
806 STOCKTON NORMAN 6 PROG 25,070.07
207 EBERHARDT RON 5 PROG 40,070.09
308 GLEASON JAMES 1 PROG 50,000.03
292 EVERLEY DONNA 3 PROG 20,000.17
EMPLOYEE CLASS: Analyst Sen Prog Prog Jr Prog Unclassified
# ON THIS PAGE:
# ON THIS PAGE:
EMPLOYEE SALARY REPORT PAGE 3
EMP EMP PRESENT INCREASE PAY NEW
NUM NAME YEARS POSITION SALARY % INCREASE SALARY
409 ICK MICK 25 PROG 99,999.99
607 ODELLE NICK 10 ANALYST 25,070.18
332 HELD ANNA 2 PROG 40,000.02
802 SHEA MICHAEL 6 PROG 20,330.08
102 BELLSLEY ART 8 PROG 30,000.09
282 ESTABAN JUAN 19 SEN PROG 40,550.00
505 LAMBERT JERRY 1 ANALYST 40,010.04
EMPLOYEE CLASS: Analyst Sen Prog Prog Jr Prog Unclassified
# ON THIS PAGE:
# ON THIS PAGE:
EMPLOYEE SALARY REPORT PAGE 4
EMP EMP PRESENT INCREASE PAY NEW
NUM NAME YEARS POSITION SALARY % INCREASE SALARY
215 EDSON WILBUR 6 SEN PROG 70,500.08
EMPLOYEE CLASS: Analyst Sen Prog Prog Jr Prog Unclassified
# ON THIS PAGE:
AVERAGE INCREASES: ANALYST= SEN PROG=
PROG= JR PROG=
I know it is not an ez thing to figure out and I appreciate whatever answer you provide.
Cheers!
The problem I see is that the correct value for ws-position shows on the next record; this happens because ws-calc-position is determined after the line is printed. This caused a blank on the first record and an incorrect value on the following print lines.
I suggest moving the code for determining ws-calc-position to just before it is needed. 120-process-lines and 220-process-rpt-lines incorporates those suggestions.
The IF code should not include AND, as expressed originally. It causes some values to be missed, where in-yrs-serv is 15, 07, or 02. Those particular values caused (or would cause) the previously determined position to appear in the output. That change has be made below.
Also, this line
05 ws-emp-name pic 9(15).
should be
05 ws-emp-name pic x(15).
120-process-lines.
* Decide whether to output to report or data file
*
if il-88-type-K
perform 210-process-data-lines
else
add 1 to ws-line-count
* if ws-line-count = 1
* perform 120-print-headings
* end-if
perform 220-process-rpt-lines
if ws-line-count > ws-lines-per-page
or ws-eof-flag = "y"
perform 230-print-page-totals
end-if
end-if.
* NOTE: Moved code to determine position to 225-determine-position
*
* Read next input record for the next iteration of perform loop
*
read input-file
at end
move "y" to ws-eof-flag.
220-process-rpt-lines.
*
*
* Count staff and accumulate salary for page subtotals
*
add 1 to ws-s-staff-count.
add in-prsnt-sly to ws-s-salary.
*
*
* Output Salesperson Detail Line
*
* Clear the detail line
move spaces to ws-record-line.
*
*
* Move input lines(sales-file) to output lines(report-line)
*
move in-emp-no to ws-emp-num.
move in-name to ws-emp-name.
move in-yrs-serv to ws-years.
move in-prsnt-sly to ws-salary.
move ws-page-count to page-num.
move ws-o-staff-count to ws-oth-staff-count.
perform 225-determine-position.
move ws-calc-position to ws-position.
*
write output-line from ws-record-line.
225-determine-position.
*
* Logic to calculate the POSITION based on years of xp..
*
if in-yrs-serv > 15
then
move "ANALYST" to ws-calc-position
else
**
if in-yrs-serv > 7
then
move "SEN PROG" to ws-calc-position
else
***
if in-yrs-serv > 2
then
move "PROG" to ws-calc-position
else
****
move "UNCLASSIFIED" to ws-calc-position
****
end-if
***
end-if
**
end-if.
*-----------------------
IDENTIFICATION DIVISION.
*-----------------------
PROGRAM-ID. TOPACCTS
AUTHOR. Sohan Kundu.
*--------------------
ENVIRONMENT DIVISION.
*--------------------
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PRINT-LINE ASSIGN TO PRTLINE.
SELECT ACCT-REC ASSIGN TO ACCTREC.
*-------------
DATA DIVISION.
*-------------
FILE SECTION.
FD PRINT-LINE RECORD CONTAINS 80 CHARACTERS RECORDING MODE F.
01 PRINT-REC.
05 FILLER PIC X(01) VALUE SPACES.
05 FIRST-NAME-O PIC X(11).
05 FILLER PIC X(02) VALUE SPACES.
05 LAST-NAME-O PIC X(22).
05 FILLER PIC X(02) VALUE SPACES.
05 ACCT-BALANCE-O PIC X(12).
05 FILLER PIC X(30) VALUE SPACES.
*
FD ACCT-REC RECORD CONTAINS 80 CHARACTERS RECORDING MODE F.
01 ACCT-FIELDS.
05 FIRST-NAME PIC X(11).
05 LAST-NAME PIC X(22).
05 FILLER PIC X(28).
05 ACCT-BALANCE PIC X(12).
05 FILLER PIC X(7).
*
WORKING-STORAGE SECTION.
01 FLAGS.
05 LASTREC PIC X VALUE SPACE.
*
01 TOTAL-CLIENTS.
05 FILLER PIC X(14) VALUE
'# OF RECORDS: '.
05 CLIENTS PIC 9(3) VALUE ZERO.
05 FILLER PIC X(63) VALUE SPACES.
*
01 HEADER-1.
05 FILLER PIC X(30) VALUE 'REPORT FOR TOP ACCOUNT HOLDERS'.
05 FILLER PIC X(50) VALUE SPACES.
*
01 HEADER-2.
05 FILLER PIC X(05) VALUE 'Year '.
05 HDR-YR PIC 9(04).
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(06) VALUE 'Month '.
05 HDR-MO PIC X(02).
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(04) VALUE 'Day '.
05 HDR-DAY PIC X(02).
05 FILLER PIC X(53) VALUE SPACES.
*
01 HEADER-3.
05 FILLER PIC X(11) VALUE 'First Name '.
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(10) VALUE 'Last Name '.
05 FILLER PIC X(14) VALUE SPACES.
05 FILLER PIC X(08) VALUE 'Balance '.
05 FILLER PIC X(35) VALUE SPACES.
*
01 HEADER-4.
05 FILLER PIC X(11) VALUE '-----------'.
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(10) VALUE '----------'.
05 FILLER PIC X(14) VALUE SPACES.
05 FILLER PIC X(08) VALUE '--------'.
05 FILLER PIC X(35) VALUE SPACES.
*
01 WS-CURRENT-DATE-DATA.
05 WS-CURRENT-DATE.
10 WS-CURRENT-YEAR PIC 9(04).
10 WS-CURRENT-MONTH PIC 9(02).
10 WS-CURRENT-DAY PIC 9(02).
05 WS-CURRENT-TIME.
10 WS-CURRENT-HOURS PIC 9(02).
10 WS-CURRENT-MINUTE PIC 9(02).
10 WS-CURRENT-SECOND PIC 9(02).
10 WS-CURRENT-MILLISECONDS PIC 9(02).
*
*------------------
PROCEDURE DIVISION.
*------------------
OPEN-FILES.
OPEN INPUT ACCT-REC.
OPEN OUTPUT PRINT-LINE.
*
WRITE-HEADERS.
MOVE FUNCTION CURRENT-DATE TO WS-CURRENT-DATE-DATA.
MOVE WS-CURRENT-YEAR TO HDR-YR.
MOVE WS-CURRENT-MONTH TO HDR-MO.
MOVE WS-CURRENT-DAY TO HDR-DAY.
WRITE PRINT-REC FROM HEADER-1.
WRITE PRINT-REC FROM HEADER-2.
MOVE SPACES TO PRINT-REC.
WRITE PRINT-REC AFTER ADVANCING 1 LINES.
WRITE PRINT-REC FROM HEADER-3.
WRITE PRINT-REC FROM HEADER-4.
MOVE SPACES TO PRINT-REC.
*
READ-NEXT-RECORD.
PERFORM READ-RECORD
PERFORM UNTIL LASTREC = 'Y'
PERFORM IS-BALANCE-HIGH
PERFORM READ-RECORD
END-PERFORM
.
*
CLOSE-STOP.
WRITE PRINT-REC FROM TOTAL-CLIENTS.
CLOSE ACCT-REC.
CLOSE PRINT-LINE.
STOP RUN.
*
READ-RECORD.
READ ACCT-REC
AT END MOVE 'Y' TO LASTREC
END-READ.
*
IS-BALANCE-HIGH.
IF FUNCTION NUMVAL-C(ACCT-BALANCE) > 8500000 THEN
ADD 1 TO CLIENTS
PERFORM WRITE-RECORD
END-IF.
*
WRITE-RECORD.
MOVE FIRST-NAME TO FIRST-NAME-O.
MOVE LAST-NAME TO LAST-NAME-O.
MOVE ACCT-BALANCE TO ACCT-BALANCE-O.
WRITE PRINT-REC.
*
I want to read the account details from an input file and print if the balance is more than 8500000.
The code is showing the following error:
IGZ0201W A file attribute mismatch was detected. File PRINT-LINE in program TOPACCTS had a record length of 81 and
the file specified in the ASSIGN clause had a record length of 80.
IGZ0035S There was an unsuccessful OPEN or CLOSE of file PRTLINE in program TOPACCTS at relative location X'1E8'.
Neither FILE STATUS nor an ERROR declarative were specified. The status code was 39.
From compile unit TOPACCTS at entry point TOPACCTS at compile unit offset +000001E8 at entry offset +000001E8
at address 1B8001E8.
In the JCL that you are using to execute this program (as a batchjob), within the step with EXEC PGM=TOPACCTS, make sure that you use a DD-card for your output file PRTLINE which looks similar to this:
//PRTLINE DD DISP=(NEW,CATLG),DSN=YOUR.DSN.GOES.HERE,
// UNIT=SYSDA,SPACE=(CYL,(5,5)),
// RECFM=FB,LRECL=80
That way you'll avoid the status code '39', which indicates that there is a mismatch between your record length of 80 (as shown in your program with CONTAINS 80 CHARACTERS), and whatever you specified in your JCL's DD-card.
My outputs are not getting out right, and I'm not too sure how to go about doing a two dimensional array.
I have my outputs follow by the outputs should look like.....
Good example how to set up 2 dimensional table would help, since not sure what I find on line is good plus haven't found a good enough book to explain to an old person terms.
First is my code:
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO DATAIN
ORGANIZATION IS LINE SEQUENTIAL.
SELECT OUTPUT-FILE ASSIGN TO DATAOUT
ORGANIZATION IS LINE SEQUENTIAL.
SELECT ERROR-FILE ASSIGN TO DATAOUT2
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
*-------------------------------------------------------------*
* INPUT FILE LAYOUT *
*-------------------------------------------------------------*
FD INPUT-FILE.
01 INPUT-RECORD.
05 IR-JOB-NUM PIC 9(02).
88 IR-JOB-NUM-VALID VALUE 01 THRU 11.
05 IR-EMP-NUM PIC 9(01).
88 IR-EMP-NUM-VALID VALUE 1 THRU 4.
05 IR-NUM-COMPLETE PIC 9(04).
05 FILLER PIC X(03).
05 FILLER PIC X(07).
*-------------------------------------------------------------*
* OUTPUT FILE *
*-------------------------------------------------------------*
FD OUTPUT-FILE.
01 OUTPUT-RECORD PIC X(80).
*-------------------------------------------------------------*
* ERROR FILE *
*-------------------------------------------------------------*
FD ERROR-FILE.
01 ERROR-RECORD PIC X(80).
*-------------------------------------------------------------*
* WORKING STORAGE SECTION *
*-------------------------------------------------------------*
WORKING-STORAGE SECTION.
01 FLAGS-AND-ACCUMALATORS.
05 END-OF-FILE PIC XXX VALUE "NO".
88 AT-END-OF-FILE VALUE "YES".
05 ERROR-FLAG PIC XXX VALUE "NO".
05 BLANK-LINE PIC X(80) VALUE SPACES.
05 LINE-NUM-IR-POSITION PIC 999 VALUE ZERO.
01 SUBSCRIPT.
05 SUB PIC 99 VALUE ZERO.
*---------------------------------------------------------------*
* REPORT STRUCTURE *
*---------------------------------------------------------------*
* ERROR HEADER RECORD *
01 ER-HEADER.
05 FILLER PIC X(08) VALUE SPACES.
05 FILLER PIC X(03) VALUE "NO.".
05 FILLER PIC X(10) VALUE SPACES.
05 FILLER PIC X(06) VALUE "RECORD".
05 FILLER PIC X(15) VALUE SPACES.
05 FILLER PIC X(05) VALUE "ABOVE".
05 FILLER PIC X(33) VALUE SPACES.
* ERROR DETAIL RECORD *
01 ER-DETAIL-LINE.
05 FILLER PIC X(06) VALUE SPACES.
05 DL-ASTERIK PIC X(01) VALUE SPACES.
05 FILLER PIC X(01) VALUE SPACES.
05 DL-LINE-NUM PIC ZZ9 VALUE SPACES.
05 FILLER PIC X(09) VALUE SPACES.
05 DL-ERROR PIC X(16) VALUE SPACES.
05 FILLER PIC X(09) VALUE SPACES.
05 DL-ERROR-BIG-NUM PIC ZZZ9 VALUE SPACES.
* ERROR ERROR RECORD *
01 ER-ERROR-LINE.
05 FILLER PIC X(20) VALUE SPACES.
05 EL-JOB-NUM PIC X(02) VALUE SPACES.
05 EL-EMP-NUM PIC X(01) VALUE SPACES.
05 EL-NUM-COMPLETE PIC X(03) VALUE SPACES.
05 FILLER PIC X(54) VALUE SPACES.
* OUTPUT HEADER RECORD *
01 OR-HEADER.
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(03) VALUE "NO.".
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(08) VALUE "LOCATION".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 1 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 2 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 3 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 4 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE "TOTAL".
05 FILLER PIC X(15) VALUE SPACES.
* OUTPUT DETAIL RECORD *
01 OR-DETAIL-LINE.
03 OR-DETAIL OCCURS 11 TIMES.
05 FILLER PIC X(02) VALUE SPACES.
05 OR-JOB-NUM PIC 9(02).
05 FILLER PIC X(03) VALUE SPACES.
05 OR-LOCATION PIC X(08) VALUE "XXXXXXXX".
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP1-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP2-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP3-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP4-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-JOB-TOT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(15) VALUE SPACES.
* SUMMARY RECORD *
01 OR-SUMMARY.
05 FILLER PIC X(08) VALUE SPACES.
05 FILLER PIC X(06)
VALUE "TOTALS".
05 FILLER PIC X(04) VALUE SPACES.
05 OR-TOT1-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT2-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT3-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT4-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT-TOT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(15) VALUE SPACES.
PROCEDURE DIVISION.
*****************************************************************
*0000-MAIN-PROCEDURE *
*****************************************************************
0000-MAIN-PROCEDURE SECTION.
OPEN INPUT INPUT-FILE
OUTPUT OUTPUT-FILE
ERROR-FILE.
PERFORM 1000-INITIALIZE.
PERFORM UNTIL AT-END-OF-FILE
READ INPUT-FILE
AT END
MOVE 'YES' TO END-OF-FILE
NOT AT END
PERFORM 2000-PROCESS
END-READ
END-PERFORM.
PERFORM VARYING SUB FROM 1 BY 1 UNTIL SUB > 11
PERFORM 3000-FINALIZE
END-PERFORM.
PERFORM 4000-SUMMARY.
CLOSE INPUT-FILE
OUTPUT-FILE
ERROR-FILE.
GOBACK.
0000-EXIT.
EXIT.
/
*****************************************************************
*1000-INITIALIZE *
*****************************************************************
*PURPOSE: INITIALIZE ALL THE VARIABLES AND *
* WRITE THE HEADER RECORDS TO THE OUTPUT FILES. *
*****************************************************************
1000-INITIALIZE SECTION.
WRITE ERROR-RECORD FROM ER-HEADER.
WRITE ERROR-RECORD FROM BLANK-LINE.
WRITE OUTPUT-RECORD FROM OR-HEADER.
WRITE OUTPUT-RECORD FROM BLANK-LINE.
1000-EXIT.
EXIT.
/
2000-PROCESS SECTION.
*****************************************************************
*PURPOSE: *
*****************************************************************
MOVE 'NO' TO ERROR-FLAG.
ADD 1 TO LINE-NUM-IR-POSITION.
IF NOT IR-JOB-NUM-VALID
MOVE INPUT-RECORD TO DL-ERROR
MOVE LINE-NUM-IR-POSITION
TO DL-LINE-NUM
MOVE 'YES' TO ERROR-FLAG
MOVE ALL '*' TO EL-JOB-NUM
END-IF.
IF NOT IR-EMP-NUM-VALID
MOVE INPUT-RECORD TO DL-ERROR
MOVE LINE-NUM-IR-POSITION
TO DL-LINE-NUM
MOVE 'YES' TO ERROR-FLAG
MOVE ALL '*' TO EL-EMP-NUM
END-IF.
IF ERROR-FLAG = 'NO'
INSPECT IR-NUM-COMPLETE REPLACING LEADING
SPACES BY ZEROES
IF IR-NUM-COMPLETE IS NUMERIC
MOVE IR-JOB-NUM TO SUB
IF IR-EMP-NUM = 1
ADD IR-NUM-COMPLETE TO
OR-EMP1-AMT(SUB)
END-IF
IF IR-EMP-NUM = 2
ADD IR-NUM-COMPLETE TO
OR-EMP2-AMT(SUB)
END-IF
IF IR-EMP-NUM = 3
ADD IR-NUM-COMPLETE TO
OR-EMP3-AMT(SUB)
END-IF
IF IR-EMP-NUM = 4
ADD IR-NUM-COMPLETE TO
OR-EMP4-AMT(SUB)
END-IF
ELSE
MOVE INPUT-RECORD TO DL-ERROR
MOVE LINE-NUM-IR-POSITION
TO DL-LINE-NUM
MOVE 'YES' TO ERROR-FLAG
MOVE ALL '*' TO EL-NUM-COMPLETE
END-IF.
IF ERROR-FLAG = 'YES'
IF IR-NUM-COMPLETE > 50
MOVE ALL '*' TO DL-ASTERIK
MOVE IR-NUM-COMPLETE TO DL-ERROR-BIG-NUM
END-IF
WRITE ERROR-RECORD FROM ER-DETAIL-LINE
WRITE ERROR-RECORD FROM ER-ERROR-LINE
MOVE SPACES TO ER-DETAIL-LINE
MOVE SPACES TO ER-ERROR-LINE
END-IF.
2000-EXIT.
EXIT.
/
3000-FINALIZE SECTION.
*****************************************************************
*PURPOSE: *
*****************************************************************
MOVE SUB TO OR-JOB-NUM(SUB).
ADD OR-EMP1-AMT(SUB)
OR-EMP2-AMT(SUB)
OR-EMP3-AMT(SUB)
TO OR-EMP4-AMT(SUB)
GIVING OR-JOB-TOT(SUB).
ADD OR-EMP1-AMT(SUB) TO OR-TOT1-AMT.
ADD OR-EMP2-AMT(SUB) TO OR-TOT2-AMT.
ADD OR-EMP3-AMT(SUB) TO OR-TOT3-AMT.
ADD OR-EMP4-AMT(SUB) TO OR-TOT4-AMT.
ADD OR-JOB-TOT(SUB) TO OR-TOT-TOT.
IF OR-JOB-TOT(SUB) > 0
WRITE OUTPUT-RECORD FROM OR-DETAIL(SUB)
WRITE OUTPUT-RECORD FROM BLANK-LINE
END-IF.
3000-EXIT.
EXIT.
/
4000-SUMMARY SECTION.
*****************************************************************
*PURPOSE: *
*****************************************************************
WRITE OUTPUT-RECORD FROM BLANK-LINE.
WRITE OUTPUT-RECORD FROM OR-SUMMARY.
4000-EXIT.
EXIT.
My output in the Exception report is:
NO. RECORD ABOVE
3 0r4000700 03
**
6 074000Q00 06
***
* 7 075075000 07 750
*
* 8 06105 100 08 5 1
***
10 095000500 10
*
* 12 125999999 12 9999
***
19 08500050 19
*
21 125000899 21
***
23 A01001111 23
**
But should be:
ERROR REPORT
NO. CONTENTS ABOVE
2 032 200 02
****
3 0r4000700 03
**
5 073 73000 05
****
6 074000Q00 06
****
* 7 075075000 07 750
*
8 06105 100 08
****
9 011 52000 09
****
10 095000500 10
*
* 12 125999999 12 9999
***
19 08500050 19
*
* 20 091010000 20 100
21 125000899 21
***
23 A01001111 23
**
And my output for summary is:
NO. LOCATION 1 2 3 4 TOTAL
01 XXXXXXXX 00520 00000 00000 00000 00520
03 XXXXXXXX 00000 00002 00000 00007 00009
04 XXXXXXXX 00010 00010 00003 00000 00023
05 XXXXXXXX 00000 00012 00000 00004 00016
06 XXXXXXXX 00000 00000 00000 00004 00004
07 XXXXXXXX 00000 00000 00730 00000 00730
08 XXXXXXXX 00006 00000 00000 00004 00010
09 XXXXXXXX 00100 00000 00000 00000 00100
TOTALS 00636 00024 00733 00019 01412
And should look like this:
SUMMARY REPORT
NO. LOCATION 1 2 3 4 TOTAL
1 PETERS, FL 0 0 0 0 0
2 ATCHISON, KS 0 0 0 0 0
3 KANSAS CITY, MO 0 0 0 7 7
4 DENVER, CO 10 10 3 0 23
5 SAN JOSE, CA 0 12 0 4 16
6 REDMOND, WA 0 0 0 4 4
7 HOUSTON, TX 0 0 0 0 0
8 TOPEKA, KS 6 0 0 4 10
9 WICHITA, KS 100 0 0 0 100
10 JEFFERSON CITY, MO 0 0 0 0 0
11 ST. LOUIS MO 0 0 0 0 0
TOTALS 116 22 3 19 160
For Multi dimensional arrays in Cobol, just nest the occurs clause:
01 WS-DETAIL-totals OCCURS 11 TIMES.
05 WS-JOB-NUM PIC 9(02).
05 WS-LOCATION PIC X(08) VALUE "XXXXXXXX".
05 WS-EMP-AMT occurs 4 PIC s9(05) COMP VALUE ZEROES.
05 WS-JOB-TOT PIC s9(05) COMP VALUE ZEROES.
01 OR-DETAIL-LINE.
03 OR-DETAIL OCCURS 11 TIMES.
05 FILLER PIC X(02) VALUE SPACES.
05 OR-JOB-NUM PIC z9.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-LOCATION PIC X(08) VALUE "XXXXXXXX".
05 FILLER PIC X(03) VALUE SPACES.
05 Filler occurs 4.
10 OR-EMP1-AMT PIC ----9.
10 FILLER PIC X(03) VALUE SPACES.
05 OR-JOB-TOT PIC ----9 VALUE ZEROES.
05 FILLER PIC X(15) VALUE SPACES.
You should also accumulate in comp fields (like in ws table above) and move to output table.
The
INSPECT IR-NUM-COMPLETE REPLACING LEADING
SPACES BY ZEROES
statement in 2000- means errors like the following are not caught
2 032 200 02
****
I keep getting the error
"LOWMID-COMMISSION-CTR" was not a uniquely defined name. The definition
to be used could not be determined from the context.
And similar on all of my counters. I have no idea where I'm going wrong here, how is it not a uniquely defined name when it is clearly in the WORKING-STORAGE SECTION? Do I put it somewhere else so that it's a uniquely defined name? Below I have showed where I defined my counters, and where the counters are used.
IDENTIFICATION DIVISION.
PROGRAM-ID. LAB3.
AUTHOR.
******************************************************************
ENVIRONMENT DIVISION.
* defines the external files - an input file and output file
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SALES-FILE ASSIGN TO DATAIN
FILE STATUS IS EF-STATUS.
SELECT REPORT-FILE ASSIGN TO DATAOUT
FILE STATUS IS PF-STATUS.
DATA DIVISION.
* has two sections - the file section that describes the files
* and the working storage section - where output lines and
* processing variables are defined
FILE SECTION.
FD SALES-FILE.
01 SALES-RECORD.
05 EMPLOYEE-NAME-IN PIC X(24).
05 SALES-IN PIC 99999.
05 FILLER PIC X(51).
FD REPORT-FILE.
01 REPORT-RECORD PIC X(80).
WORKING-STORAGE SECTION.
01 FLAGS-AND-ACCUMLATORS.
05 LOW-COMMISSION-CTR PIC 99999 VALUE ZERO.
05 LOWMID-COMMISSION-CTR PIC 99999 VALUE ZERO.
05 HIGHMID-COMMISSION-CTR PIC 99999 VALUE ZERO.
05 HIGH-COMMISSION-CTR PIC 99999 VALUE ZERO.
05 TOTAL-SALES PIC $$$,$$9.99 VALUE ZERO.
05 TOTAL-COMMISSION PIC $$$,$$9.99 VALUE ZERO.
05 END-OF-FILE PIC XXX VALUE "NO".
05 EF-STATUS PIC 99 VALUE 0.
05 PF-STATUS PIC 99 VALUE 0.
05 COMMISSION PIC 99999V99.
01 REPORT-BLANK-LINE.
05 PIC X(80).
01 HEADING-LINE-1.
05 PIC X(30) VALUE SPACES.
05 PIC X(19) VALUE
"COMPANY OF AARON".
01 HEADING-LINE-2.
05 PIC X(30) VALUE SPACES.
05 PIC X(19) VALUE
"KEARNEY, MISSOURI".
01 HEADING-LINE-3.
05 PIC X(03) VALUE SPACES.
05 PIC X(48) VALUE
"Number of employees with up to 10,000 in sales: ".
05 LOW-COMMISSION-CTR PIC 99999.
01 HEADING-LINE-4.
05 PIC X(03) VALUE SPACES.
05 PIC X(52) VALUE
"Number of employees from 10,001 to 20,000 in sales: ".
05 LOWMID-COMMISSION-CTR PIC 99999.
01 HEADING-LINE-5.
05 PIC X(03) VALUE SPACES.
05 PIC X(52) VALUE
"Number of employees from 20,001 to 30,000 in sales: ".
05 HIGHMID-COMMISSION-CTR PIC 99999.
01 HEADING-LINE-6.
05 PIC X(03) VALUE SPACES.
05 PIC X(42) VALUE
"Number of employees over 30,000 in sales: ".
05 HIGH-COMMISSION-CTR PIC 99999.
01 HEADING-LINE-7.
05 PIC X(03) VALUE SPACES.
05 PIC X(13) VALUE
"Total Sales: ".
05 TOTAL-SALES PIC $$$,$$9.99.
01 HEADING-LINE-8.
05 PIC X(03) VALUE SPACES.
05 PIC X(18) VALUE
"TOTAL COMMISSION: ".
05 TOTAL-COMMISSION PIC $$$,$$9.99.
01 COLUMN-HEADING-1.
05 PIC X(03) VALUE SPACES.
05 PIC X(24) VALUE "SALESPERSON".
05 PIC X(15) VALUE "SALES".
05 PIC X(10) VALUE "COMMISSION".
01 COLUMN-HEADING-2.
05 PIC X(14) VALUE "SUMMARY REPORT".
01 DETAIL-LINE.
05 PIC X(03) VALUE SPACES.
05 EMPLOYEE-NAME-OUT PIC X(24).
05 SALES-OUT PIC $$$,$$9.
05 PIC X(05) VALUE SPACES.
05 COMMISSION-OUT PIC $$$,$$9.99.
PROCEDURE DIVISION.
1000-MAIN-CONTROL.
PERFORM 2000-INITIALIZE.
PERFORM UNTIL END-OF-FILE = "YES"
READ SALES-FILE
AT END
MOVE "YES" TO END-OF-FILE
NOT AT END
PERFORM 3000-PROCESS
END-PERFORM
PERFORM 4000-PROCESS.
STOP RUN.
2000-INITIALIZE.
OPEN INPUT SALES-FILE
OUTPUT REPORT-FILE.
WRITE REPORT-RECORD FROM HEADING-LINE-1.
WRITE REPORT-RECORD FROM HEADING-LINE-2.
WRITE REPORT-RECORD FROM REPORT-BLANK-LINE.
WRITE REPORT-RECORD FROM COLUMN-HEADING-1.
WRITE REPORT-RECORD FROM REPORT-BLANK-LINE.
3000-PROCESS.
IF SALES-IN < 10001
MULTIPLY SALES-IN BY .04 GIVING COMMISSION
ADD 1 TO LOW-COMMISSION-CTR
ADD COMMISSION TO TOTAL-COMMISSION
END-IF.
IF SALES-IN > 10000 AND < 20001
MULTIPLY SALES-IN BY .055 GIVING COMMISSION
ADD 1 TO LOWMID-COMMISSION-CTR
ADD COMMISSION TO TOTAL-COMMISSION
END-IF.
IF SALES-IN > 20000 AND < 30000
MULTIPLY SALES-IN BY .065 GIVING COMMISSION
ADD 1 TO HIGHMID-COMMISSION-CTR
ADD COMMISSION TO TOTAL-COMMISSION
END-IF.
IF SALES-IN > 30000
MULTIPLY SALES-IN BY .075 GIVING COMMISSION
ADD 1 TO HIGH-COMMISSION-CTR
ADD COMMISSION TO TOTAL-COMMISSION
END-IF.
MOVE EMPLOYEE-NAME-IN TO EMPLOYEE-NAME-OUT.
MOVE SALES-IN TO SALES-OUT.
MOVE COMMISSION TO COMMISSION-OUT.
WRITE REPORT-RECORD FROM DETAIL-LINE.
4000-PROCESS.
WRITE REPORT-RECORD FROM REPORT-BLANK-LINE.
WRITE REPORT-RECORD FROM COLUMN-HEADING-2.
WRITE REPORT-RECORD FROM HEADING-LINE-3.
WRITE REPORT-RECORD FROM HEADING-LINE-4.
WRITE REPORT-RECORD FROM HEADING-LINE-5.
WRITE REPORT-RECORD FROM HEADING-LINE-6.
WRITE REPORT-RECORD FROM HEADING-LINE-7.
WRITE REPORT-RECORD FROM HEADING-LINE-8.
4000-TERMINATE.
CLOSE SALES-FILE, REPORT-FILE.
Thje variable LOWMID-COMMISSION-CTR is defined twice.
once in FLAGS-AND-ACCUMLATORS
01 FLAGS-AND-ACCUMLATORS.
05 LOW-COMMISSION-CTR PIC 99999 VALUE ZERO.
05 LOWMID-COMMISSION-CTR PIC 99999 VALUE ZERO.
once in HEADING-LINE-4
01 HEADING-LINE-4.
05 PIC X(03) VALUE SPACES.
05 PIC X(52) VALUE
"Number of employees from 10,001 to 20,000 in sales: ".
05 LOWMID-COMMISSION-CTR PIC 99999.
So either
rename one of the LOWMID-COMMISSION-CTR to some thing else
01 HEADING-LINE-4.
05 PIC X(03) VALUE SPACES.
05 PIC X(52) VALUE
"Number of employees from 10,001 to 20,000 in sales: ".
05 HEADER-LOWMID-COMMISSION-CTR PIC 99999.
fully qualify the field.
Add 1
to LOWMID-COMMISSION-CTR
of FLAGS-AND-ACCUMLATORS
Same applies to other FLAGS-AND-ACCUMLATORS fields