IBM Books

Net.Data Administration and Programming Guide for OS/400

Calling Functions

Use a Net.Data function call statement to call both user-defined functions and built-in functions. Use the at (@) character followed by a FUNCTION block name or a MACRO_FUNCTION block name:

@function_name([ argument,... ])

function_name
This is the name of the FUNCTION block or MACRO_FUNCTION block to invoke. The function must already be defined in the Net.Data macro, unless this is a built-in function.

argument
This is the name of a defined variable, a literal character string, a variable reference, or a function call. Arguments on a function call are matched up with the parameters on a FUNCTION block or MACRO_FUNCTION block, and each parameter is assigned the value of its corresponding argument while the FUNCTION block or MACRO_FUNCTION block is being processed. The arguments must be the same number and type as the corresponding parameters.

Net.Data processes the FUNCTION block, MACRO_FUNCTION block, or built-in functions associated with a function call in the following order:

  1. Net.Data processes the variable references and function calls in the executable-statements section of the FUNCTION block. Net.Data replaces all variable references with the current values of the variables, and executes and replaces all function calls with the return value of the function call. The variable references and function calls are processed in the order in which they are specified. Net.Data does not process built-in functions or MACRO_FUNCTION blocks during this step.

  2. The native language processor processes the executable-statements section. For FUNCTION blocks, the processor corresponds to the language environment specified on the FUNCTION block, such as SQL, REXX, or Perl. For MACRO_FUNCTION blocks, Net.Data acts as the language processor and executes the executable statements. Built-in functions do not have executable statements. Net.Data processes the built-in functions by function name.

    Net.Data passes the function's parameters to the native language processor. Net.Data passes values to the native language processor only for IN and INOUT parameters and accepts returned values from the native language processor only for OUT and INOUT parameters,

  3. Net.Data sets the implicit RETURN_CODE and DTW_DEFAULT_MESSAGE variables based on the return code and the returned message from the language processor. Net.Data does not set these variables for MACRO_FUNCTION blocks.

  4. If the FUNCTION block or MACRO_FUNCTION block contains one or more REPORT blocks, or specifies default reports to be generated, Net.Data processes the reports using the new values of any referenced output parameters. Net.Data does not generate reports for built-in functions.

  5. If the FUNCTION block contains a local MESSAGE block, Net.Data processes the MESSAGE block. Net.Data processes the global MESSAGE block when one of the following conditions occurs: blocks.

  6. Net.Data replaces the function call with the returned value of the function. For FUNCTION blocks, this value is one of the following:

    RETURNS parameter value
    Substituted for the FUNCTION block with a RETURNS keyword.

    Empty string ("")
    Substituted For the FUNCTION block without a RETURNS keyword when RETURN_CODE is zero.

    RETURN_CODE
    Substituted for FUNCTION block without a RETURNS keyword when RETURN_CODE is not zero.

    For MACRO_FUNCTION blocks, the results of processing the executable-statements section replaces the function call.

    For built-in functions, the value depends on the format of the built-in function.


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