The original program includes the following statements:
DISPLAY "TO END PROGRAM, ENTER 0.".
DISPLAY "TO CALCULATE SALES TAX, ENTER THE SALES AMOUNT.".
The above statements are executed prior to "ACCEPT"ing every inputted amount.
If the intent of this program was to receive input from a file, why would these
statements be within the source? Why would they be repeatedly executed?
-----Original Message-----
From: IBM Mainframe Discussion List [mailto:[email protected]] On Behalf
Of Bill Woodger
Sent: Sunday, July 10, 2016 12:25 PM
To: [email protected]
Subject: Error in a simple COBOL program
Here's one with the priming read, and a little trick for multiple ACCEPTs,
because ACCEPT doesn't give "end of file".
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
ID DIVISION.
PROGRAM-ID. CALC1000.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 INPUT-DATA.
05 FILLER.
88 END-OF-INTERACTIVE-SESSION VALUE HIGH-VALUES
ZERO.
10 SALES-AMOUNT PIC 9(5)V99.
05 FILLER PIC X(73).
01 SALES-TAX PIC Z,ZZZ.99.
PROCEDURE DIVISION.
PERFORM PRIMING-READ
PERFORM CALCULATE-ONE-SALES-TAX
UNTIL END-OF-INTERACTIVE-SESSION
GOBACK
.
CALCULATE-ONE-SALES-TAX.
COMPUTE SALES-TAX ROUNDED = SALES-AMOUNT
* 0.0785
DISPLAY
SALES-AMOUNT
" SALES TAX = "
SALES-TAX
PERFORM READ-DATA
.
PRIMING-READ.
PERFORM READ-DATA
.
READ-DATA.
MOVE HIGH-VALUES TO INPUT-DATA
ACCEPT INPUT-DATA
.
The trick is through the knowledge that when ACCEPT operates and there is no
remaining data, the target field (INPUT-DATA) remains unchanged. So set the
target-field to a known value which cannot exist (logically) in the input, and
you have an end-of-file test. In this case this is a catch-all for if the
"user" gets the "I don't want any more" response wrong when using a dataset for
input.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send email to
[email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN