Was this helpful?
Sample Report
The following example demonstrates a simple report using Report-Writer. This report specification was created with a text editor, stored within the database with the sreport command, and run with the report command.
The report shows a titled listing of data from an existing table, edat in a database. The jobcat column is displayed only once for each job category value.
/* Sample report */
  .NAME        jobcat
  .OUTPUT      jobcat.out
  .DATA        edat
  .SORT        jobcat, name
  .HEADER REPORT
      .NEWLINE 2
      .CENTER
      .PRINT 'Sample Report'
      .NEWLINE 2
  .HEADER jobcat
    .TFORMAT jobcat(' zzzz ')
  .DETAIL
    .PRINT jobcat(b8), name(c15), dept,
      code, age, sales(f12.3)
    .NEWLINE
The report output looks like this:
                Sample Report
10   Adams,Joe     toy    0  22  10500.000
     Green,James   toy    0  34  43645.000
     Smith,Tony    acct   0  48  8690.000
20   Davis,Miles   music  0  56  234987.000
     Tanhous,Karl  music  0  20  18765.000
30   Jones,Mary    acct   1  34  34599.000
     Maney,Sikkim  none   1  51  15333.000
     Mellon,Tim    toy    0  24  45098.000
     Mellon,Tim    any    0  44  67876.000
     Norris,Bill   acct   0  22  23988.000
This list briefly explains each statement's function:
The .name statement gives a name to the report, which is placed in the Reports Catalog by the sreport facility and is used by the report command to locate the report specifications.
The .data statement identifies an existing table or view in the database that contains the data to report.
The .sort statement indicates the order the data is to be displayed on the report.
The .header report statement begins the section of Report-Writer statements to be performed at the start of the report.
The .newline, .center, and .print statements are used in positioning and printing a title.
The .header jobcat statement begins the section of Report-Writer statements to be performed any time the value in the jobcat column changes. The .tformat statement is used to temporarily change the normal print format of the jobcat column on the next printing of jobcat, which occurs in the .detail section.
Normally jobcat is not printed. Its format is (b8), which means "print 8 blank spaces." The .tformat statement makes a change to the format to enable a one‑time printing of this value, so the actual value of the jobcat column is output. The .detail statement begins the specification of Report-Writer statements to be performed on each row in the data table.
The .print statement within the detail section prints out the values of the columns in the formats given after the column names, or the default format for that type of data item, if no format is specified. The chapter “Report-Writer Expressions and Formats” describes the format specifications that appear in the parentheses following the column names in detail.
This table shows the table definition data on which the report was run:
Column Name
Type
Length
Nulls
Defaults
jobcat
integer
4
yes
no
name
char
15
yes
no
dept
char
6
yes
no
code
integer
1
yes
no
age
integer
2
yes
no
sales
money
 
yes
no
This table shows the data for the sample report:
jobcat
name
dept
code
age
sales
10
Adams, Joe
toy
0
22
$10500.00
10
Green, James
toy
0
34
$43645.00
10
Smith, Tony
acct
0
48
$8690.00
20
Davis, Miles
music
0
56
$234987.00
20
Tanhaus, Karl
music
0
20
$18765.00
30
Jones, Mary
acct
1
34
$34599.00
30
Maney, Sikkim
none
1
51
$15333.00
30
Mellon, Tim
toy
0
44
$67876.00
30
Mellon, Tim
any
0
24
$45098.00
30
Norris, Bill
acct
0
26
$23988.00
Last modified date: 04/03/2024