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 The REPORT control block has the pr_custrec record passed as an argument.
  • Lines 02 thru 10 define a local program record r_custrec to store the values that the calling routine passes to the report.
  • Line 12 tells the REPORT control block that the records will be passed sorted in order by state, then city. The ORDER 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 the FORMAT section.
  • Lines16 thru 20 The PAGE HEADER block specifies the layout generated at the top of each page. Each PRINT statement starts a new line containing text or a value. The PRINT statement can have multiple COLUMN clauses, which all print on the same line. The COLUMN 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-in TODAY operator generates the current date; the USING clauses formats this. The SKIP statement inserts empty lines. The PAGE 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 thru 41 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 four PRINT statements in this control block, the first three PRINT statements are terminated by semicolons. This suppresses the new line signal, resulting in just a single row of printing. The CLIPPED keyword eliminates any trailing blanks after the name, addresses, and city values. Any IF statement that is included in the FORMAT section must contain the same number of PRINT / SKIP statements regardless of which condition is met. Therefore, if r_custrec.addr2 is not NULL, a PRINT statement prints the value followed by a single space; if it is NULL, a PRINT statement prints a single space. As mentioned earlier, each PRINT 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 and 44 start a new page for each group containing the same value for r_custrec.city.
  • Lines 46 thru 49 specify a control block to be executed after the statements in ON EVERY ROW and AFTER GROUP OF control block. This prints at the end of the report. The aggregate function COUNT(*) is used to print the total number of records passed to the report. The USING keyword formats the number. This appears as follows:
        <skipped line>
        Total number of customers:   <count>
  • Lines 51 thru 53 specifies the layout generated at the bottom of each page. The built-in function PAGENO is used to print the page number. The USING keyword formats the number, left-justified. This appears as follows:
        <skipped line>
        <skipped line>
                      - <pageno> -