78 DB2 for OS/390 and z/OS Powering the Worlds e-business
4. Net.Data receives the input form data and makes the data available in macro
variables.
5. Net.Data processes the user macro, referencing variables, calling functions
and language environments, and formatting the results as requested.
6. Net.Data sends the resulting Web page to the client browser for formatting.
Figure 5-4 Net.Data runtime flow control
Anatomy of a Net.Data macro
Macros form the basis of Net.Data programming. They are executed on the Web
server and are responsible for access to the data sources. Macros are comprised
of listed sections, also called building blocks (Figure 5-5). A macro can include all
of the sections; the smallest macro can include just an HTML and a function
definition section.
HTML
Input
Form
Input
Form
Request
HTML
report
Form
Report
Form
Request
Web
Browser
HTML
Input
Form
Input
Form
Request
HTML
report
Form
Report
Form
Request
Web
Server
Results
Read/Write
SQL
Query
Results
SQL
Query
Net.
Data
Flat
File
Relational
Database
Web Server Machine
Common Gateway
Interface or API
Dynamic SQLHTTP/HTML
Chapter 5. Net.Data 79
Figure 5-5 Macro building blocks
The macro sections are:
Define section: Contains definitions of variables.
Function definition section: Contains language-dependent calls for
performing operations or actions on data sources.
Report section: Nested within the function definition section, contains format
data or the answer set for display on the browser.
HTML or XML blocks: Contains the main procedure of the program or
externally callable object. One or more HTML or XML blocks can be included
in a macro.
Include section: Like C include statements, includes flat files of code into the
macro.
Message section: Typically nested within the function definition section,
contains error handling or other special situation messages.
Comment Section (anywhere)
Define Section
Function Definition Section
Exec Section
Report Section
Row Section
Message Section
Variable References
HTML Section
Any HTML tags
Function call
Conditional Section
Include Section
Variable References
Message Section
80 DB2 for OS/390 and z/OS Powering the Worlds e-business
Figure 5-6 shows a sample Net.Data macro and the input and output windows it
generates at the browser.
Figure 5-6 Sample Net.Data macro
The example in Figure 5-6 prompts for a last name to be found in an Employee
Directory and returns a list of matches. Note the sections of the macro:
The define section identifies parameterized standard information, such as the
Web page header.
The HTML section, named getlast, defines the format of the first Web page,
the variable to store the users entry, and the result page where the result will
be returned. The implicit variable, MATCH, will be used in the SQL statement.
The function section defines the query to be performed. Note that the implicit
variable, MATCH, is used in the SQL predicate. The function section in this
example also has a report section, which specifies how the answer set is to
be formatted.
The HTML section, named Report, shows the invocation of the SQL
statement.
%DEFINE(
STDHDR="Employee Directory"
DTATBASE="SAMPLE"
%)
%HTML(getlast)
<HTML>
<FORM METHOD="POST"
ACTION="/CGI-BIND/DB2WWW/CGDEMO8.DBW/REPORT">
$(STDHDR)<p>
Enter Last Name: <b>
<INPUT SIZE=20 NAME="MATCH"><INPUT TYPE=SUBMIT
TYPE="SEARCH">
</FORM>
</HTML>
%)
%FUNCTION(DTW_SQL) getname() (
Select * from EMPLOYEE WHERE
LASTNAME='$(MATCH)'
%REPORT(
Employee Name:<br>
%ROW (
<BR>
$(V1) $(V2)
%)
%)
%)
%HTML (REPORT) (
@getname()
%)
Define section
HTML input page
and implicit variable
definition
Function block and
Implicit variable
definition
HTML output page
Employee Directory
Enter Last name:
Winston Submit
Browser Screens
Employee Names:
Harry
Winston
James
Winston
Julia
Winston
Xavier
Winston

Get DB2 for OS/390 and z/OS Powering the World's e-business Solutions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.