I'm working on an assignment for my class, and I'm having an issue with getting a percentage to show the proper value for my COBOL Lab.
My issue is with PERCENT-DISCOUNT / WS-PERCENT-WITH-DISCOUNT (at least, I believe it is).
When the program is run, I get the result 50.0. The result I should be getting (assuming I did the math correctly by hand) is 55.6. I'm not too sure where I'm going wrong.
Here is the code that I currently have written for the program.
*
IDENTIFICATION DIVISION.
PROGRAM-ID. LAB2.
AUTHOR. XXXXXXX XXXXXXXXXXX.
*
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IPT-FILE ASSIGN TO 'LAB2.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT PRT-FILE ASSIGN TO 'LAB2_OUTPUT.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
*
DATA DIVISION.
FILE SECTION.
*
FD IPT-FILE
RECORD CONTAINS 80 CHARACTERS
RECORDING MODE IS F
DATA RECORD IS INPUT-RECORD.
01 IPT-RECORD.
05 IPT-INV-NUMBER PIC 9(04).
05 IPT-INV-QUANTITY PIC 9(03).
05 IPT-INV-DESCRIPTION PIC X(13).
05 IPT-INV-UNITPRICE PIC 9999V99.
05 IPT-INV-PROD-CLASS PIC 9(01).
*
FD PRT-FILE
RECORD CONTAINS 132 CHARACTERS
RECORDING MODE IS F
DATA RECORD IS PRT-LINE.
01 PRT-LINE.
05 FILLER PIC X(04).
05 PRT-INV-NUMBER PIC 9(04).
05 FILLER PIC X(02).
05 PRT-EXTENDED-PRICE PIC Z,ZZZ,ZZ9.99.
05 FILLER PIC X(04).
05 PRT-DISCOUNT-AMOUNT PIC ZZZ,ZZ9.99.
05 FILLER PIC X(03).
05 PRT-NET-PRICE PIC Z,ZZZ,ZZ9.99.
05 FILLER PIC X(10).
05 PRT-PRODUCT-CLASS PIC 9.
05 FILLER PIC X(07).
05 PRT-TRANS-PERCENT PIC Z9.9.
05 FILLER PIC X(05).
05 PRT-TRANS-CHARGE PIC ZZZ,ZZ9.99.
*
WORKING-STORAGE SECTION.
*
01 EOF-SWITCH PIC X VALUE 'N'.
*
01 WS-EXTENDED-COST PIC 9(07)V99.
01 WS-DISCOUNT-AMOUNT PIC 9(06)V99.
01 WS-NET-COST PIC 9(07)V99.
01 WS-TRANS-PERCENT PIC ZZ9V9.
01 WS-TRANS-COST PIC 9(06)V99.
*
01 WS-TOTAL-EXTENDED-COST PIC 9(09)V99 VALUE ZERO.
01 WS-TOTAL-NET-COST PIC 9(08)V99 VALUE ZERO.
01 WS-TOTAL-TRANS-COST PIC 9(08)V99 VALUE ZERO.
01 WS-TOTAL-WITH-DISCOUNT PIC 99V9 VALUE ZERO.
01 WS-TOTAL-ITEMS PIC 99V9 VALUE ZERO.
01 WS-PERCENT-WITH-DISCOUNT PIC 99V9.
01 WS-TOTAL-NO-DISCOUNT PIC 99V9 VALUE ZERO.
*
01 HEADING-NAME.
05 MY-NAME PIC X(20) VALUE
'XXXXX XXXXXXX, LAB 2'.
01 HEADING-COLUMN-1.
05 FILLER PIC X(05) VALUE SPACES.
05 COLUMN-1-INV-NUM PIC X(03) VALUE 'INV'.
05 FILLER PIC X(06) VALUE SPACES.
05 COLUMN-1-EXT-PRC PIC X(08) VALUE 'EXTENDED'.
05 FILLER PIC X(06) VALUE SPACES.
05 COLUMN-1-DISC-AMT PIC X(08) VALUE 'DISCOUNT'.
05 FILLER PIC X(06) VALUE SPACES.
05 COLUMN-1-NET-PRC PIC X(09) VALUE 'NET PRICE'.
05 FILLER PIC X(06) VALUE SPACES.
05 COLUMN-1-CLASS PIC X(05) VALUE 'CLASS'.
05 FILLER PIC X(06) VALUE SPACES.
05 COLUMN-1-TRANS-P PIC X(05) VALUE 'TRANS'.
05 FILLER PIC X(06) VALUE SPACES.
05 COLUMN-1-TRANS-C PIC X(14) VALUE 'TRANSPORTATION'.
01 HEADING-COLUMN-2.
05 FILLER PIC X(05) VALUE SPACES.
05 COLUMN-2-INV-NUM PIC X(03) VALUE 'NUM'.
05 FILLER PIC X(09) VALUE SPACES.
05 COLUMN-2-EXT-PRC PIC X(08) VALUE 'PRICE'.
05 FILLER PIC X(05) VALUE SPACES.
05 COLUMN-2-DISC-AMT PIC X(08) VALUE 'AMOUNT'.
05 FILLER PIC X(06) VALUE SPACES.
05 COLUMN-2-NET-PRC PIC X(09) VALUE SPACES.
05 FILLER PIC X(06) VALUE SPACES.
05 COLUMN-2-CLASS PIC X(05) VALUE SPACES.
05 FILLER PIC X(08) VALUE SPACES.
05 COLUMN-2-TRANS-P PIC X(05) VALUE '%'.
05 FILLER PIC X(05) VALUE SPACES.
05 COLUMN-2-TRANS-C PIC X(14) VALUE 'CHARGE'.
01 BLANK-LINE.
05 BLANK-SPACE PIC X VALUE SPACES.
01 TOTAL-FOOTER.
05 FILLER PIC X(07) VALUE SPACES.
05 TOTAL-EXTENDED-COST PIC $$$$,$$$,$$9.99.
05 FILLER PIC X(15) VALUE SPACES.
05 TOTAL-NET-COST PIC $$$,$$$,$$9.99.
05 FILLER PIC X(23) VALUE SPACES.
05 TOTAL-TRANS-COST PIC $$$,$$$,$$9.99.
01 TOTAL-NO-DISCOUNT-FOOTER.
05 TOTAL-SENTENCE PIC X(31) VALUE
'TOTAL ITEMS WITHOUT DISCOUNT = '.
05 TOTAL-NO-DISCOUNT PIC Z9.
01 PERCENT-DISCOUNT-FOOTER.
05 PERCENT-SENTENCE PIC X(44) VALUE
'PERCENT OF ITEMS THAT RECEIVED A DISCOUNT = '.
05 PERCENT-DISCOUNT PIC Z9.9.
*
PROCEDURE DIVISION.
*
OPEN INPUT IPT-FILE.
OPEN OUTPUT PRT-FILE.
*
WRITE PRT-LINE FROM HEADING-NAME AFTER ADVANCING 0 LINES.
WRITE PRT-LINE FROM HEADING-COLUMN-1 AFTER ADVANCING 3 LINES.
WRITE PRT-LINE FROM HEADING-COLUMN-2 AFTER ADVANCING 1 LINES.
WRITE PRT-LINE FROM BLANK-LINE AFTER ADVANCING 1 LINES.
*
READ IPT-FILE AT END MOVE 'Y' TO EOF-SWITCH.
*
PERFORM MAIN-LOOP UNTIL EOF-SWITCH EQUALS 'Y'.
*
DIVIDE WS-TOTAL-WITH-DISCOUNT BY WS-TOTAL-ITEMS
GIVING WS-PERCENT-WITH-DISCOUNT.
MULTIPLY WS-PERCENT-WITH-DISCOUNT BY 100
GIVING WS-PERCENT-WITH-DISCOUNT.
*
MOVE WS-TOTAL-EXTENDED-COST TO TOTAL-EXTENDED-COST.
MOVE WS-TOTAL-NET-COST TO TOTAL-NET-COST.
MOVE WS-TOTAL-TRANS-COST TO TOTAL-TRANS-COST.
MOVE WS-TOTAL-NO-DISCOUNT TO TOTAL-NO-DISCOUNT.
MOVE WS-PERCENT-WITH-DISCOUNT TO PERCENT-DISCOUNT.
*
WRITE PRT-LINE FROM TOTAL-FOOTER AFTER ADVANCING 3 LINES.
WRITE PRT-LINE FROM TOTAL-NO-DISCOUNT-FOOTER AFTER
ADVANCING 3 LINES.
WRITE PRT-LINE FROM BLANK-LINE AFTER ADVANCING 1 LINES.
WRITE PRT-LINE FROM PERCENT-DISCOUNT-FOOTER AFTER ADVANCING
1 LINES.
*
CLOSE IPT-FILE, PRT-FILE.
STOP RUN.
*
MAIN-LOOP.
MOVE SPACES TO PRT-LINE.
*
MULTIPLY IPT-INV-QUANTITY BY IPT-INV-UNITPRICE
GIVING WS-EXTENDED-COST ROUNDED.
MOVE WS-EXTENDED-COST TO PRT-EXTENDED-PRICE.
*
ADD 1 TO WS-TOTAL-ITEMS
*
IF WS-EXTENDED-COST IS GREATER THAN 200 THEN
MULTIPLY WS-EXTENDED-COST BY 0.11 GIVING
WS-DISCOUNT-AMOUNT ROUNDED
ADD 1 TO WS-TOTAL-WITH-DISCOUNT
*
ELSE
MOVE ZERO TO WS-DISCOUNT-AMOUNT
ADD 1 TO WS-TOTAL-NO-DISCOUNT
END-IF.
*
IF IPT-INV-PROD-CLASS IS EQUAL TO 1 THEN
MOVE 27.0 TO WS-TRANS-PERCENT
MULTIPLY WS-EXTENDED-COST BY 0.27 GIVING
WS-TRANS-COST ROUNDED
*
ELSE IF IPT-INV-PROD-CLASS IS EQUAL TO 2 THEN
MOVE 17.0 TO WS-TRANS-PERCENT
MULTIPLY WS-EXTENDED-COST BY 0.17 GIVING
WS-TRANS-COST ROUNDED
*
ELSE IF IPT-INV-QUANTITY IS GREATER THAN 100 THEN
MOVE 13.5 TO WS-TRANS-PERCENT
MULTIPLY WS-EXTENDED-COST BY 0.135 GIVING
WS-TRANS-COST ROUNDED
*
ELSE
MOVE ZERO TO WS-TRANS-PERCENT
MOVE 25.00 TO WS-TRANS-COST
END-IF.
*
SUBTRACT WS-EXTENDED-COST FROM WS-DISCOUNT-AMOUNT
GIVING WS-NET-COST.
ADD WS-EXTENDED-COST TO WS-TOTAL-EXTENDED-COST.
ADD WS-NET-COST TO WS-TOTAL-NET-COST.
ADD WS-TRANS-COST TO WS-TOTAL-TRANS-COST.
*
MOVE IPT-INV-NUMBER TO PRT-INV-NUMBER.
MOVE WS-EXTENDED-COST TO PRT-EXTENDED-PRICE.
MOVE WS-DISCOUNT-AMOUNT TO PRT-DISCOUNT-AMOUNT.
MOVE WS-NET-COST TO PRT-NET-PRICE.
MOVE IPT-INV-PROD-CLASS TO PRT-PRODUCT-CLASS.
MOVE WS-TRANS-PERCENT TO PRT-TRANS-PERCENT.
MOVE WS-TRANS-COST TO PRT-TRANS-CHARGE.
*
WRITE PRT-LINE AFTER ADVANCING 1 LINES.
*
READ IPT-FILE AT END MOVE 'Y' TO EOF-SWITCH.
Here is the information that the .dat file holds.
2047105TYPEWRITER 0800002
1742010HANDLE 0010001
2149150USB DRIVE 1200003
3761005TAPE 5000004
2791010BOLTS 0000751
3000100STAPLER 0002007
3001101OVERHEAD PROJ0099997
3002099PENCILS 0000097
4001184CANADIAN RUGS0150294
4003050CARPET 0040000
4005001WASTE BASKETS0003793
5001010HINGES 0010001
5003010PENS (GOLD) 0049992
5004400PENS (BLACK) 0002004
8888999HIGH CHAIR 9999991
8889412PLAY PEN 0074992
0001001LOW TEST 0000019
9999999LAST RECORD 0000011
Your problem is here:
01 WS-PERCENT-WITH-DISCOUNT PIC 99V9.
When you do your divide, you store the result in that field. If you expect it to be 0.556, what you are storing is 0.5, because you have only defined one decimal place, so the two low-order decimal places are simply truncated.
When you then multiply by 100, you make that 50.0.
If you define that field with three decimal places, your expected answer should appear (I've not checked your data).
However, a better way to do it is to define more integer digits, so that the field is large enough to hold your intermediate result and multiply by 100 first. Then you can divide (and you may want to consider ROUNDED on that, but it depends on the spec for the program).
There are a few questions here on problems with COMPUTE. Reading those questions and understanding the answers will help you get a good grasp on this. In COBOL, you define the accuracy you require, and you do that by supplying the correct number of integer and decimal digits.
You could also look through some of the other COBOL questions, where you'll find lots of advice on using FILE STATUS on your files, and checking the result of each IO. You can also use the file-status field you define to check for end-of-file, rather than using AT END/NOT AT END: you should find that it needs less code, and is more easy to understand.
Ditch as many full-stops/periods as you can. You need one at the end of the PROCEDURE DIVISION header, one at the end of a procedure-name, one at the end of a procedure, and one at the end of the program (if you have no procedure-names). All the others are superfluous. Commas in code tend to distract, you may find it clearer to use indentation and formatting of the statements.
Whilst it is well-constructed, your nested-IF would be better as an EVALUATE.
You have many constants in your program. It is better to define those as data-items, with a well-chosen name, so that the code "reads", and no-one has to wonder about the significance of 0.27. You also have examples where you have two constants which are obviously related, 27.0 and 0.27 for instance, which are better served by just being one thing. If someone "maintains" the program, they may only change one of the values without changing the other (not expecting there to be another).
Look also at the use of 88-level condition names. The "switch = y" can become "end-of-invoice-file" for instance, and that 88 can be on the file-status for that file, with a value of "10".
You should test your program with an empty input file, and see if you like the results.
As a beginner with COBOL, it is not a bad shot at all.
Related
*-----------------------
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.
Looking for solution on my problem. The values I need to convert was in alphanumeric.
05 WS-NUM-TX.
05 WS-NUM PIC P9(04).
05 WS-NUM1 PIC P9(03).
05 WS-NUM2 PIC P9(03).
MOVE '0001 222217' TO WS-NUM-TX.
MOVE WS-NUM-TX(1:4) TO WS-NUM.
MOVE WS-NUM-TX(6:3) TO WS-NUM1.
MOVE WS-NUM-TX(9:3) TO WS-NUM2.
I did COMPUTE WS-NUM = FUNCTION NUMVAL(WS-NUM-TX) for this to be numeric.
Now, the problem is, I need this values as decimal for computation. Need help to convert this values to become .0001, .222 and .217 however the declaration
I did for external decimal displayed with no decimal point. Please help. Thank You.
The P in the PICTURE clause is an error, as is the absence of a PICTURE clause for WS-NUM-TX. (As of the the 4th revision.)
Possibly,
05 WS-NUM-TX PIC X(11).
05 WS-NUM PIC .9(04).
05 WS-NUM1 PIC .9(03).
05 WS-NUM2 PIC .9(03).
MOVE '0001 222217' TO WS-NUM-TX.
COMPUTE WS-NUM = FUNCTION NUMVAL (WS-NUM-TX(1:4)) / 10000.
COMPUTE WS-NUM1 = FUNCTION NUMVAL (WS-NUM-TX(6:3)) / 1000.
COMPUTE WS-NUM2 = FUNCTION NUMVAL (WS-NUM-TX(9:3)) / 1000.
Based on the original post (revisions 1 and 2) with additional editing.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 FILLER.
05 WS-NUM-TX.
07 WS-NUM-TX1 PIC 9(4).
07 FILLER PIC X.
07 WS-NUM-TX2 PIC 9(3).
07 WS-NUM-TX3 PIC 9(3).
05 WS-NUM PIC .9(04).
05 WS-NUM1 PIC .9(03).
05 WS-NUM2 PIC .9(03).
PROCEDURE DIVISION.
BEGIN.
MOVE '0001 222217' TO WS-NUM-TX.
DIVIDE WS-NUM-TX1 BY 10000 GIVING WS-NUM.
DIVIDE WS-NUM-TX2 BY 1000 GIVING WS-NUM1.
DIVIDE WS-NUM-TX3 BY 1000 GIVING WS-NUM2.
DISPLAY WS-NUM
DISPLAY WS-NUM1
DISPLAY WS-NUM2
STOP RUN
.
Output:
.0001
.222
.217
Use V in the picture clause. This determines the position of the comma.
For example: PIC 9(05)V9(03) will result in 00000,000
Source: https://www.ibm.com/support/knowledgecenter/en/SS6SG3_4.2.0/com.ibm.entcobol.doc_4.2/PGandLR/ref/rlddesym.htm
I am still new to COBOL and have been working on a project for school for almost a week now. I am running OpenCobol 1.1.
When I try to compile it I get this error.
typeck.c:5912: Invalid type cast from 'null'
Tag 1 0 Tag 2 10
Aborting compile of lab4.cob at line 214
I've been frustrated because I've tried changing the code around a lot with no luck.
Procedure Division.
000-Main.
Perform 100-initialize
Perform Until EndOfFile = "Y"
Read Lab4-in-File
At End
Move "Y" To EndOfFile
Not At End
Perform 300-process
End-Read
End-Perform
Perform 900-finalize
Stop Run.
100-intialize.
Perform 110-open-files
Perform 120-get-data.
110-open-files.
Open Input Lab4-in-File
Output Ot-File.
120-get-date.
Accept WS-date from date yyyymmdd
Move WS-Year To PH-Year
Move WS-Month To PH-Month
Move WS-Day To PH-Day.
300-process.
Move Dept-no To dl-dep-no
Move Employee-no To dl-emp-no
If First-name Not = "Null"
String First-name Delimited By Size
" " Delimited By Size
Last-name Delimited By Size
Into dl-emp
else
Move Last-name To dl-emp
End-If
Move Job-title To dl-job
Move DOH To dl-doh
Move Mar-status To dl-marital
Move Dependents To dl-dependents
Move MCoverage To dl-insurance
Move DCoverage To dl-insurance
Move VCoverage To dl-insurance
Move 401K To dl-401k
Move Pay-code To dl-pay-code
If Pay-code = "C" Or "S"
Compute Pay-hold rounded =
Pay / 12
Move Pay-hold To dl-monthly-pay
else
Compute Pay-hold rounded =
Pay * HPW * 4
Move Pay-hold To dl-monthly-pay
End-If
If Pay-code = "C"
Compute Com-hold rounded =
Act-sale * C-rate
Move Com-hold To dl-commission
Else
Move 0 To dl-commission
End-If
Perform 800-print
Multiply C-rate By Act-sale Giving
total-sales
Add Pay To total-sales.
800-print.
If LineNum > LinesPerPage
Perform 825-new-page
End-If
Write Lab4-Record2 From Detail-Line
**After advancing 1 line** *> This is line 214
Add 1 To LineNum.
825-new-page.
If PageNum > 0
Write Lab4-Record2 From Blank-line
After advancing 1 line
End-If
Add 1 To PageNum
Move PageNum To PH-PageNo
Write Lab4-Record2 From Page-Header
After advancing page
Write Lab4-Record2 From Blank-line
After advancing 1 line
Write Lab4-Record2 From Column-Header
After advancing 1 line
Write Lab4-Record2 From Blank-line
After advancing 1 line
Move 5 To LineNum.
900-finalize.
Perform 950-print-monthly-total
Perform 999-close-files.
950-print-monthly-total.
If LineNum + 1 > LinesPerPage
Perform 825-new-page
End-If
Write Lab4-Record2 From Blank-line
After advancing 1 line
Move total-sales To Total-pay
Write Lab4-Record2 From Total-Line
After advancing 1 line
Add 2 To LineNum.
999-close-files.
Close Lab4-in-File Ot-File.
I would really appreciate it if someone could help me find what is causing the error. Thanks in advance!
Working-Storage Section.
01 EndOfFile Pic X Value "N".
01 Report-fields.
05 PageNum Pic 9(3) value 0.
05 LinesPerPage Pic 9(2) value 40.
05 LineNum Pic 9(2) value 41.
01 WS-date.
05 WS-Year Pic 9(4).
05 WS-Month Pic 99.
05 WS-Day Pic 99.
01 total-fields.
05 total-sales Pic 9(11)v99 Value 0.
01 Page-Header.
05 PH-Month Pic Z9/.
05 PH-Day Pic 99/.
05 PH-Year Pic 9999.
05 Pic X(7) Value Spaces.
05 Pic X(29) Value "Stomper &" &
" Wombat's Emporium"
05 Pic X(6) Value "Page:".
05 PH-PageNo Pic ZZ9.
01 Column-Header.
05 Pic X(8) Value "Dep #".
05 Pic X(15) Value "Emp #".
05 Pic X(27) Value "Employee".
05 Pic X(18) Value "Title".
05 Pic X(9) Value "DOH".
05 Pic X(9) Value "Marital".
05 Pic X(7) Value "#Deps".
05 Pic X(6) Value "Ins".
05 Pic X(6) Value "401K".
05 Pic X(6) Value "Pay".
05 Pic X(27) Value "Expected " &
"Pay + Commission".
01 Pay-hold Pic 9(9)V9(2) Value 0.
01 Com-hold Pic 9(9)V9(2) Value 0.
01 Detail-Line.
05 dl-dep-no Pic X(5).
05 Pic X(1) Value spaces.
05 dl-emp-no Pic X(5).
05 Pic X(1) Value spaces.
05 dl-emp Pic X(35).
05 Pic X(1) Value spaces.
05 dl-job Pic X(20).
05 Pic X(1) Value spaces.
05 dl-doh Pic X(8).
05 Pic X(1) Value spaces.
05 dl-marital Pic X.
05 Pic X(1) Value spaces.
05 dl-dependents Pic 9(2).
05 Pic X(1) Value spaces.
05 dl-insurance Pic X(3).
05 Pic X(1) Value spaces.
05 dl-401k Pic Z.9ZZ.
05 Pic X(1) Value spaces.
05 dl-pay-code Pic X.
05 Pic X(1) Value spaces.
05 dl-monthly-pay Pic $$$$,$$$,$$9.99.
05 Pic X(1) Value spaces.
05 dl-commission Pic $$$,$$9.99.
01 Total-Line.
05 Pic X(61) Value Spaces.
05 Pic X(24) Value "Total" &
" Expected Payroll: ".
05 Total-pay Pic $$$$,$$$,$$$,$$9.99.
01 Blank-line Pic X Value spaces.
The compiler has a broken parser. It is broken because of a coding error (still a compiler bug). In cases like this you only have the chance to either spot the error or - much better - use a newer version.
I've just put your code in an online compiler using the last release of the compiler: GnuCOBOL 2.2. I highly suggest to upgrade to at least this version.
See your code here - I've just added a minimal header and end.
Then click on "Execute" and you compile it online, leading to the following error messages:
main.cobc: 27: error: duplicate PICTURE clause
main.cobc: 27: error: duplicate VALUE clause
main.cobc: 64: error: a Z or * which is after the decimal point cannot follow 9
If you check the line 27 in this program you see
05 Pic X(29) Value "Stomper &" &
" Wombat's Emporium" *> <<- missing period
05 Pic X(6) Value "Page:".
Fixed code is also available.
I am getting errors concerning my procedure division in one of my assignments for class. It is a COBOL Program that is supposed to keep a running total of the average height and weight of applicants, number of brown-eyed applicants, number of male applicants, and number of female applicants. Also the program is supposed to print the info of applicants who meet a specific set of requirements but i'm getting errors for almost all of my perform statements
COBCH0034 Operand operand should be numeric
A numeric value is required in this context, and you have specified a nonnumeric value.
COBCH0014 Invalid operand
The operand you have specified is in some way incorrect, and cannot be processed by your COBOL system. For example, you might have specified a negative integer where only positive integers are allowed
identification division.
program-id. ELECTRA-MODELING-AGENCY.
******************************************************************
*THIS PROGRAM PRODUCES THE REPORT ACCORDING TO THE GIVEN PRINTER
*SPACING CHART *
******************************************************************
environment division.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO "INFILE.txt"
Organization is line sequential.
SELECT OUTPUT-FILE ASSIGN TO "CHOSEN-APLICANTS.TXT"
Organization is line sequential.
data division.
FILE SECTION.
FD INPUT-FILE.
01 INPUT-REC.
05 APPLICANTS-NAME PIC X(20).
05 APPLICANTS-WEIGHT PIC 9(3).
05 APPLICANTS-HEIGHT PIC 9(2).
05 APPLICANTS-EYE-CODE PIC X.
05 APPLICANTS-HAIR-CODE PIC X.
05 APPLICANTS-GENDER PIC X.
FD OUTPUT-FILE.
01 OUTPUT-REC PIC X(78).
WORKING-STORAGE SECTION.
01 EOF PIC X VALUE "N".
01 HEADING-1.
05 FILLER PIC X(41) VALUE "M"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "O"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "D"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "E"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "L"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "R"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "E"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "P"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "O"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "R"
JUSTIFIED RIGHT.
05 FILLER PIC X(2) VALUE "T"
JUSTIFIED RIGHT.
05 FILLER PIC X(16) VALUE SPACES.
01 HEADING-2.
05 FILLER PIC X(23) VALUE "NAME"
JUSTIFIED RIGHT.
05 FILLER PIC X(13) VALUE "SEX"
JUSTIFIED RIGHT.
05 FILLER PIC X(10) VALUE "WEIGHT"
JUSTIFIED RIGHT.
05 FILLER PIC X(8) VALUE "HEIGHT"
JUSTIFIED RIGHT.
05 FILLER PIC X(5) VALUE "EYE"
JUSTIFIED RIGHT.
05 FILLER PIC X(6) VALUE "COLOR"
JUSTIFIED RIGHT.
05 FILLER PIC X(6) VALUE "HAIR"
JUSTIFIED RIGHT.
05 FILLER PIC X(6) VALUE "COLOR"
JUSTIFIED RIGHT.
05 FILLER PIC X VALUE SPACES.
01 DETAIL-LINE.
05 FILLER PIC X(10) VALUE SPACES.
05 NAME-OUT PIC X(20).
05 FILLER PIC X(4) VALUE SPACES.
05 GENDER-OUT PIC X.
05 FILLER PIC X(6) VALUE SPACES.
05 WEIGHT-OUT PIC X(3).
05 FILLER PIC X(6) VALUE SPACES.
05 HEIGHT-OUT PIC XX.
05 FILLER PIC X(6) VALUE SPACES.
05 EYE-COLOR-OUT PIC X(5).
05 FILLER PIC X(6) VALUE SPACES.
05 HAIR-COLOR-OUT PIC X(6).
01 SUMMARY-LINE-01
05 FILLER PIC X(17) VALUE "AVERAGE"
JUSTIFIED RIGHT.
05 FILLER PIC X(7) VALUE "HEIGHT"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "OF"
JUSTIFIED RIGHT.
05 FILLER PIC X(4) VALUE "ALL"
JUSTIFIED RIGHT.
05 FILLER PIC X(12) VALUE "APPLICANTS:"
JUSTIFIED RIGHT.
05 FILLER PIC X.
05 AVERAGE-HEIGHT PIC ZZZ9.
05 FILLER PIC X(12) VALUE SPACES.
01 SUMMARY-LINE-02
05 FILLER PIC X(17) VALUE "AVERAGE"
JUSTIFIED RIGHT.
05 FILLER PIC X(7) VALUE "WEIGHT"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "OF"
JUSTIFIED RIGHT.
05 FILLER PIC X(4) VALUE "ALL"
JUSTIFIED RIGHT.
05 FILLER PIC X(12) VALUE "APPLICANTS:"
JUSTIFIED RIGHT.
05 FILLER PIC X.
05 AVERAGE-WEIGHT PIC ZZZ9.
05 FILLER PIC X(12) VALUE SPACES.
01 SUMMARY-LINE-03
05 FILLER PIC X(16) VALUE "NUMBER"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "OF"
JUSTIFIED RIGHT.
05 FILLER PIC X(11) VALUE "BROWN-EYED"
JUSTIFIED RIGHT.
05 FILLER PIC X(12) VALUE "APPLICANTS:"
JUSTIFIED RIGHT.
05 FILLER PIC XX.
05 BROWN-EYED-APPLICANTS PIC ZZZ9.
05 FILLER PIC X(12) VALUE SPACES.
01 SUMMARY-LINE-04
05 FILLER PIC X(16) VALUE "NUMBER"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "OF"
JUSTIFIED RIGHT.
05 FILLER PIC X(5) VALUE "MALE"
JUSTIFIED RIGHT.
05 FILLER PIC X(12) VALUE "APPLICANTS:"
JUSTIFIED RIGHT.
05 FILLER PIC X(8) VALUE SPACES.
05 MALE-APPLICANTS PIC ZZZ9.
05 FILLER PIC X(12) VALUE SPACES.
01 SUMMARY-LINE-05
05 FILLER PIC X(16) VALUE "NUMBER"
JUSTIFIED RIGHT.
05 FILLER PIC X(3) VALUE "OF"
JUSTIFIED RIGHT.
05 FILLER PIC X(7) VALUE "FEMALE"
JUSTIFIED RIGHT.
05 FILLER PIC X(11) VALUE "APPLICANTS:"
JUSTIFIED RIGHT.
05 FILLER PIC X(6) VALUE SPACES.
05 FEMALE-APPLICANTS PIC ZZZ9.
05 FILLER PIC X(12) VALUE SPACES.
procedure division.
100-main.
OPEN INPUT INPUT-FILE
OUTPUT OUTPUT-FILE
PERFORM UNTIL EOF = 'Y'
READ INPUT-FILE
AT END MOVE 'Y' TO EOF
NOT AT END
PERFORM 200-HEADING.
PERFORM 200-AVG-HEIGHT.
PERFORM 200-AVG-WEIGHT.
PERFORM 200-BROWN-EYED-APPS.
PERFORM 200-MALE-APPS.
PERFORM 200-FEMALE-APPS.
PERFORM 200-MALE-DETAIL-LINE.
PERFORM 200-FEMALE-DETAIL-LINE.
CLOSE INPUT-FILE, OUTPUT-FILE.
STOP RUN.
200-HEADING.
WRITE OUTPUT-REC FROM HEADING-1.
MOVE SPACES TO OUTPUT-REC.
WRITE OUTPUT-REC.
WRITE OUTPUT-REC FROM HEADING-2.
MOVE SPACES TO OUTPUT-REC.
WRITE OUTPUT-REC.
200-AVG-HEIGHT.
IF NOT AT END
ADD APPLICANTS-HEIGHT TO AVERAGE-HEIGHT
ELSE AT END
DIVIDE AVERAGE-HEIGHT BY 21.
WRITE OUTPUT-REC FROM SUMMARY-LINE-01.
200-AVG-WEIGHT.
IF NOT AT END
ADD APPLICANTS-WEIGHT TO AVERAGE-WEIGHT
ELSE AT END
DIVIDE AVERAGE-HEIGHT BY 21.
WRITE OUTPUT-REC FROM SUMMARY-LINE-02.
200-BROWN-EYED-APPS.
IF APPLICANTS-EYE-CODE = 2
ADD 1 TO BROWN-EYED-APPLICANTS
ELSE CONTINUE.
WRITE OUTPUT-REC FROM SUMMARY-LINE-03.
200-MALE-APPS.
IF APPLICANTS-GENDER = M
ADD 1 TO MALE-APPLICANTS
ELSE CONTINUE.
WRITE OUTPUT-REC FROM SUMMARY-LINE-04.
200-FEMALE-APPS.
IF APPLICANTS-GENDER = F
ADD 1 TO FEMALE-APPLICANTS
ELSE CONTINUE.
WRITE OUTPUT-REC FROM SUMMARY-LINE-05.
200-MALE-DETAIL-LINE.
IF APPLICANTS-HAIR-CODE = 1
IF APPLICANTS-EYE-CODE = 1
IF APPLICANTS-GENDER = M
IF APPLICANTS-HEIGHT >= 72
IF 185 <= APPLICANTS-WEIGHT <= 200
ELSE CONTINUE.
WRITE OUTPUT-REC FROM 01 DETAIL-LINE.
200-FEMALE-DETAIL-LINE.
IF APPLICANTS-HAIR-CODE = 2
IF APPLICANTS-EYE-CODE = 2
IF APPLICANTS-GENDER = F
IF 62 <= APPLICANTS-HEIGHT <= 64
IF 110 <= APPLICANTS-WEIGHT <= 125
ELSE CONTINUE.
WRITE OUTPUT-REC FROM 01 DETAIL-LINE.
end program ELECTRA-MODELING-AGENCY.
So you have several things that are going wrong here. Let me detail a few of them and give you some hints to fix them.
You are using periods to end statements, this is awful and bad when you mix it with some of the newer (and by newer, i mean only 30 years old) style of statements, like inline perform and read/at end/not at end/end-read.
Instead of this:
PERFORM UNTIL EOF = 'Y'
READ INPUT-FILE
AT END MOVE 'Y' TO EOF
NOT AT END
PERFORM 200-HEADING.
PERFORM 200-AVG-HEIGHT.
PERFORM 200-AVG-WEIGHT.
PERFORM 200-BROWN-EYED-APPS.
PERFORM 200-MALE-APPS.
PERFORM 200-FEMALE-APPS.
PERFORM 200-MALE-DETAIL-LINE.
PERFORM 200-FEMALE-DETAIL-LINE.
CLOSE INPUT-FILE, OUTPUT-FILE.
STOP RUN.
You need something like this:
PERFORM UNTIL EOF = 'Y' <--- This is better as an 88 level
READ INPUT-FILE
AT END MOVE 'Y' TO EOF
NOT AT END
PERFORM SOMETHING <--- You need to accumulate you data here
END-READ
END-PERFORM
PERFORM 200-HEADING
PERFORM 200-AVG-HEIGHT
PERFORM 200-AVG-WEIGHT
PERFORM 200-BROWN-EYED-APPS
PERFORM 200-MALE-APPS
PERFORM 200-FEMALE-APPS
PERFORM 200-MALE-DETAIL-LINE
PERFORM 200-FEMALE-DETAIL-LINE
CLOSE INPUT-FILE, OUTPUT-FILE
STOP RUN. <--- This is the only period you need
<--- In your mainline
You can not do this:
200-AVG-HEIGHT.
IF NOT AT END <--- NOT AT END and AT END only work
<--- in the context of a READ statement
ADD APPLICANTS-HEIGHT TO AVERAGE-HEIGHT
ELSE AT END
DIVIDE AVERAGE-HEIGHT BY 21.
WRITE OUTPUT-REC FROM SUMMARY-LINE-01.
While you are looping through the file, accumulate the total height by adding each applicants to APPLICANTS-HEIGHT and adding 1 to your APPLICANTS-COUNT. When you are ready to do your summary line for height, do this:
200-AVG-HEIGHT.
DIVIDE APPLICANTS-HEIGHT BY APPLICANTS-COUNT
WRITE OUTPUT-REC FROM SUMMARY-LINE-01
. <---- Again, you only need a single period to end a paragraph
In all of your paragraphs, you are trying to accumulate your data AND write your summary line. This does not work. See the perform loop above where I have the "Perform Something To Accumulate your data", this is the paragraph you want to put all of your code that adds up every applicant. You need separate paragraphs, as you have, to write the summary lines.
So this should happen every record:
200-MALE-DETAIL-LINE.
IF APPLICANTS-HAIR-CODE = 1
IF APPLICANTS-EYE-CODE = 1
IF APPLICANTS-GENDER = M
IF APPLICANTS-HEIGHT >= 72
IF 185 <= APPLICANTS-WEIGHT <= 200
ELSE CONTINUE. <--- you are doing nothing here
WRITE OUTPUT-REC FROM 01 DETAIL-LINE.
It is better written like this:
200-MALE-DETAIL-LINE.
IF APPLICANTS-HAIR-CODE = 1
AND APPLICANTS-EYE-CODE = 1
AND APPLICANTS-GENDER = M
AND APPLICANTS-HEIGHT >= 72
AND (185 <= APPLICANTS-WEIGHT <= 200)
WRITE OUTPUT-REC FROM 01-DETAIL-LINE
END-IF
That should get you going. You will need to apply these hints to all the other paragraphs. In brief, your program should generally look like this:
Open Files
Perform until EOF
Read a-record
not at end
Perform Do-Detail-Lines
at end
Set EOF to true
End-Read
End-Perform
Perform Do-Summary-Lines
Close files
Stop Run.
Do-Detail-Lines.
...add up all the things you are averaging and counting...
...populate detail line...
write output-rec from detail-line
.
Do-Summary-Lines.
...calculate all averages...
...populate summary line...
write output-red from summary-line
...repeat as needed for other summary-lines...
.
Happy coding :-)
I am trying to finish a program that I have started but am confused as to what I need to do and how to do the last step. The instructions are to:
At the end of report:
A. Print the number of personnel records processed.
B. The number of records where there was an unsuccessful search of the Dept Table.
C. The number of records where there was an unsuccessful search of the Title Table.
I have completed all of the program except this last step. Can someone please help me finish this program?
enter code here ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PERSONNEL-FILE
ASSIGN TO 'CH12PPPF.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT DEPT-TABLE-FILE
ASSIGN TO 'CH12PPDT.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT TITLE-TABLE-FILE
ASSIGN TO 'CH12PPTT.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT PRINT-FILE
ASSIGN TO 'THORNTONCA4.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD PERSONNEL-FILE.
01 PERSONNEL-REC.
05 SSNO-IN PIC 9(9).
05 NAME-IN PIC X(20).
05 SALARY-IN PIC 9(6).
05 CAMPUS-CODE-IN PIC 9.
05 DEPT-CODE-IN PIC 99.
05 TITLE-CODE-IN PIC 999.
FD DEPT-TABLE-FILE.
01 DEPT-REC.
05 T-DEPT-NO PIC 99.
05 T-DEPT-NAME PIC X(10).
FD TITLE-TABLE-FILE.
01 TITLE-REC.
05 T-TITLE-CODE PIC 999.
05 T-TITLE-NAME PIC X(10).
FD PRINT-FILE.
01 PRINT-REC PIC X(80).
WORKING-STORAGE SECTION.
01 STORED-AREAS.
05 MORE-RECS PIC X(3) VALUE 'YES'.
05 WS-DATE.
10 WS-YEAR PIC 9999.
10 WS-MONTH PIC 99.
10 WS-DAY PIC 99.
05 WS-PAGE-CT PIC 99
VALUE ZERO.
05 WS-LINE-CT PIC 99
VALUE ZERO.
01 HDR1-OUT.
05 PIC X(25)
VALUE SPACES.
05 PIC X(20)
VALUE 'FINAL REPORT'.
05 DATE-OUT.
10 MONTH-OUT PIC 99.
10 PIC X
VALUE '/'.
10 DAY-OUT PIC 99.
10 PIC X
VALUE '/'.
10 YEAR-OUT PIC 9999.
05 PIC X(2)
VALUE SPACES.
05 PIC X(5)
VALUE 'PAGE'.
05 PAGE-OUT PIC Z9.
*****************************************************************
* The Campus Table consists of 5 10-position names and will be *
* accessed as a direct-referenced table. EACH_CAMPUS *
* subscriped by the CAMPUS_CODE_IN will provide the name. *
*****************************************************************
01 CAMPUTS-TABLE
VALUE 'UPSTATE DOWNSTATE CITY MELVILLE HUNTINGTON'.
05 EACH-CAMPUS
OCCURS 5 TIMES PIC X(10).
*****************************************************************
* The Dept Table will be accessed by a SEARCH. Even if the *
* table is entered in Dept No sequence, there would be no *
* real benefit to using a SEARCH ALL since there are only *
* 25 entries. *
*****************************************************************
01 DEPT-TABLE.
05 DEPT-ENTRIES OCCURS 25 TIMES INDEXED BY X1.
10 DEPT-NO PIC 99.
10 DEPT-NAME PIC X(10).
*****************************************************************
* The Title Talbe will be accessed by a SEARCH ALL. To use a *
* binary seach the entries must be in sequence by a key *
* field and the table should be relatively large. *
*****************************************************************
01 TITLE-TABLE.
05 TITLE-ENTRIES OCCURS 50 TIMES
ASCENDING KEY IS TITLE-NO INDEXED BY X2.
10 TITLE-NO PIC 999.
10 TITLE-NAME PIC X(10).
01 DETAIL-REC.
05 PIC X(1) VALUE SPACES.
05 SSNO-OUT PIC 999B99B9999.
05 PIC X(1) VALUE SPACES.
05 NAME-OUT PIC X(20).
05 PIC X(1) VALUE SPACES.
05 SALARY-OUT PIC $ZZZ,ZZZ.
05 PIC X(1) VALUE SPACES.
05 CAMPUS-OUT PIC X(10).
05 PIC X(1) VALUE SPACES.
05 DEPT-OUT PIC X(10).
05 PIC X(1) VALUE SPACES.
05 TITLE-OUT PIC X(10).
PROCEDURE DIVISION.
100-MAIN-MODULE.
OPEN INPUT PERSONNEL-FILE
DEPT-TABLE-FILE
TITLE-TABLE-FILE
OUTPUT PRINT-FILE
MOVE FUNCTION CURRENT-DATE TO WS-DATE
MOVE WS-MONTH TO MONTH-OUT
MOVE WS-DAY TO DAY-OUT
MOVE WS-YEAR TO YEAR-OUT
PERFORM 500-HDG-RTN.
PERFORM 200-LOAD-DEPT-TABLE
PERFORM 300-LOAD-TITLE-TABLE
PERFORM UNTIL MORE-RECS = 'NO '
READ PERSONNEL-FILE
AT END
MOVE 'NO ' TO MORE-RECS
NOT AT END
PERFORM 400-CALC-RTN
END-READ
END-PERFORM
CLOSE PERSONNEL-FILE
DEPT-TABLE-FILE
TITLE-TABLE-FILE
PRINT-FILE
STOP RUN.
200-LOAD-DEPT-TABLE.
PERFORM VARYING X1 FROM 1 BY 1
UNTIL X1 > 25
READ DEPT-TABLE-FILE
AT END DISPLAY 'NOT ENOUGH DEPT TABLE RECORDS'
STOP RUN
END-READ
MOVE DEPT-REC TO DEPT-ENTRIES (X1)
END-PERFORM.
300-LOAD-TITLE-TABLE.
PERFORM VARYING X2 FROM 1 BY 1
UNTIL X2 > 50
READ TITLE-TABLE-FILE
AT END DISPLAY 'NOT ENOUH TITLE TABLE RECORDS'
STOP RUN
END-READ
MOVE TITLE-REC TO TITLE-ENTRIES (X2)
IF X2 > 1 THEN
IF TITLE-NO (X2) <= TITLE-NO (X2 - 1)
DISPLAY 'TITLE RECORDS ARE NOT IN SEQUENCE'
STOP RUN
END-IF
END-IF
END-PERFORM.
400-CALC-RTN.
MOVE SPACES TO DETAIL-REC
MOVE SSNO-IN TO SSNO-OUT
MOVE NAME-IN TO NAME-OUT
MOVE SALARY-IN TO SALARY-OUT
IF CAMPUS-CODE-IN >= 1 AND <= 5
MOVE EACH-CAMPUS (CAMPUS-CODE-IN) TO CAMPUS-OUT
END-IF
SET X1 TO 1
SEARCH DEPT-ENTRIES
AT END MOVE 'XXXXXXXXXX' TO DEPT-OUT
WHEN DEPT-CODE-IN = DEPT-NO (X1)
MOVE DEPT-NAME (X1) TO DEPT-OUT
END-SEARCH
SEARCH ALL TITLE-ENTRIES
AT END MOVE 'XXXXXXXXXX' TO TITLE-OUT
WHEN TITLE-NO (X2) = TITLE-CODE-IN
MOVE TITLE-NAME (X2) TO TITLE-OUT
END-SEARCH
WRITE PRINT-REC FROM DETAIL-REC
AFTER ADVANCING 2 LINES.
500-HDG-RTN.
ADD 1 TO WS-PAGE-CT
MOVE WS-PAGE-CT TO PAGE-OUT
WRITE PRINT-REC FROM HDR1-OUT
AFTER ADVANCING PAGE
MOVE ZEROS TO WS-LINE-CT.
You need to:
Produce code to accumulate all the values you need to print at the end
Produce definition(s) of the final part of the report
Produce the final part of report once the main input file has been processed, ie after your first PERFORM and before the CLOSE
You should get into the habit of checking all file statuses after each IO operation, using FILE-STATUS, and accurately report when something unexpected happens.
You'll find it worthwhile to give good names even to indexes, and use 88s wherever possible for IF or EVALUATE and avoid using things like this "IF CAMPUS-CODE-IN >= 1 AND <= 5".