6 Example Report Programs

Example 3

This example is a subprogram which uses data from an Eloquence database. The statements which access the database are described in the Eloquence DBMS Manual. However, the Eloquence Report Writer portions of the program can be understood without knowledge of the Eloquence database management system.

The breaks are set on product and region. Products must have a lower break level than region since product has less frequent breaks. These breaks are shown in lines 1430 and 1440. The file which has the data must be sorted first by product then by region. This is done in line 1240.

The report description section sets up the headers, trailers, and totals. The header (B in the listing and report) for the product looks up the product description and prints the product number and description every time the product changes. The trailer (C) is the total number of orders, the total amount and the average price.

The header for the region (D) lists the region every time the product or region changes. The trailer (E) is the total number of orders (the number of detail lines printed) and the total dollar amount sold.

The report header (F) is the name of the report which is printed on top of the first page. The report trailer (G) lists the grand totals: the number of orders (the number of detail lines), the amount and the average price printed on the last report page.

To have a total printed in the trailer, the TOTALS ON (or GRAND TOTALS ON) statement must be used in the header. Line 1710, the report trailer, is directly connected to line 1350, the report header.

The detail line, line 1900, prints the order number, customer, city, date, and price.

The page header (H) gives the date and report name then the column headings on every page. The page trailer gives the page.

