IBM Books

Administration and Programming Guide for OS/400

The FUNCTION Block

The FUNCTION block contains declarations for functions invoked by the HTML blocks. Functions are processed by language environments and can execute programs, SQL queries, or stored procedures.

The following example shows two FUNCTION blocks. One defines a call to an external REXX program and the other contains inline REXX statements.

%{ ********************** FUNCTION Block **********************************%}
%FUNCTION(DTW_REXX) rexx1 (IN input) returns(result) { <-- This function accepts
                                                       one parameter and returns the
                                                       variable 'result', which is
                                                       assigned by the external REXX
                                                       program
     %EXEC{ompsamp.mbr %}  <-- The function executes an external REXX program
                               called "ompsamp.mbr"
%}
 
%FUNCTION(DTW_REXX) today () RETURNS(result) {
      result = date()  <-- The single source statement for this function is
                           contained inline.
%}

The first function block, rexx1, is a REXX function declaration that in turn, runs an external REXX program called ompsamp.mbr. One input variable, input, is accepted by this function and automatically passed to the external REXX command. The REXX command also returns one variable called result. The contents of the result variable in the REXX command replaces the invoking @rexx1() function call contained in the OUTPUT block. The variables input and result are directly accessible by the REXX program, as shown in the source code for ompsamp.mbr:

/* REXX */
result = 'The REXX program received "'input'" from the macro.'

The code in this function echoes the data that was passed to it. You can format the resulting text any way you want by enclosing the requesting @rexx1() function call in normal mark-up style tags (like <b> or <em>). Rather than using the result variable, the REXX program could have written HTML tags to standard output using REXX SAY statements.

The second function block, also refers to a REXX program, today. However, the entire REXX program in this case is contained in the function declaration itself. An external program is not needed. Inline programs are allowed for both REXX and Perl functions because they are interpreted languages that can be parsed and executed dynamically. Inline programs have the advantage of simplicity by not requiring a separate program file to manage. The first REXX function could also have been handled inline.


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