REXX Language Environment

The REXX language environment allows you to run REXX programs.

Configuring the REXX Language Environment

To use the REXX language environment, you need to verify the Net.Data initialization settings and set up the language environment.

Verify that the following configuration statement is in the initialization file, on one line:

ENVIRONMENT (DTW_REXX)     DTWREXX   ( OUT RETURN_CODE )
 

See Environment Configuration Statements to learn more about the Net.Data initialization file and language environment ENVIRONMENT statements.

Executing REXX Programs

With the REXX language environment you can execute both in-line REXX programs or external REXX programs. An in-line REXX program is a REXX program that has the source of the REXX program in the macro. An external REXX program has the source of the REXX program in a external file.

To execute an in-line REXX program:

Define a function that uses the REXX (DTW_REXX) language environment and contains the REXX code in the language environment-executable section of the function.

Example: A function that contains a in-line REXX program

%function(DTW_REXX) helloWorld() {
        SAY 'Hello World'
%}

To run an external REXX program:

Define a function that uses the REXX (DTW_REXX) language environment and includes a path to the REXX program that is to be run in an EXEC statement.

Example: A function that contains an EXEC statement pointing to a the external program

%function(DTW_REXX) externalHelloWorld() {        
%EXEC{ helloworld.exe%}       
%}

Required: Ensure that the REXX file name is listed in a path specified for the EXEC_PATH configuration variable in the Net.Data initialization file. See EXEC_PATH to learn how to define the EXEC_PATH configuration variable.

Passing Parameters to REXX programs

There are two ways to pass information to a REXX program that is invoked by the REXX (DTW_REXX) language environment, directly and indirectly.

Directly
Pass parameters directly to an external REXX program using the %EXEC statement. For example:
%FUNCTION(DTW_REXX) rexx1() {                               
  %EXEC{                                   
    CALL1.CMD $(INPARM) "literal string"   %}                            
%}

The Net.Data variable INPARM1 is dereferenced and passed to the external REXX program. The REXX program can reference the variable by using REXX PARSE ARG instruction. The parameters that are passed to the program using this method are considered input type parameters (the parameters passed to the program can be used and manipulated by the program, but changes to the parameters are not reflected back to Net.Data).

Indirectly

Pass parameters indirectly, by way of the REXX program variable pool. When a REXX program is started, a space which contains information about all variables is created and maintained by the REXX interpreter. This space is called the variable pool.

When a REXX language environment (DTW_REXX) function is called, any function parameters that are input (IN) or input/output (INOUT) are stored in the variable pool by the REXX language environment prior to executing the REXX program. When the REXX program is invoked, it can access these variables directly. Upon the successful completion of the REXX program, the DTW_REXX language environment determines whether there are any output (OUT) or INOUT function parameters. If so, the language environment retrieves the value corresponding to the function parameter from the variable pool and updates the function parameter value with the new value. When Net.Data receives control, it updates all OUT or INOUT parameters with the new values obtained from the REXX language environment. For example:

%DEFINE a = "3"
%DEFINE b = "0"
%FUNCTION(DTW_REXX) double_func(IN inp1, OUT outp1){
   outp1 = 2*inp1
%}
 
%HTML(REPORT) { 
Value of b is $(b), @double_func(a, b) Value of b is $(b)
%}

In the above example, the call @double_func passes two parameters, a and b. The REXX function double_func doubles the first parameter and stores the result in the second parameter. When Net.Data invokes the macro, b has a value of 6.

You can pass Net.Data tables to a REXX program. A REXX program accesses the values of a Net.Data macro table parameter as REXX stem variables. To a REXX program, the column headings and field values are contained in variables identified with the table name and column number. For example, in the table myTable, the column headings are myTable_N.j, and the field values are myTable_N.i.j, where i is the row number and j is the column number. The number of rows in the table is myTable_ROWS and the number of columns in the table is myTable_COLS.

Improving Performance for the AIX operating system:

If you have many calls to the REXX language environment on your AIX system, consider setting the RXQUEUE_OWNER_PID environment variable to 0. Macros that make many calls to the REXX language environment can easily spawn many processes, swamping system resources.

You can set the environment variable in one of three ways:

REXX Language Environment Example

The following example shows a macro that calls a REXX function to generate a Net.Data table that has two columns and three rows. Following the call to the REXX function, a built-in function, DTW_TB_TABLE(), is called to generate an HTML table that is sent back to the browser.

%DEFINE myTable = %TABLE
%DEFINE DTW_DEFAULT_REPORT = "NO"     
 
%FUNCTION(DTW_REXX) genTable(out out_table) {
  out_table_ROWS = 3
  out_table_COLS = 2
 
  /* Set Column Headings */
  do j=1 to out_table_COLS
    out_table_N.j = 'COL'j
  end
 
  /* Set the fields in the row */
  do i = 1 to out_table_ROWS
    do j = 1 to out_table_COLS
      out_table_V.i.j = '[' i j ']'
    end
  end
%}
 
%HTML(REPORT)  {
 @genTable(myTable)
 @DTW_TB_TABLE(myTable)
%}

Results:

  COL1      COL2 
[ 1 1 ]   [ 1 2 ] 
[ 2 1 ]   [ 2 2 ] 
[ 3 1 ]   [ 3 2 ]  


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