The page length, margin, level and page suppression is set up in I of the listing. These values are passed to the subprogram through the COM statements.


    1010   !      RP301 - Report Writer demo - produces bicycle
    by region rpt
    1030    COM Base$[8],Pselect,Pass$[8],Buff$[200],Lst$[2],
    Clr$[41],Dat$[8]
    1040    COM INTEGER Cur_seg,Menu_no,Curovly$[16]
    1050   !
    1060   COM I$[160],INTEGER S(0:9),Restart,Spool,Code,Msg$[80],
    K$(1:8)
    1070   !
    1080   COM #1,Sort(1:4),Options,Level,Left,Value
    1090   !
    1100   DIM Name$[30]
    1110   INTEGER Order_date,Product
    1120   !
    1130   !
    1140          ON ERROR GOTO R98_error
    1150          LOAD SUB "RWUTIL";7,9        ! Rwhalt,Error,FNCrt
    1160          ON HALT CALL Rwhalt
    1170   !
    1180          CURSOR (1,19)
    1190          LDISP "One moment while data is being sorted."
    1200          IN DATA SET "CUSTOMER" USE SKP 1,Name$,SKP 1,City$,
    SKP 3,Order_date,SKP 1,Region$,Product
    1210          IN DATA SET "OPTION" USE Order$,Option$,Option_price
    1220          ASSIGN "WORKF" TO #1
    1230          WORKFILE IS #1;THREAD IS "CUSTOMER","ORDER","OPTION"
    1240          SORT BY Product,Region$,Order$,Option$
    1250   !
    1260          PRINTER IS Pselect
    1270          IF NOT Spool THEN R05
    1280             PRINTER IS "SPOOL"
    1290             CURSOR (1,15)
    1300             LDISP " ";
    1310             CURSOR (25,10)
    1320             LDISP "*** REPORT IS BEING SPOOLED ***"
    1330   !
    1340   R05:   REPORT HEADER
    1350             GRAND TOTALS ON Option_price
    1360             PRINT SPA(27),"Eloquence REPORT WRITER DEMO"
    1370   !
    1380             PAGE LENGTH 66-45*(Pselect=8),2*(Pselect%<>8),
    1+3*(Pselect%<>8)
    1390             LEFT MARGIN Left
    1400             SUPPRESS PRINT AT Level
    1410             SUPPRESS PRINT FOR Restart PAGES
    1420   !
    1430             BREAK 3 WHEN Product CHANGES
    1440             BREAK 6 WHEN Region$ CHANGES
    1450   !
    1460          PAGE HEADER WITH 5 LINES USING Ph1;Dat$
    1470             PRINT USING Ph2
    1480             PRINT USING Ph3
    1490             PRINT USING Ph4
    1500   !
    1510          PAGE TRAILER WITH 2 LINES USING Pt1;Last$,VAL$
    (NUMPAGE)
    1520             IF (Pselect=8) AND NOT Spool THEN ON FNCrt(Last_
    flag,NUMPAGE,Restart,5) GOTO R20,R90_exit
    1530             IF NOT Spool THEN R20
    1540                CURSOR (34,11)
    1550                DISP "CURRENT PAGE ";VAL$(NUMPAGE)
    1560   !
    1570   !
    1580          HEADER 3 WITH 7 LINES
    1590             TOTALS ON Option_price
    1600             DBGET (Base$,"PRODUCT",7,S(*),Lst$,Buff*,Product)
    1610             IF S(0) THEN R95_dberror
    1620             PRINT USING Hd3;Product,Buff$[3;30]
    1630   !
    1640          HEADER 6 WITH 4 LINES USING Hd6;Region$
    1650             TOTALS ON Option_price
    1660   !
    1670          TRAILER 3 WITH 5 LINES USING Tr3;OLDCV(3),NUMDETAIL
    (3),TOTAL(3,1),AVG(3,1)
    1680   !
    1690          TRAILER 6 WITH 4 LINES USING Tr6;OLDCV$(6),NUMDETAIL
    (6),TOTAL(6,1)
    1700   !
    1710          REPORT TRAILER WITH 5 LINES USING Rt1;NUMDETAIL(0).
    TOTAL(0,1),AVG(0,1)
    1720             Last$="LAST"
    1730             Last_flag=1
    1740   !
    1750   R20:   END REPORT DESCRIPTION
    1760   !
    1770          ON KEY #8:"EXIT" GOTO R90_exit
    1780          ON KEY #16 GOTO R90_exit
    1790          IF NOT Spool AND (Pselect=8) THEN DISP "   ";
    1800   !
    1810          BEGIN REPORT R05
    1820          FOR I=1 TO WFLEN(1)
    1830             READ #1,I;Cnptr,Orptr,Opptr
    1840             IF Cnptr=Lcnptr THEN R40
    1850             Lcnptr=Cnptr
    1860             DBGET (Base$,"CUSTOMER",4,S(*),Lst$,Buff$,Cnptr)
    1870             IF S(0) THEN R95_dberror
    1880             DBGET (Base$,"OPTION",4,S(*),Lst$,Buff$,Opptr)
    1890             IF S(0) THEN R95_dberror
    1900             DETAIL LINE 1 USING Dl1;Order$,Name$,City$,Val$
    (Order_date MOD 100)&"/"&VAL$(INT(Order_date/100)),Option_price
    1910   R40:      NEXT I
    1920          IF NUMDETAIL (0) THEN END REPORT
    1930   !
    1940   R90_exit:!
    1950          ASSIGN * TO #1
    1960          STOP REPORT
    1970          LOAD "RM00"
    1980   !
    1990   R95_dberror:!
    2000          LOAD "SALES",Dberror
    2010   !
    2020   R98_error:!
    2030          OFF ERROR
    2040          OFF KEY #
    2050          CALLRwerror (ERRM$,Base$,S(*))
    2060          PAUSE
    2070          STOP
    2080   !

    2090   !      ***** PRINT USING IMAGE STATEMENTS *****
    2100   !
    2110   Ph1:   IMAGE "DATE:  ",21A,"BICYCLES BY REGION REPORT",/
    2120   !
    2130   Ph2:   IMAGE 6X,"ORDER",51X,"ORDER"
    2140   !
    2150   Ph3:   IMAGE 6X,"NUMBER",11X,"CUSTOMER",19X,"CITY",8X,
    "DATE",7X,"PRICE"
    2160   !
    2170   Ph4:   IMAGE 4X,"=========",X,"==========================
    ===",2X,"================",X,"=====",2X,"==========",/
    2180   !
    2190   Pt1:   IMAGE /,65X,5A,"PAGE ",3A
    2200   !
    2210   Hd3:   IMAGE /,"FOR PRODUCT: ",K," - ",K,/
    2220   !
    2230   Hd6:   IMAGE "  FOR REGION: ",K,/
    2240   !
    2250   Tr3:   IMAGE /,19X,"**** TOTAL ORDERS FOR ",4D,28X,DDDDD,/,
    19X,"**** TOTAL AMOUNT",31X,DDDDCDDD.DD,/,19X,"**** AVERAG 
    PRICE",30X,DDDDCDDD.DD,/
    2260   !
    2270   Tr6:   IMAGE /,19X,"*** TOTAL ORDERS FOR REGION: ",25A,
    DDDDD,/,19X,"*** TOTAL REGION AMOUNT",25X,DDDDCDDD.DD,/
    2280   !
    2290   Rt1:   IMAGE 2/,19X,"***** GRAND TOTALS OF ORDERS",25X,
    7D,/,19X,"***** GRAND AMOUNT",30X,DDDDCDDD.DD,/,19X,"***** GRAND
    AVERAGE PRICE",23X,DDDDCDDD.DD
    2300   !
    2310   D11:   IMAGE 4X,11A,31A,17A,6A,DDCDDD.DD

