Re: Report enhancements

From: Lueko Willms (l.willms_at_jpberlin.de)
Date: 11/02/04


Date: 02 Nov 2004 15:24:00 GMT


. On 29.10.04
  wrote ricksmith@mfi.net (Rick Smith)
     on /COMP/LANG/COBOL
     in 10o5kbsmbg43h0b@corp.supernews.com
  about Re: Report enhancements

RS>
RS> Apparently, my vision is quite selective and I did not
RS> see that phrases were buried within phrases. By
RS> "qualifying phrase," I intended the TIMES, UNTIL,
RS> and VARYING phrases.

>>> There are three distinct phrases: TIMES, UNTIL, and
>>> VARYING. You seem to be treating VARYING as an
>>> variation of UNTIL; it is not.
>>
>> Do you have a form of VARYING that does not require the UNTIL ?

RS> I have no form of VARYING that is not in the standard
RS> and the standard specifies that VARYING and UNTIL
RS> are separate phrases.

   Sure, but VARYING does not provide a terminating condition. One
could as well add or subtract the counter value being VARYied within
the loop.

   Decisive is the UNTIL-clause which determines which condition
prevents the loop being entered (WITH TEST BEFORE) or being exited
(WITH TEST AFTER).

   So, actually there are only two ways to formulate the termination
of a loop in COBOL:

   PERFORM ... TIMES

   (when the number of occurences is known beforehand)

and

   PERFORM UNTIL some-condition

  (when there is a finite, but yet unknown number of occurrences).

   Instead of

     READ input-record
     PERFORM UNTIL has-reached-end-of-file
       VARYING record-counter FROM 1 BY 1
       do-something-with-the-record
       READ input-record
     END-PERFORM

   one could also write:

     READ input-record
     PERFORM UNTIL has-reached-end-of-file
       ADD 1 TO record-counter
       do-something-with-the-record
       READ input-record
     END-PERFORM

   and it is functionally the same. For nested VARYINGs one might
simply write nested loops, like this:

    MOVE ZERO TO outer-counter
    PERFORM UNTIL NOT outer-loop-entry-condition
      ADD 1 TO outer-counter
      MOVE ZERO to inner-counter
      PERFORM UNTIL NOT inner-loop-entry-condition
        ADD 1 TO inner-counter
        do-something-cute
           *> e.g. using the inner and outer counter
           *> as subscripts into a table,
      END-PERFORM
    END-PERFORM

   instead of

    PERFORM UNTIL NOT outer-loop-entry-condition
            VARYING outer-counter FROM 1 BY 1
         AFTER VARYING inner-counter FROM 1 BY 1
           UNTIL NOT inner-loop-entry-condition

      do-something-with-it
    END-PERFORM

    Frankly, in all those years that I was programming COBOL for
production, I always had problems figuring out what was the outer and
inner loop of the nested VARYING.

Yours,
Lüko Willms http://www.willms-edv.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --

Man kann wirklich nicht wissen ob man nicht jetzt im Tollhaus sitzt. -G.C.Lichtenberg



Relevant Pages

  • Re: Report enhancements
    ... >> qualifying phrase means exactly the same as its absence. ... see that phrases were buried within phrases. ... and VARYING phrases. ... "The loop-with-exit loop is a one-entry, one-exit, structured ...
    (comp.lang.cobol)
  • database-driven varying content of title and alt tags
    ... I read somewhere that the search engines like to see content varying ... six phrases from a database of several hundred, ...
    (alt.internet.search-engines)
  • Re: EXIT PERFORM Help, please [LONG response]
    ... > misunderstood as saying that the UNTIL condition in a PERFORM VARYING ... is where the "philosophy" (as documented in the site standards) comes in. ... > the UNTIL condition as the general condition to enter the loop, ... I don't believe there is any such "misunderstanding". ...
    (comp.lang.cobol)
  • Re: EXIT PERFORM Help, please [LONG response]
    ... COBOL's version of the FOR loop: ... misunderstood as saying that the UNTIL condition in a PERFORM VARYING ... PD> or other" Could you translate, ... Er kann die Tinte nicht halten, und wenn es ihm ankommt, jemand zu besudeln, so besudelt er sich gemeiniglich am meisten. ...
    (comp.lang.cobol)
  • simplifying repetitive routines in VBA
    ... I have a code to copy a (varying) range from one file to 25 other files. ... Sub Repetitive_macro ... '1st loop ... SkipBlanks _ ...
    (microsoft.public.excel.programming)