To create your own functions, a C or C++ development tool
is required, or the Java Native Interface (JNI) if you are working
in a Java environment.
Procedure
-
In the Type
Designer or Map Designer, you can create a new function by selecting .
The Custom Function Modules window is
displayed.
- In the Path field, enter the path
of where to create the external library.
This should always be in the
<install_dir>/function_libs directory.
- In the Name field, enter a name
for the library.
- Click Add to add a function to the
library.
The Function Specification window is displayed.
- In the Name field, enter a name
for the function.
- For Return Type, select the function
return type from the drop-down list.
You can select up to four function parameters from the respective drop-down list. Choices
include None, Text, Number, Date and Time.
- In the space provided, enter a description for your function.
This information will be displayed in the Functions window of both
Designers.
-
Click OK to validate the selected parameters and close the
Function Specifications window.
- Click Generate.
The
Designer generates a collection of operating system specific makefiles
and definition files that provide the framework for the function you
are creating.
-
Go to the <install_dir>/function_libs
directory to view the results.
As a result of the generation process, framework files are created for each
operating system that IBM Sterling Transformation Extender supports. You
can find the operating system-specific makefiles and definition files in the
<install_dir>/function_libs/your_new_lib
directory.
- Now you must modify the framework that was generated by
the Designer.
The following functions with the parameter information that you selected were exported to the
.c file:
- GetFunctionCount
- GetFunctionName
- GetInputParameter
- GetReturnType
- GetParameterCount
- GetFunctionDesc
To complete the new function, open the .c file and add your
programming code for the applicable function or functions provided.
Use the .c
file to build your dynamic link library (DLL) and then place the DLL in the
<install_dir>/function_libs/your_new_lib
directory. (All custom designed libraries and functions must be placed in the
<install_dir>/function_libs directory.)
The new library name is listed under Category in the
Functions window, and the new function that you created is placed
in the list of functions and will remain available for future use from both the Type
Designer and Map Designer applications.
Example
The following example displays how to implement a custom
function called SIN. void ConvertToBytes(double returnValue, LPEXITPARAM lpep)
{
double value = 0.0;
int decimal = 2, sign = 0, j = 0, k = 0;
char byString[100];
char* lpbyData = _fcvt(returnValue, 7, &decimal, &sign );
memset(byString, 0, sizeof(byString));
if (sign)
byString[j++] = '-';
if (decimal <= 0)
{
byString[j++] = '0';
byString[j++] = '.';
while (decimal != 0)
{
byString[j++] = '0'; decimal++;
}
}
else if (decimal > 0)
{
while (decimal != 0)
{
byString[j++] = lpbyData[k++]; decimal--;
}
byString[j++] = '.';
}
while (lpbyData[k]) byString[j++] = lpbyData[k++];
byString[j] = '\0';
if (NULL == (lpep->lpDataFromApp = GlobalAllocPtr
(GHND, j + 1)))
{
lpep->nReturn = -1;
lstrcpy(lpep->szErrMsg, "Memory allocation failed in Alternate");
return;
}
memcpy(lpep->lpDataFromApp, byString, j);
lpep->dwFromLen = j;
lpep->lpDataFromApp[j++] = '\0';
}
void CALLBACK EXPORT SIN(LPEXITPARAM lpep)
{
double value = 0.0;
double returnValue = 0.0;
LPEXITPARAMEXTENDED lpExtended = NULL;
if (lpep->dwSize != sizeof(EXITPARAM))
{
return;
}
lpExtended = (LPEXITPARAMEXTENDED)lpep->lpv;
value = atof(lpExtended->lpFirstInputParameter);
returnValue = sin(value);
ConvertToBytes(returnValue, lpep);
lpep->wCleanupAction = GetReturnType("SIN");
lstrcpy(lpep->szErrMsg, "SIN function was successful");
return;
}
What to do next
At run time, all custom designed libraries and functions that your maps use
must be in the <install_dir>/function_libs
directory. When you deploy a map that uses a custom function to a remote host, the library is
not transferred. Therefore you must manually copy the custom function library to the
<install_dir>/function_libs directory on the remote host. From a
component rule in the Type Designer or from a map rule in the Map Designer, right-click and
select the Insert Functions option. The new custom functions library
appears as a separate category in the Functions window displayed in the
Designers. Drag and Drop the new custom function in the component rule in the Type Designer
or map rule in the Map Designer.
Custom functions follow the calling
convention:
library_name->function_name([argument 1, [argument 2, [argument 3, [argument 4]]]])