Thanks for this example. I was looking for a way to not test for the first
iteration every time. Another example illustrated it and kept it goto-less.
I can honestly say that in all my years of MV, no prior programmers or VARs
to my client's systems used LOOP-REPEAT for READNEXT and that virtually
every one was the
10 READNEXT ID ELSE GOTO 19
READ REC FROM F.FILE, ID ELSE GOTO 10
(process)
GOTO 10
scenario.
My Client's packages include Media Services Group, SHIMS, Results, Service
Automation Systems, Primac, GULL, Infoquest, IDS, DataMaster, Wizard, and a
whole slew of home-grown systems and they all use GOTO's in a logical sense
and yes, some in an illogical sense. But none are the GOTO-less environments
that everyone seems to harp upon.
I just wanted to see how it was done. You've answered all of my questions.
Thanks.
----- Original Message -----
From: "Dennis Bartlett" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, June 21, 2004 5:07 AM
Subject: RE: [U2] [UV] WHILE READNEXT id DO {{not a holy war,just a code
example)
> SORT CUSTOMER
> BY STATE
> BY CITY
> {showing} NAME
> BREAK-ON CITY
> BREAK-ON STATE
> TOTAL YTD-SALES
>
>
> ORDERS File layout
> ------------------
> <0> Order Number
> <1> State
> <2> City
> <3> Cust.Name (for purpose of example)
> <4> Sales by month position (ie 12 multivals)
>
>
> PROGRAM YTD.SALES.RPT
> * author : d.bartlett
> * written : 21 June 04
> * example of GOTO-less code in a break-on environment
> * ---------------------------------------------------
> * Assumes there won't be a city in a different state
> * with the same name / code
> * ---------------------------------------------------
> OPEN 'ORDERS' TO CUSTOMER ELSE STOP 201,'CUSTOMER'
> TODAY = OCONV(DATE(),'D2/') ; * assumes dd/mm/yy
> PERIOD = TODAY[4,2] ; * assumes simple periods
> CUST.YTD.SALES = 0
> LPT.WIDTH = 80
> STATE.SALES = 0
> CITY.SALES = 0
> CUST.SALES = 0
> TOT.SALES = 0
> LAST.STATE = ''
> LAST.CITY = ''
>
> * --------------------------------------------------
> * select data - assumes I can still use select-by
> * - if not, we do a two stage pass
> * (1) process file,
> * using locate to sequence state*city
> * build array1 = state*city } state*city*
> * build array2 = orderno
> *
> * (2) process sorted array1 with REMOVE
> * MORE = 1
> * LOOP
> * REMOVE KEY FROM ARRAY1 SETTING MORE
> * REMOVE ORDERNO FROM ARRAY2 SETTING JUNK
> * * --> process
> * WHILE MORE
> * REPEAT
> *
> * Limitations are size, speed
> * --------------------------------------------------
> CMD = 'SELECT CUSTOMER'
> CMD := ' BY STATE'
> CMD := ' BY CITY'
> CRT 'Selecting data - please wait'
> EXECUTE CMD CAPTURING X RETURNING Y
>
> IF (Y < 1) THEN
> MSG = 'No records were found matching'
> MSG := ' your selection'
> CRT MSG :; INPUT REPLY
> END ELSE
> CRT Y : ' records selected'
> GOSUB PROCESS.ORDERS
> END
> CRT @(-1)
> STOP
> * =================================================
> PROCESS.ORDERS:
> LOOP
> READNEXT ORDERNO ELSE DONE = 1
> UNTIL (DONE = 1)
> READ ORDREC FROM ORDERS, ORDERNO THEN
> GOSUB PARSE.ORDER
> GOSUB ACCUM.YTD
>
> * initialise temp variables
> IF (LAST.STATE = '') THEN
> LAST.STATE = STATE
> LAST.CITY = CITY
> END
>
> * test if city has changed?
> IF (CITY NE LAST.CITY) THEN GOSUB CITY.TOTALS
>
> * test if state has changed?
> IF (STATE NE LAST.STATE) THEN GOSUB STATE.TOTALS
>
> * print a detail line
> CRT NAME 'L#40' :
> CRT OCONV(YTD.SALES, 'MD2') 'R#15'
> END
> REPEAT
>
> * final CITY totals
> GOSUB CITY.TOTALS
> GOSUB STATE.TOTALS
> GOSUB FINAL.TOTAL
> RETURN
> * ---------------------------------------------------
> PARSE.ORDER:
> * <0> Order Number
> * <1> State
> * <2> City
> * <3> Cust.ID
> * <4> Cust.Name (for purpose of example)
> * <5> Sales by month position (ie 12 multivals)
> STATE = ORDREC<1>
> CITY = ORDREC<2>
> NAME = ORDREC<3>
> SALES = ORDREC<4>
> RETURN
> * ---------------------------------------------------
> ACCUM.YTD:
> CUST.SALES = 0
> FOR P = 1 TO PERIOD
> CUST.SALES += OR.SALES<1,P>
> NEXT P
> STATE.SALES += CUST.SALES
> CITY.SALES += CUST.SALES
> TOT.SALES += CUST.SALES
> RETURN
> * ---------------------------------------------------
> CITY.TOTALS:
> CRT SPACE(40) :
> CRT STR('-',15)
>
> CRT SPACE(40) :
> CRT OCONV(CITY.SALES, 'MD2') 'R#15'
>
> LAST.CITY = CITY
> CITY.SALES = 0
> RETURN
> * ---------------------------------------------------
> STATE.TOTALS:
> CRT
>
> CRT SPACE(40) :
> CRT STR('=',15)
>
> CRT SPACE(40) :
> CRT OCONV(STATE.SALES, 'MD2') 'R#15'
>
> STATE.SALES = 0
> LAST.STATE = STATE
> RETURN
> * ---------------------------------------------------
> FINAL.TOTAL:
> CRT
>
> CRT STR('=',LPT.WIDTH)
> CRT SPACE(40) :
>
> CRT OCONV(TOT.SALES, 'MD2') 'R#15'
> CRT STR('=',LPT.WIDTH)
> RETURN
> * ---------------------------------------------------
> END
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Mark Johnson
> Sent: 18 June 2004 04:14
> To: [EMAIL PROTECTED]
> Subject: Re: [U2] [UV] WHILE READNEXT id DO
>
>
> I respond with the GOTO perspective
> -------
> u2-users mailing list
> [EMAIL PROTECTED]
> To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[EMAIL PROTECTED]
To unsubscribe please visit http://listserver.u2ug.org/