IBM Books

Net.Data Administration and Programming Guide for OS/400

Calling Net.Data Built-in Functions

Net.Data provides a large set of built-in functions to simplify Web page development. These functions are already defined by Net.Data, so you do not need to define them in a FUNCTION block. You can simply call these functions anywhere in the macro where a user-defined function can be called.

You use the same method to call a built-in function that you use to call a user-defined function, the Net.Data function call. Figure 7 shows how the Net.Data functions and the macro file interact.

Figure 7. Net.Data Built-in Functions


Net.Data Built-in Functions

From within an HTML block, Net.Data processes a function call for the built-in function. Net.Data processes the function and then returns any results within an HTML block in the macro file.

Built-in functions can return their results in three ways. You can tell how each one returns its results by its prefix:

Some built-in functions do not have each type. To determine which type a particular built-in function has, see the Net.Data built-in functions chapter in Net.Data Reference.

The following sections provide a high-level overview of the Net.Data built-in functions. Use these functions to perform general purpose, math, string, word, or table manipulation functions. Additionally, you can use persistent functions for transaction processing. See Net.Data Reference for descriptions of each function with syntax and examples. Some of these functions required variables to be set prior to their use, or must be used in a specific context.

General Purpose Functions

This set of functions help you develop Web pages by altering data or accessing system services. You can use them to query and set environment variables, use HTML escape codes, and get other useful information from the system.

For example, to specify that Net.Data should exit a macro if a specific condition occurs, without processing the rest of the macro file, you use the DTW_EXIT function:

%HTML(cache_example) {
 
<html>
 <head>
 <title>This is the page title</title>
 </head>
 <body>
 <center>
 <h3>This is the Main Heading</h3>
 <!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>
 <! Joe Smith sees a very short page                   !>
 <!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>
 %IF (customer == "Joe Smith")
</body>
</html>
 
@DTW_EXIT()
 
%ENDIF
 
...
 
</body>
 </html>
 %}

The DTW_URLESCSEQ function replaces characters that are not allowed in a URL with their escape values. For example, if the input variable string1 equals "Guys & Dolls", DTW_URLESCSEQ assigns the output variable to the value "Guys%20%26%20Dolls".

Math Functions

These functions perform mathematical operations, letting you calculate or alter numeric data. Besides standard mathematical operations, you can also perform modulus division, specify a result precision, and use scientific notation.

For example, the function DTW_POWER raises the value of its first parameter to the power of its second parameter and returns the result, as shown in the following example:

@DTW_rPOWER("2", "-3", result)

DTW_POWER returns ".125"

String Functions

These functions let you manipulate characters within strings. You can change a string's case, insert or delete characters, assign a string value to another variable, plus other useful functions.

For example, you can use DTW_ASSIGN to assign the value of an input variable to an output variable. You can also use this function to change a variable in a macro. In the following example, the variable RC is assigned to zero.

@DTW_ASSIGN(RC, "0")

Other string functions include DTW_CONCAT, which concatenates strings, and DTW_INSERT, which inserts strings at a specific position, as well many other string manipulations functions.

Word Functions

These functions let you manipulate words in character strings. Most of these functions work the same as string functions, but on entire words. For example, they let you count the number of words in a string, remove words, search a string for a word.

For example, use DTW_DELW0RD to delete a specified number of words from a string:

@DTW_DELWORD("Now is the time", "2", "2", result)

DTW_DELWORD returns the string "Now time".

Other word functions include DTW_WORDLENGTH, which returns the number of characters in a string, and DTW_WORDPOS, which returns the position of a word within a string.

Table Functions

You can use these functions to generate reports or forms using the data in a Net.Data table variable. You can also use these functions to get and set the values in a Net.Data table variable. Table variables contain an array of values and their associated column names. They provide a convenient way to pass groups of values to a function.

For example, DTW_TB_APPENDROW appends a row to the table. In the following example, Net.Data appends ten rows to the table, myTable:

@DTW_TB_APPENDROW(myTable, "10")

Additionally, DTW_TB_DUMPH, returns the contents of a macro table variable, enclosed in <PRE></PRE> tags, with each row of the table is displayed on a different line. And DTW_TB_CHECKBOX returns one or more HTML check box input tags from a macro table variable.

Flat File Functions

Use the flat file interface (FFI) functions to open, read, and manipulate data from flat file sources (text files), as well as store data in flat files.

For example, DTWF_APPEND, writes the contents of a table variable to the end of a file, and DTWF_DELETE deletes records from a file.

Additionally, the FFI functions allow file locking with DTWF_CLOSE and DTWF_OPEN. DTWF_OPEN locks a file that so that another process cannot read or update the file. DTWF_CLOSE releases the file when Net.Data is done with it, allowing other processes to access the file.


Web Registry Functions

Use the Web registry functions to maintain registries and the entries they contain. A Web registry is a file with a key maintained by Net.Data to allow you to add, retrieve, and delete entries easily.

For example, DTWR_ADDENTRY adds entries, while DTWR_DELENTRY deletes entries. DTWR_LISTSUB returns information about the registry entries in an OUT table parameter, and DTWR_UPDATEENTRY replaces the existing values for a specified registry entry with a new value.

Persistent Functions

The persistent macro functions support transaction processing in Net.Data by helping you define which macro blocks are persistent within a single transaction. Use these functions to define the start and end of a transaction, which HTML blocks are persistent throughout the transaction, the scope of the variables within the transaction, and whether to commit or rollback changes within the transaction.

For example, DTW_ACCEPT identifies the transaction handle for a transaction, while DTW_TERMINATE identifies the final HTML block in the transaction. DTW_RTVHANDLE generates a unique transaction handle for blocks in the transaction. You can use DTW_COMMIT and DTW_ROLLBACK to initiate commits and rollbacks during the transaction.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]