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 REPORTNote:
- Line
01TheREPORTcontrol block has thepr_custrecrecord passed as an argument. - Lines
02thru10define a local program recordr_custrecto store the values that the calling routine passes to the report. - Line
12tells theREPORTcontrol block that the records will be passed sorted in order bystate, thencity. TheORDER EXTERNALsyntax 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
14is the beginning of theFORMATsection. - Lines
16thru20ThePAGE HEADERblock specifies the layout generated at the top of each page. EachPRINTstatement starts a new line containing text or a value. ThePRINTstatement can have multipleCOLUMNclauses, which all print on the same line. TheCOLUMNclause 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-inTODAYoperator generates the current date; theUSINGclauses formats this. TheSKIPstatement inserts empty lines. ThePAGE HEADERfor 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
28thru41specifies 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 fourPRINTstatements in this control block, the first threePRINTstatements are terminated by semicolons. This suppresses the new line signal, resulting in just a single row of printing. TheCLIPPEDkeyword eliminates any trailing blanks after the name, addresses, and city values. AnyIFstatement that is included in theFORMATsection must contain the same number ofPRINT/SKIPstatements regardless of which condition is met. Therefore, ifr_custrec.addr2is notNULL, aPRINTstatement prints the value followed by a single space; if it isNULL, aPRINTstatement prints a single space. As mentioned earlier, eachPRINTstatement 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
43and44start a new page for each group containing the same value forr_custrec.city. - Lines
46thru49specify a control block to be executed after the statements inON EVERY ROWandAFTER GROUP OFcontrol 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. TheUSINGkeyword formats the number. This appears as follows:<skipped line> Total number of customers: <count> - Lines
51thru53specifies the layout generated at the bottom of each page. The built-in functionPAGENOis used to print the page number. TheUSINGkeyword formats the number, left-justified. This appears as follows:<skipped line> <skipped line> - <pageno> -