The Report Definition
The Report Definition uses the REPORT
program block to format the
input records from the Report Driver.
Report definition
custreport.4gl:
01
REPORT
cust_list(r_custrec)
02
DEFINE
r_custrec RECORD
03
store_num LIKE
customer.store_num,
04
store_name LIKE
customer.store_name,
05
addr LIKE
customer.addr,
06
addr2 LIKE
customer.addr2,
07
city LIKE
customer.city,
08
state LIKE
customer.state,
09
zip_code LIKE
customer.zip_code
10
END RECORD
11
12
ORDER EXTERNAL BY
r_custrec.state, r_custrec.city
13
14
FORMAT
15
16
PAGE HEADER
17
SKIP
2 LINES
18
PRINT COLUMN
30, "Customer Listing"
19
PRINT COLUMN
30, "As of ", TODAY USING
"mm/dd/yy"
20
SKIP
2 LINES
21
22
PRINT COLUMN
2, "Store #",
23
COLUMN
12, "Store Name",
24
COLUMN
40, "Address"
25
26
SKIP
2 LINES
27
28
ON EVERY ROW
29
PRINT COLUMN
5, r_custrec.store_num USING
"####",
30
COLUMN
12, r_custrec.store_name CLIPPED
,
31
COLUMN
40, r_custrec.addr CLIPPED
;
32
33
IF
r_custrec.addr2 IS NOT NULL THEN
34
PRINT
1SPACE
, r_custrec.addr2 CLIPPED
, 1 space;
35
ELSE
36
PRINT
1 SPACE
;
37
END IF
38
39
PRINT
r_custrec.city CLIPPED
, 1 SPACE
,
40
r_custrec.state, 1 SPACE
,
41
r_custrec.zip_code CLIPPED
42
43
BEFORE GROUP OF
r_custrec.city
44
SKIP TO TOP OF PAGE
45
46
ON LAST ROW
47
SKIP
1 LINE
48
PRINT
"TOTAL number of customers: ",
49
COUNT(*) USING
"#,###"
50
51
PAGE TRAILER
52
SKIP
2 LINES
53
PRINT COLUMN
30, "-", PAGENO USING
"<<", " -"
54
55
END REPORT
Note:
- Line
01
TheREPORT
control block has thepr_custrec
record passed as an argument. - Lines
02
thru10
define a local program recordr_custrec
to store the values that the calling routine passes to the report. - Line
12
tells theREPORT
control block that the records will be passed sorted in order bystate
, thencity
. TheORDER EXTERNAL
syntax is used to prevent a second sorting of the program records, since they have already been sorted by the SQL statement in the report driver. - Line
14
is the beginning of theFORMAT
section. - Lines
16
thru20
ThePAGE HEADER
block specifies the layout generated at the top of each page. EachPRINT
statement starts a new line containing text or a value. ThePRINT
statement can have multipleCOLUMN
clauses, which all print on the same line. TheCOLUMN
clause specifies the offset of the first character from the first position after the left margin. The values to be printed can be program variables, static text, or built-in functions. The built-inTODAY
operator generates the current date; theUSING
clauses formats this. TheSKIP
statement inserts empty lines. ThePAGE HEADER
for this report will appear as follows:<skipped line> <skipped line> Customer Listing As of <date> <skipped line> <skipped line> Store # Store Name Address <skipped line> <skipped line>
- Lines
28
thru41
specifies the layout generated for each row. The data can be read more easily if each program record passed to the report is printed on a single row. Although there are fourPRINT
statements in this control block, the first threePRINT
statements are terminated by semicolons. This suppresses the new line signal, resulting in just a single row of printing. TheCLIPPED
keyword eliminates any trailing blanks after the name, addresses, and city values. AnyIF
statement that is included in theFORMAT
section must contain the same number ofPRINT
/SKIP
statements regardless of which condition is met. Therefore, ifr_custrec.addr2
is notNULL
, aPRINT
statement prints the value followed by a single space; if it isNULL
, aPRINT
statement prints a single space. As mentioned earlier, eachPRINT
statement is followed by a semicolon to suppress the newline. The output for each row will be as follows:106 TrueTest Hardware 6123 N. Michigan Ave Chicago IL 60104 101 Bandy's Hardware 110 Main Chicago IL 60068
- Lines
43
and44
start a new page for each group containing the same value forr_custrec.city
. - Lines
46
thru49
specify a control block to be executed after the statements inON EVERY ROW
andAFTER GROUP OF
control block. This prints at the end of the report. The aggregate functionCOUNT(*)
is used to print the total number of records passed to the report. TheUSING
keyword formats the number. This appears as follows:<skipped line> Total number of customers: <count>
- Lines
51
thru53
specifies the layout generated at the bottom of each page. The built-in functionPAGENO
is used to print the page number. TheUSING
keyword formats the number, left-justified. This appears as follows:<skipped line> <skipped line> - <pageno> -