The client application invokes Net.Data by specifying both the macro name and the name of one of the macro's entry points. The entry point to the macro can be either an HTML or XML block. These blocks contain most of the document markup and are where the calls to the functions are made. They are the "main" program block of the macro.
Because the entry point block drives the execution of the macro, there must be at least one entry point block in a macro. There can be multiple HTML or XML blocks, but only one is executed per client request. And, with each request a single document is returned to the client. To create an application consisting of many client documents, you can invoke Net.Data multiple times to process various HTML or XML blocks using standard navigation techniques, such as links and forms.
Any text presentation statements can appear in an HTML or XML block, as long as it is valid for the client. For example, HTML blocks can contain HTML or JavaScript. The JavaScript is not executed by Net.Data, but is sent along with the rest of the HTML block output to the client for execution and display. In an HTML or XML block, you can also include function calls, variable references, and INCLUDE statements. The following example shows a common use of an HTML block in a Net.Data macro:
%DEFINE DATABASE="MNS96" %HTML(INPUT){ <h1>Hardware Query Form</h1> <hr> <form method="post" action="/cgi-bin/db2www/equiplst.d2w/report"> <dl> <dt>What hardware do you want to list? <dd><input type="radio" name="hdware" value="MON" checked />Monitors <dd><input type="radio" name="hdware" value="PNT" />Pointing devices <dd><input type="radio" name="hdware" value="PRT" />Printers <dd><input type="radio" name="hdware" value="SCN" />Scanners </dl> <hr /> <input type="submit" value="Submit" /> </form> %} %FUNCTION(DTW_SQL) myQuery() { SELECT MODNO, COST, DESCRIP FROM EQPTABLE WHERE TYPE=$(hdware) %REPORT{ <b>Here is the list you requested:</b><br /> %ROW{ <hr> $(N1): $(V1) $(N2): $(V2) <p> $(V3) %} %} %} %HTML(report){ @myQuery() %}
You can invoke the Net.Data macro from an HTML link.
<a href="http://www.ibm.com/cgi-bin/db2www/equiplst.d2w/input"> List of hardware</a>
When the application user clicks on this link, the Web browser invokes Net.Data, and Net.Data parses the macro. When Net.Data begins processing the HTML block specified on the invocation, in this case HTML(input), it begins to process the text inside the block. Anything that Net.Data does not recognize as a Net.Data macro language construct, it sends to the browser for display.
After the user makes a selection and presses the Submit button, Net.Data runs the ACTION part of the HTML FORM element, which specifies a call to the Net.Data macro's HTML(output) block. Net.Data then processes the HTML(output) block just as it did with the HTML(input) block.
Net.Data then processes the myQuery() function call, which in turn invokes the SQL FUNCTION block. After replacing the $(hdware) variable reference in the SQL statement with the value returned from the input form, Net.Data runs the query. At this point, Net.Data resumes processing the report, displaying the results of the query according to the text presentation statements specified in the REPORT block.
After Net.Data completes the REPORT block processing, it returns to the HTML(OUTPUT) block, and finishes processing.