Bill, I thought you just said you'd never seen this before on the mainframe!  
:-)


I'm going to sidetrack this a bit to try to plug EXIT PERFORM.  Yes, I know you 
(Bill) don't like it.  But I'm curious on others thoughts about the following 
(taking your program and changing it):

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       ID DIVISION.
       PROGRAM-ID. CALC1000.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       01                                      PIC X VALUE LOW-VALUES.
           88  EXIT-OF-PERFORM                       VALUE HIGH-VALUES.
       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 UNTIL EXIT-OF-PERFORM
               PERFORM                  READ-DATA
               IF END-OF-INTERACTIVE-SESSION
                   EXIT PERFORM
               END-IF
               PERFORM                  CALCULATE-ONE-SALES-TAX
           END-PERFORM
           GOBACK
           .
       CALCULATE-ONE-SALES-TAX.
           COMPUTE SALES-TAX ROUNDED    = SALES-AMOUNT
                                         * 0.0785
           DISPLAY
                   SALES-AMOUNT
                   " SALES TAX = "
                   SALES-TAX
           PERFORM                      READ-DATA
           .
       READ-DATA.
           MOVE HIGH-VALUES             TO INPUT-DATA
           ACCEPT INPUT-DATA
           .


The good (in my mind):

- There is one and only one "point of input".  No explicit "priming read".

- It is more obvious that you are processing the input and then looping back to 
read the next input.  (And then exiting without processing (*) if there is no 
more input.)


The bad (in my mind):

The COBOL standard (#) does not support:

- a comparison of two literals (IF 0 = 1)

- a "infinite/unbounded loop" (PERFORM UNTIL EXIT)


MicroFocus COBOL and GNU COBOL both have the "non-standard" PERFORM UNTIL EXIT 
/ PERFORM FOREVER.

Fujitsu COBOL has the "non-standard" PERFORM WITH NO LIMIT.

IBM Enterprise COBOL has nothing similar and IBM refuses to implement one.  
(Yes, I'm obsessive and upset about this.)


(*) The following might make it more apparent that we're not doing processing 
if there is no more input:

           PERFORM UNTIL EXIT-OF-PERFORM
               PERFORM                  READ-DATA
               IF END-OF-INTERACTIVE-SESSION
                   EXIT PERFORM
               ELSE
                   PERFORM              CALCULATE-ONE-SALES-TAX
               END-IF
           END-PERFORM

Frank



________________________________
From: IBM Mainframe Discussion List <[email protected]> on behalf of 
Bill Woodger <[email protected]>
Sent: Sunday, July 10, 2016 11:24 AM
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

Reply via email to