Print totals at the beginning of a report
Review these instructions if you wish to print aggregate values prior to printing the first detail row. For example, you may need to print totals at the start of the report and then provide the detail rows.
To print aggregate values prior to the detail rows, the aggregate values must be part of the data schema, separate from the variables shipped with every row.
Modify your Genero BDL application to send the aggregate value
In a Genero BDL reporting application, you can send the aggregate values separate from the detail
rows by using
AFTER GROUP OF
or ON LAST ROW
clauses. For example,
to send the report total separate from the report total included with ON EVERY ROW
,
add the ON LAST ROW
clause to the REPORT
block, as demonstrated in
this modification to the OrderReport.4gl sample report
program:REPORT report_all_orders( orderline )
DEFINE
orderline OrderType,
lineitemprice LIKE lineitem.unitprice,
overalltotal LIKE orders.totalprice,
usertotal LIKE orders.totalprice,
ordertotal LIKE orders.totalprice,
lastRowValue DECIMAL(9,2)
ORDER EXTERNAL BY orderline.orders.userid, orderline.orders.orderid, orderline.lineitem.linenum
FORMAT
FIRST PAGE HEADER
LET overalltotal = 0
PRINT controlBlock.*
BEFORE GROUP OF orderline.orders.userid
DISPLAY "USER " || orderline.orders.userid
LET usertotal = 0
BEFORE GROUP OF orderline.orders.orderid
DISPLAY " ORDER " || orderline.orders.orderid
LET ordertotal = 0
ON EVERY ROW
DISPLAY " EVERY ROW " || orderline.lineitem.linenum
LET lineitemprice = orderline.lineitem.unitprice * orderline.lineitem.quantity
LET overalltotal = overalltotal + lineitemprice
LET usertotal = usertotal + lineitemprice
LET ordertotal = ordertotal + lineitemprice
PRINT orderline.*, lineitemprice, overalltotal, usertotal, ordertotal
ON LAST ROW
LET lastRowValue = overalltotal
PRINT lastRowValue
END REPORT
The data schema now includes a variable that you can place in the report header.
Add aggregates using a Report Schema Transformation
Rather than modify the report application, you can use a report schema transformation to add the required aggregates to the data schema.
In this example, a report schema transformation was added to aggregate the lineitemprice for all groups and for the report total.