Re: Report enhancements
From: Lueko Willms (l.willms_at_jpberlin.de)
Date: 11/02/04
- Next message: Jeff York: "Re: Infinite Loops and Explicit Exits"
- Previous message: Lueko Willms: "Re: Infinite Loops and Explicit Exits"
- Maybe in reply to: Robert Wagner: "Re: Report enhancements"
- Next in thread: Howard Brazee: "Re: Report enhancements"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Jeff York: "Re: Infinite Loops and Explicit Exits"
- Previous message: Lueko Willms: "Re: Infinite Loops and Explicit Exits"
- Maybe in reply to: Robert Wagner: "Re: Report enhancements"
- Next in thread: Howard Brazee: "Re: Report enhancements"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|