DATE: 07/10/91                    DEMONSTRATION BICYCLE COMPANY
                                  BICYCLES BY REGION REPORT

    ORDER                                                   ORDER  NUMBER             CUSTOMER                 CITY        DATE     PRICE
    =======   =====================     ==============   =====   ======


FOR PRODUCT: 100 - Standard Bicycle

  FOR REGION:  MSR

        101       Noname, Joseph           Loveland            5/91     75.00

                      *** TOTAL ORDERS FOR REGION:  MSR                     1
                      *** TOTAL REGION AMOUNT                           75.00

  FOR REGION:  SA

        103       Hernandes, Jose          Mexico City         6/91     75.00
        108       Arauja, Luciano A.       Rio de Janeiro      8/91     75.00

                      *** TOTAL ORDERS FOR REGION:  SA                      2
                      *** TOTAL REGION AMOUNT                          150.00


                      **** TOTAL ORDERS FOR 100                             3
                      **** TOTAL AMOUNT                                225.00
                      **** AVERAGE PRICE                                75.00


FOR PRODUCT: 300 - 3-Speed Bicycle

  FOR REGION:  FE

        104       Houseman, Sean           Sidney              6/91    110.00

                      *** TOTAL ORDERS FOR REGION:  FE                      1
                      *** TOTAL REGION AMOUNT                          110.00


                      **** TOTAL ORDERS FOR 300                             1
                      **** TOTAL AMOUNT                                110.00
                      **** AVERAGE PRICE                               110.00


FOR PRODUCT: 500 - 5-Speed Bicycle

  FOR REGION:  AFR

        105       Sono, Jomo A.            Addis Ababa         5/91    125.00

                      *** TOTAL ORDERS FOR REGION:  AFR                     1
                      *** TOTAL REGION AMOUNT                          125.00


                                                                       PAGE 1





DATE: 07/10/91                    BICYCLES BY REGION REPORT

       ORDER                                                    ORDER
       NUMBER             CUSTOMER                 CITY        DATE     PRICE
       =======     =====================     =============   =====   ========

FOR REGION:  ESR

        100       Smith, Thomas A.         Ft. Collins         6/91    125.00

                      *** TOTAL ORDERS FOR REGION:  ESR                     1
                      *** TOTAL REGION AMOUNT                          125.00


FOR REGION:  FE

        109       Bekker, Bart             Kilbirnie           6/91    125.00

                      *** TOTAL ORDERS FOR REGION:  FE                      1
                      *** TOTAL REGION AMOUNT                          125.00


                      **** TOTAL ORDERS FOR 500                             3
                      **** TOTAL AMOUNT                                375.00
                      **** AVERAGE PRICE                               125.00


FOR PRODUCT: 1000 - 10-Speed Bicycle

FOR REGION:  EUR

        106       Heining, Heinz           Boeblingen          7/91    150.00

                      *** TOTAL ORDERS FOR REGION:  EUR                     1
                      *** TOTAL REGION AMOUNT                          150.00


FOR REGION:  MSR

        107       Dalling, Jimmy           Ft. Collins         8/91    150.00

                      *** TOTAL ORDERS FOR REGION:  MSR                     1
                      *** TOTAL REGION AMOUNT                          150.00


FOR REGION: WSR

        102       Johnson, Sam             San Francisco       7/91    150.00

                      *** TOTAL ORDERS FOR REGION:  WSR                     1
                      *** TOTAL REGION AMOUNT                          150.00


                      **** TOTAL ORDERS FOR 1000                            3
                      **** TOTAL AMOUNT                                450.00
                      **** AVERAGE PRICE                               150.00


                                                                       PAGE 2




DATE: 07/10/91                    BICYCLES BY REGION REPORT

       ORDER                                                   ORDER
       NUMBER             CUSTOMER                 CITY        DATE     PRICE
       =======   =====================     =================   =====  ========

                       ***** GRAND TOTALS OF ORDERS                         10
                       ***** GRAND AMOUNT                             1,160.00
                       ***** GRAND TOTALS OF ORDERS                     116.00


                                                                   LAST PAGE 3


Eloquence Report Manual - 19 DEC 2002