Skip to main content

 
IBM Power Systems software  >  IBM i  > Software  > 

Net.Data for i5/OS

  
Overview News Library Education Support

New Net.Data Table Built-in Functions

With our latest set of PTFs (which includes V3R2, V3R7 and subsequent releases), Net.Data is providing a complete set of built-in functions which allow users to directly access and manipulate Net.Data table variables. These built-ins can be called from anywhere in your macro, and provide the following capabilities:

  • Get the current number of rows or columns in a table
  • Get the maximum number of rows in a table
  • Get column names
  • Get row/column values
  • Add or remove rows or columns
  • Set or modify column names
  • Set or modify row/column values

The table below gives the list of the functions and a short description. Detailed information can be found in the Net.Data Reference.

(Note that on other platforms, Version 2 of Net.Data (now in beta) currently supports the following functions: DTW_TB_GETN, DTW_TB_GETV, DTW_TB_COLS, and DTW_TB_ROWS).

Function Description
DTW_TB_APPENDROW Adds one or more rows to the end of a table.
DTW_TB_COLS, DTW_TB_rCOLS Returns the current number of columns in a table.
DTW_TB_DELETECOL Removes one or more columns from a table.
DTW_TB_DELETEROW Removes one or more rows from a table.
DTW_TB_GETN, DTW_TB_rGETN Retrieves a table column heading.
DTW_TB_GETV, DTW_TB_rGETV Retrieves a value from a table.
DTW_TB_INSERTCOL Inserts one or more columns in a table.
DTW_TB_INSERTROW Inserts one or more rows in a table.
DTW_TB_MAXROWS, DTW_TB_rMAXROWS Returns the maximum number of rows allowed in a table.
DTW_TB_QUERYCOLNONJ, DTW_TB_rQUERYCOLNONJ Returns the column number associated with a column heading.
DTW_TB_ROWS, DTW_TB_rROWS Returns the current number of rows in a table.
DTW_TB_SETCOLS Sets the number of columns in the table.
DTW_TB_SETN Assigns a name to a column heading.
DTW_TB_SETV Assigns a value in a table.

Previously, the only way for a user to modify a table was to call a REXX program or a program that is called from the SYSTEM language environment. This not only required programming skills, but was also costly in terms of performance, particularly with REXX. In addition, just to reference or display the data in a table, a user had to write a %FUNCTION or %MACRO_FUNCTION block with a %REPORT block, which again was not very efficient, particularly if the user wanted to access a specific value in a table.

The new table built-ins allow the user to get or change any value in a Net.Data table variable with a single built-in function call from anywhere in a macro. Not only does this greatly simplify table processing, but at the same time provides a tremendous performance improvement over current methods of processing table variables.

Another important benefit of these new built-in functions is the fact that you do not have to define variables and then assign table values to these variables in order to use the data in the table outside of a FUNCTION block or in another FUNCTION block. All you have to do is define a table variable in your macro and pass the table variable to the FUNCTION block that will populate the table. Then you can use the functions to access individual table fields from anywhere in the macro!

In the following example, we can provide 3 different views of a table while doing just a single query:

%DEFINE {
   myTable = %table
   DTW_DEFAUT_REPORT = "NO"
   rowIndex = "0"
   numRows = "0"
%}

%FUNCTION(DTW_SQL) custlist(OUT table) {
   SELECT Name, Phone, Fax, City, Zipcode from dbLib.CustomerTbl
%}

%HTML(REPORT) {
   %{ get the data for our tables %}
   @custlist(myTable)
   @DTW_TB_ROWS(myTable, numRows)

   %{ display a list of all customers in Chicago %}

Customers in Chicago:
%WHILE (rowIndex < numRows) { %IF ("Chicago" == @DTW_TB_rGETV(myTable, rowIndex, "4")) %ENDIF @DTW_ADD(rowIndex, "1", rowIndex) %}

Name Phone Fax
@DTW_TB_rGETV(myTable, rowIndex, "1") @DTW_TB_rGETV(myTable, rowIndex, "2") @DTW_TB_rGETV(myTable, rowIndex, "3")

   %{ display a list of all customers with zip code 60609 %}
   @DTW_ASSIGN(rowIndex, "0")

Customers with zip code 60609:
%WHILE (rowIndex < numRows) { %IF ("60609" == @DTW_TB_rGETV(myTable, rowIndex, "5")) %ENDIF @DTW_ADD(rowIndex, "1", rowIndex) %}

Name Phone Fax
@DTW_TB_rGETV(myTable, rowIndex, "1") @DTW_TB_rGETV(myTable, rowIndex, "2") @DTW_TB_rGETV(myTable, rowIndex, "3")

   %{ display a list of all customers in area code 201 %}
   @DTW_ASSIGN(rowIndex, "0")

Customers with area code 201:
%WHILE (rowIndex < numRows) { %IF ("201" == @DTW_rSUBSTR(@DTW_TB_rGETV(myTable, rowIndex, "4"),"1","3")) %ENDIF @DTW_ADD(rowIndex, "1", rowIndex) %}

Name Phone Fax
@DTW_TB_rGETV(myTable, rowIndex, "1") @DTW_TB_rGETV(myTable, rowIndex, "2") @DTW_TB_rGETV(myTable, rowIndex, "3")

%}