All the following examples of report production use a file called ACCOUNTS that contains the following records. It is assumed that the file is ordered (i.e.: keyed) by company, division and department.
Company (#COMP) | Division (#DIV) | Department (#DEPT) | Expenditure (#EXPEND) | Revenue (#REVNU) |
|---|---|---|---|---|
01 | 1 | ADM | 400 | 576 |
" | " | MKT | 678 | 56 |
" | " | SAL | 123 | 6784 |
" | 2 | ADM | 46 | 52 |
" | " | SAL | 978 | 456 |
" | 3 | ACC | 456 | 678 |
" | " | SAL | 123 | 679 |
02 | 1 | ACC | 843 | 400 |
" | " | MKT | 23 | 0 |
" | " | SAL | 876 | 10 |
" | 2 | ACC | 0 | 43 |
The simplest type of report that can be produced is a straight listing from all or part of a file.
To list all of the ACCOUNTS file, all that is required is:
DEF_LINE NAME(#ACCOUNT) FIELDS(#COMP #DIV #DEPT
#EXPEND #REVNU)
SELECT FIELDS(#ACCOUNT) FROM_FILE(ACCOUNTS)
PRINT LINE(#ACCOUNT)
ENDSELECT
ENDPRINT
This would produce a report that looked something like this:
Company Division Department Expenditure Revenue
01 1 ADM 400 576
01 1 MKT 678 56
01 1 SAL 123 6784
01 2 ADM 46 52
01 2 SAL 978 456
01 3 ACC 456 678
01 3 SAL 123 679
02 1 ACC 843 400
02 1 MKT 23 0
02 1 SAL 876 10
02 2 ACC 0 43
Of course, this example can be changed in various ways to only print part of the file - such as only the records for a selected company:
DEF_LINE NAME(#ACCOUNT) FIELDS(#COMP #DIV #DEPT
#EXPEND #REVNU)
REQUEST FIELDS(#COMP)
SELECT FIELDS(#ACCOUNT) FROM_FILE(ACCOUNTS)
WITH_KEY(#COMP)
PRINT LINE(#ACCOUNT)
ENDSELECT
ENDPRINT
Or, only records where the difference between expenditure and revenue is less than a specified amount:
DEF_LINE NAME(#ACCOUNT) FIELDS(#COMP #DIV
#DEPT #EXPEND #REVNU)
DEFINE FIELD(#MAXLOSS) REFFLD(#REVNU)
LABEL('Allowable loss')
REQUEST FIELDS(#MAXLOSS)
SELECT FIELDS(#ACCOUNT) FROM_FILE(ACCOUNTS)
WHERE('(#REVNU - #EXPEND) *LT #MAXLOSS')
PRINT LINE(#ACCOUNT)
ENDSELECT
ENDPRINT
This final example uses the *ONCHANGE field attribute to only print the company number when it changes, rather than on every line:
DEF_LINE NAME(#ACCOUNT) FIELDS((#COMP *ONCHANGE)
#DIV #DEPT #EXPEND #REVNU)
SELECT FIELDS(#ACCOUNT) FROM_FILE(ACCOUNTS)
PRINT LINE(#ACCOUNT)
ENDSELECT
ENDPRINT
This would produce a report that looks something like this:
Company Division Department Expenditure Revenue
01 1 ADM 400 576
1 MKT 678 56
1 SAL 123 6784
2 ADM 46 52
2 SAL 978 456
3 ACC 456 678
3 SAL 123 679
02 1 ACC 843 400
1 MKT 23 0
1 SAL 876 10
2 ACC 0 43