Use the REPORT block language construct to format and display data output from a FUNCTION block. This output is typically table data, although any valid combination of text, macro variable references, and function calls can be specified. A table name can optionally be specified on the REPORT block. If you do not specify a table name, Net.Data uses the table data from the first output table in the FUNCTION parameter list.
The REPORT block has three parts, each of which is optional:
Example:
%REPORT{ <H2>Query Results</H2> <P>Select a name for details. <TABLE BORDER=1> <TR> <TD>Name</TD> <TD>Location</TD></TR> %ROW{ <TR> <TD> <a href="/cgi-bin/db2www/name.d2w/details?name=$(V1)&location;=$(V2)">$(V1)</a> </TD> <TD>$(V2)</TD> </TR> %} </TABLE> %}
Use the following guidelines when creating REPORT blocks:
SHIPDATE | RECDATE | SHIPNO | ------------------------------------- 25/05/1997 | 30/05/1997 | 1495194B | ------------------------------------- 25/05/1997 | 28/05/1997 | 2942821G | -------------------------------------
%REPORT{%}
The following example shows how you can customize report formats using special variables and HTML tags. It displays the names, phone numbers, and FAX numbers from the table CustomerTbl:
%DEFINE SET_TOTAL_ROWS="YES" ... %FUNCTION(DTW_SQL) custlist() { SELECT Name, Phone, Fax FROM CustomerTbl %REPORT{ <I>Phone Query Results:</I> <BR> ===================== <BR> %ROW{ Name: <B>$(V1)</B> <BR> Phone: $(V2) <BR> Fax: $(V3) <BR> ------------------------------ <BR> %} Total records retrieved: $(TOTAL_ROWS) %} %}
The resulting report looks like this in the Web browser:
Phone Query Results: ==================== Name: Doen, David Phone: 422-245-1293 Fax: 422-245-7383 ------------------------------ Name: Ramirez, Paolo Phone: 955-768-3489 Fax: 955-768-3974 ------------------------------ Name: Wu, Jianli Phone: 525-472-1234 Fax: 525-472-1234 ------------------------------ Total records retrieved: 3
Net.Data generated the report by:
You can specify multiple REPORT blocks within a single FUNCTION or MACRO FUNCTION block to generate multiple reports with one function call.
Typically, you would use multiple REPORT blocks with the DTW_SQL language environment with a function that calls a stored procedure, which returns multiple result sets (see Stored Procedures). However, multiple REPORT blocks can be used with any language environment to generate multiple reports.
To use multiple REPORT blocks, place a Net.Data table variable in the function parameter list. If more result sets are returned from the stored procedure than the number of REPORT blocks you have specified, and if the Net.Data built-in function DTW_DEFAULT_REPORT = "MULTIPLE", then default reports are generated for each table that is not associated with a report block. If no report blocks are specified, and if DTW_DEFAULT_REPORT = "YES", then only one default report will be generated. Note that for the SQL language environment only, a DTW_DEFAULT_REPORT value of "YES" is equivalent to a value of "MULTIPLE".
The following examples demonstrate ways in which you can use multiple report blocks.
To display multiple reports using default report formatting:
Example 1: DTW_SQL language environment
%DEFINE DTW_DEFAULT_REPORT = "MULTIPLE" %FUNCTION (dtw_sql) myStoredProc (OUT table1, table2) { CALL myproc %}
In this example, the stored procedure myproc returns two result sets, which are placed in table1 and table2. Because no REPORT blocks are specified, default reports are displayed for both tables, table1 first, then table2.
Example 2: MACRO_FUNCTION block. In this example, two tables are passed into the MACRO_FUNCTION block. When DTW_DEFAULT_REPORT="MULTIPLE" is specified, Net.Data generates reports for both tables.
%DEFINE DTW_DEFAULT_REPORT = "MULTIPLE" %MACRO_FUNCTION multReport (INOUT tablename1, tablename2) { %}
In this example, two tables are passed into the MACRO_FUNCTION multReport. Again, Net.Data displays default reports for the two tables in the order in which they appear in the MACRO FUNCTION block parameter list, table1 first, then table2.
Example 3: DTW_REXX language environment
%DEFINE DTW_DEFAULT_REPORT = "YES" %FUNCTION (dtw_rexx) multReport (INOUT table1, table2) { SAY 'Generating multiple default reports...<BR>' %}
In this example, two tables are passed into the REXX function multReport. Because DTW_DEFAULT_REPORT="YES" is specified, Net.Data displays a default report for the first table only.
To display multiple reports by specifying REPORT blocks for display processing:
Example 1: Named REPORT blocks
%FUNCTION(dtw_sql) myStoredProc (OUT table1, table2) { CALL myproc (table1, table2) %REPORT(table2) { ... %ROW { .... %} ... %} %REPORT(table1) { ... %row { .... %} ... %} %}
In this example, REPORT blocks have been specified for both of the tables passed in the FUNCTION block parameter list. The tables are displayed in the order they are specified on the REPORT blocks, table2 first, then table1. By specifying a table name on the REPORT block, you can control the order in which the reports are displayed.
Example 2: Unnamed REPORT blocks
%FUNCTION(dtw_sql) myStoredProc (OUT table1, table2) { CALL myproc %REPORT { ... %ROW { .... %} ... %} %REPORT { ... %ROW { .... %} ... %} %}
In this example, REPORT blocks have been specified for both of the tables passed in the FUNCTION block parameter list. Because there are no table names specified on the REPORT blocks, reports are displayed for the two tables in the order in which they are returned from the stored procedure.
To display multiple reports using a combination of default reports and REPORT blocks:
Example: A combination of default reports and REPORT blocks
%DEFINE DTW_DEFAULT_REPORT = "MULTIPLE" %FUNCTION(dtw_system) editTables (INOUT table1, table2, table3) { %EXEC{ /qsys.lib/mylib.lib/mypgm.pgm %} %REPORT(table2) { ... %ROW { .... %} ... %} %}
In this example, only one REPORT block is specified, and because it specifies a table name of table2, it uses this table to display its report. Because there are fewer REPORT blocks specified the number of result sets returned from the stored procedure, default reports are displayed for the remaining for the remaining result sets: first, a default report for table1; then a default report for table3.
Use the following guidelines and restrictions when specifying multiple REPORT blocks in a FUNCTION or MACRO_FUNCTION block.
Guidelines:
Restrictions: