Information icon IBM InfoSphere DataStage and InfoSphere QualityStage, Version 8.5
space Feedback

Function Statement

Identifies a user-written function and specifies the number and names of the arguments to be passed to it. Not available in expressions.

Syntax

Function [name] [ argument1 [, argument2] ...]

name is the name of the user-written function and can be any valid variable name.

argument1 and argument2 are the formal names of arguments to be passed to the function. The formal names reference the actual names of the parameters that are used in the calling program (see the examples). You can specify up to 254 arguments. The calling function in the main program must specify the same number of arguments as the Function statement.

Remarks

A user-written function can contain only one Function statement, which must be the first noncomment line.

An extra argument is hidden so that the user-written function can use it to return a value. An extra argument is retained by the user-written function so that a value is returned by the Return statement. If you use the Return statement in a user-written function and you do not specify a value to return, an empty string is returned.

Calling the User-Written Function

The calling program must contain a Deffun statement that defines the user-written function before it is called. The user-written function must be cataloged in either a local catalog or the system catalog, or it must be a record in the same object file as the calling program.

If the user-defined function calls itself recursively, you must include a Deffun statement preceding the recursive call. For example:

Function Cut(expression, character)
Deffun Cut (A1,A2)
If character # '' Then
...
   Return (Cut (expression, character [2,999999]))
End Else
   Return (expression)
End
End

Examples

In this example, a user-defined function called Short compares the length of two arguments and returns the shorter:

Function Short(A,B)
AL = Len(A)
BL = Len(B)
If AL < BL Then Result = A Else Result = B
Return(Result)

In this example, a function called MyFunc is defined with the argument names A, B, and C. It is followed by an example of the DefFun statement declaring and using the MyFunc function. The values held in X, Y, and Z are referenced by the argument names A, B, and C so that the value assigned to T can be calculated.

Function MyFunc(A, B, C)
Z = ...
Return (Z)
   ...
   End
DefFun MyFunc(X, Y, Z)
T = MyFunc(X, Y, Z)
End

This example shows how to call a transform function named MyFunctionB from within another transform function named MyFunctionA:

Function MyFunctionA(Arg1)
* When referencing a user-written function that is held in the 
* DataStage repository, you must declare it as a function with 
* the correct number of arguments, and add a "DSU." prefix.
Deffun MyFunctionB(A) Calling "DSU.MyFunctionB"
   Ans = MyFunctionB(Arg1)
* Add own transformation to the value in Ans...
...

PDFThis topic is also in the IBM InfoSphere DataStage Server Job Developer's Guide.

Update timestamp Last updated: 2010-09-30