Domanda

On this read statement below couldn't it be made into the form of the following? I think personaly it might be easier to understand and read.

Basically the read statement is simply reading through a file and making decision on which paragraph performs should be executed. It probably is difficult to see exaclty what the program does but what I was really interested to know was if you can change the read to a different format as listed below.

READ DATA-FILE AT END ...do some code NOT AT END ...do code that is below END-READ.

Class:

    INIT-READ.                                            
    READ C AT END                                
            GO TO EOJ.                                
    IF C-ID = '  ' AND C-S = 'P'            
       GO TO I-R                                
    END-IF.                                           
    IF CID = ' ' AND C-S = 'D'             
       IF F = 'Y'                                   
          MOVE 'N' TO F                             
          MOVE 'your text here' TO RPT-ID 
          MOVE A           TO H6                  
          MOVE B           TO H7                  
          PERFORM PA THRU H-A-X             
       END-IF                                         
          PERFORM WD-CLAIM THRU W-X            
       GO TO I-R                                
    END-IF.                                           
          PERFORM N-V THRU N-V-X.             
È stato utile?

Soluzione

At the bottom of a discussion thread, captured in the GNU Cobol FAQ, http://opencobol.add1tocobol.com/gnucobol/#performing-forever Roger While mentioned a pretty nice idiom for READ control without paragraphs.

One thing that I saw on earlier posts to the newsgroup cobol was

What is the need/justification for an empty inline perform group.

ie. PERFORM ... END-PERFORM

None of the discussions then realized that there is a - EXIT PERFORM [CYCLE]

Therefore, it is a method to to define an exit condition without having paragraphs.

ie. (very simply)

PERFORM
    READ xxx
      AT END
        EXIT PERFORM
    END-READ
    MOVE something TO somewhere
END-PERFORM

.. test xxx status and somewhere

There are, of course, other variations. Basically, it means that you code without using section/paragraphs. (Recommended, if only from performance point of view)

Note that the CYCLE option offers interesting possibilities.

Roger

Altri suggerimenti

Have a look here. COBOL read/store in table. for a way of avoiding GO TO, and even the AT END/NOT AT END. No END-READ needed either.

To avoid the AT END/NOT AT END, simply use the File Status, which you should already be using anyway to check that all IO operations were successful. For an input file, READ will give a file status of 10 when end-of-file is detected.

Use an 88 on your file status. So you can say things like END-OF-PAYMENTS-TRANSACTIONS.

Then, to process your file, you use a "priming read". This is a read outside the loop.

priming read
processing-loop until END-OF-PAYMENTS-TRANSACTIONS
   do the processing
   read

EXIT PERFORM (and some other EXIT options) is not available in all COBOLs currently. Be aware that if you are part of a large team and put an EXIT PERFORM in your program you will likely find several EXIT PERFORMs in the same block of code within a couple of years. So they may have well been GO TOs all along. The new EXIT options are just a way of have a GO TO which is spelled differently. OK, a little tongue-in-cheek, but there we go.

Of course, the priming read and read above both PERFORM a single paragraph to do the actual read and check the validity of the io (file status zero or 10 is OK, else a problem).

Be careful about considering avoiding PERFORM paragraph/SECTION for "performance". Write for clarity unless performance is critical. With IBM's Enterprise COBOL, using OPT, PERFORM code can be "inlined" anyway.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top