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/

Reply via email to