Step 7 Add a Grand Total Line

Visual LANSA

Step 7. Add a Grand Total Line

FRM115 - Writing Reports

1.  In this step, you will add the grand total of all departments displayed in the report and you will add a blank line between printed lines:

a.  Define a working field for the report called GRANDTOT. The field should be P(17,2) with an edit code of A. Enter a label, column heading and description of Grand Total.

b.  Define another report break which prints the GRANDTOT field at the end of the report.

c.  Add another KEEP_TOTAL command to accumulate SALARY into the GRANDTOT field.

d.  Add a blank line (SPACE) between each printed line.

2.  Try to make the necessary code changes based on the function description above.

     Your code should appear as follows:

FUNCTION OPTIONS(*DIRECT)
DEFINE FIELD(#TOTAL) TYPE(*DEC) LENGTH(11) DECIMALS(2) LABEL('Total Amount')

DESC('Total Amount') COLHDG('Total Amount') EDIT_CODE(A)
DEFINE FIELD(#EMPCOUNT) TYPE(*DEC) LENGTH(3) DECIMALS(0) LABEL('Employee Count')

DESC('Employee Count') COLHDG('Employee Count') EDIT_CODE(A)
DEFINE FIELD(#GRANDTOT) TYPE(*DEC) LENGTH(17) DECIMALS(2) LABEL('Grand Total')

DESC('Grand Total') COLHDG('Grand Total') EDIT_CODE(A)
DEF_REPORT FORMSIZE(66 80)

GROUP_BY NAME(#REPDATA) FIELDS(#DEPTMENT #DEPTDESC #SECTION #EMPNO #SALARY
#STARTDTE)

DEF_HEAD NAME(#HDR01) FIELDS(#REP1PAGE #FUNCTION #STD_TITLE #DEPTMENT #DEPTDESC)
TRIGGER_BY(*OVERFLOW #DEPTMENT) DESIGN(*DOWN)

DEF_FOOT NAME(#FTR01) FIELDS(#DATE #TIME #REP1PAGE)
DEF_LINE NAME(#DET01) FIELDS(#SECTION #EMPNO #SALARY #STARTDTE)

DEF_BREAK NAME(#BRK01) FIELDS(#EMPCOUNT #TOTAL) TRIGGER_BY(#DEPTMENT)
DEF_BREAK NAME(#BRK02) FIELDS(#GRANDTOT)

#STD_TITLE := 'Employee Report'
SELECT FIELDS(#REPDATA) FROM_FILE(PSLMST1) WITH_KEY(#DEPTMENT #SECTION)

NBR_KEYS(*COMPUTE) GENERIC(*YES)
KEEP_TOTAL OF_FIELD(#SALARY) IN_FIELD(#GRANDTOT)

KEEP_TOTAL OF_FIELD(#SALARY) IN_FIELD(#TOTAL) BY_FIELD(#DEPTMENT)
KEEP_COUNT OF_FIELD(#EMPNO) IN_FIELD(#EMPCOUNT) BY_FIELD(#DEPTMENT)

FETCH FIELDS(#DEPTDESC) FROM_FILE(DEPTAB) WITH_KEY(#DEPTMENT) KEEP_LAST(1)
PRINT LINE(#DET01)
SPACE
ENDSELECT
ENDPRINT

 

3.  Save the code and then full function check or build the RDML. Make any corrections as required.

4.  Compile the function.

5.  Submit your new function.

a.  Enter a department of A and leave the section blank.

b.  Check that the report grand total is correct and check that it appears in the proper location.

6.  Your report should look like the following:

7.  OPTIONAL: Paint the Report

     If you wish, you may paint the report using the Report Painter. The Report Painter is very similar to the LANSA Screen Painter and is accessed from the function editor.

     The report painter displays all screen elements, and enables one of these to be edited at one time. For example report header (HDR01) or report detail line (DET01). Changes made in the painter will be reflected in the RDML source.