7 66 3 KEEP_TOTAL Examples

LANSA Technical

7.66.3 KEEP_TOTAL Examples

Example 1: A sales history file contains details of a company name (#COMPANY), a division name (#DIVNAM) and a sales value (#SALES). Print all sales details and print total and average sales details by division, company and report (grand total):

DEF_LINE  NAME(#DETAIL) FIELDS(#COMPANY #DIVNAM #SALES)
DEF_BREAK NAME(#SUBDIV) FIELDS(#DIVTOT #DIVAVG) TRIGGER_BY(#COMPANY #DIVNAM)
DEF_BREAK NAME(#SUBCOM) FIELDS(#COMTOT #COMAVG) TRIGGER_BY(#COMPANY)
DEF_BREAK NAME(#GRAND)  FIELDS(#GRDTOT #GRDAVG)
SELECT    FIELDS(#DETAIL)  FROM_FILE(SALEHIST)
KEEP_TOTAL OF_FIELD(#SALES) IN_FIELD(#DIVTOT) BY_FIELD(#COMPANY #DIVNAM)
KEEP_AVG   OF_FIELD(#SALES) IN_FIELD(#DIVAVG) BY_FIELD(#COMPANY #DIVNAM)
KEEP_TOTAL OF_FIELD(#SALES) IN_FIELD(#COMTOT) BY_FIELD(#COMPANY)
KEEP_AVG   OF_FIELD(#SALES) IN_FIELD(#COMAVG) BY_FIELD(#COMPANY)
KEEP_TOTAL OF_FIELD(#SALES) IN_FIELD(#GRDTOT)
KEEP_AVG   OF_FIELD(#SALES) IN_FIELD(#GRDAVG)
PRINT   LINE(#DETAIL)
ENDSELECT
ENDPRINT
 

Example 2: A sales file contains details of a company division (#DIVNAM) and of an entire year's sales in 4 quarters (#QTR01 -> #QTR04). Produce a report that summarizes total and average yearly sales by division.

DEF_BREAK    NAME(#SUMMARY) FIELDS(#TOTAL #AVERAGE) TRIGGER_BY(#DIVNAM)
 
SELECT       FIELDS(#DIVNAM #QTR01 #QTR02 #QTR03 #QTR04) FROM_FILE(DIVSALES)
KEEP_TOTAL OF_FIELD(#QTR01 #QTR02 #QTR03 #QTR04) IN_FIELD(#TOTAL) BY_FIELD(#DIVNAM)
KEEP_AVG   OF_FIELD(#QTR01 #QTR02 #QTR03 #QTR04) IN_FIELD(#AVERAGE) BY_FIELD(#DIVNAM)
PRINT      LINE(*BREAKS)
ENDSELECT
 
ENDPRINT