Calling User-Written Functions

The syntax for calling a user-written function in a rule file is:

%%Ans = Name(%%IN_VAR)

The following table describes the parameters used to call a user-written function.

Parameter Description
%%Ans A variable whose value results from the call to the user-written function.
Name The user-written function name. This must be identical to the name value in the USERFUNCTION command used to declare the function.
%%IN_VAR The variable or constant string to store in InData in the Input Call Area (that is, the data the user-written function will use as input).

In the example rule file shown in the figure below, the user-written function ims_database is a COBOL load module FNIMS2 that uses an account number to look up a client’s age in an IMS database. Either %%Account or %%Account2 contains the customer account. FNIMS2 is a normal user-written function subroutine with an input string (%%Account or %%Account2) of maximum length 25 bytes that returns an output string (%%Age) of up to 3 bytes. The Input Call area is 65 bytes (40 + 25) in length while the Output Call area is 43 bytes (40 + 3) in length.

USERFUNCTION ims_database FNIMS2 COBOL N 25 3
IF %%Account <> '' THEN
   %%Age = ims_database(%%Account)
ELSE
   %%Age = ims_database(%%Account2)
ENDIF

Hints

  • User-written functions always have one argument, %%IN_VAR, that can be a variable or a constant string.
  • If multiple variables must be passed into the user-written function, you can concatenate them into one long variable.
  • If multiple values must be returned by the user-written function, you can extract them from the result variable using the SUBSTR or RGET built-in functions.