Using the Define Function Dialog Box to Define an Expression
When you define a Java expression, you configure the function, create the expression, and generate the code that invokes the expression.
You can define the function and create the expression in the Define Function dialog box.
To create an expression function and use the expression in a Java transformation, complete the following high-level tasks:
- 1. Configure the function that invokes the expression, including the function name, description, and parameters. You use the function parameters when you create the expression.
- 2. Create the expression syntax and validate the expression.
- 3. Generate the Java code that invokes the expression.
The Developer places the code on the Functions code entry tab.
After you generate the Java code, call the generated function on the appropriate code entry tab to invoke an expression or get a JExpression object, based on whether you use the simple or advanced interface.
Step 1. Configure the Function
You configure the function name, description, and input parameters for the Java function that invokes the expression.
Use the following rules and guidelines when you configure the function:
- •Use a unique function name that does not conflict with an existing Java function in the transformation or reserved Java keywords.
- •You must configure the parameter name, Java datatype, precision, and scale. The input parameters are the values you pass when you call the function in the Java code for the transformation.
- •To pass the Date datatype to an expression, use the String datatype for the input parameter.
If an expression returns the Date datatype, you can use the return value as the String datatype in the simple interface and the String or long datatype in the advanced interface.
Step 2. Create and Validate the Expression
When you create the expression, use the parameters you configured for the function.
You can also use transformation language functions, custom functions, or other user-defined functions in the expression. You can create and validate the expression in the Define Function dialog box.
Step 3. Generate Java Code for the Expression
After you configure the function and function parameters and define and validate the expression, you can generate the Java code that invokes the expression.
The Developer places the generated Java code on the Functions code entry tab. Use the generated Java code to call the functions that invoke the expression in the code entry tabs. You can generate the simple or advanced Java code.
After you generate the Java code that invokes an expression, you cannot edit the expression and revalidate it. To modify an expression after you generate the code, you must create the expression again.
Creating an Expression and Generating Java Code by Using the Define Function Dialog Box
You can create a function that invokes an expression in the Define Function dialog box.
Complete the following steps to create a function that invokes an expression:
1. In the Developer, open a Java transformation or create a new Java transformation.
2. On the Java Code tab, click New Function.
The Define Function dialog box appears.
3. Enter a function name.
4. Optionally, enter a description for the expression.
Enter up to 2,000 characters.
5. Create the arguments for the function.
When you create the arguments, configure the argument name, datatype, precision, and scale.
6. On the Expression tab, create an expression with the arguments that you created.
7. To validate the expression, click Validate.
8. Optionally, enter the expression in the Expression box. Then, click Validate to validate the expression.
9. To generate Java code by using the advanced interface, select the Generate Advanced Code option. Then, click Generate.
The Developer generates the function to invoke the expression on the Functions code entry tab.
Java Expression Templates
You can generate Java code for an expression using the simple or advanced Java code for an expression.
The Java code for the expression is generated based on the template for the expression.
The following example shows the template for a Java expression generated for simple Java code:
Object function_name (Java datatype x1[,
Java datatype x2 ...] )
throws SDK Exception
{
return (Object)invokeJExpression( String expression,
new Object [] { x1[, x2, ... ]} );
}
The following example shows the template for a Java expression generated by using the advanced interface:
JExpression function_name () throws SDKException
{
JExprParamMetadata params[] = new JExprParamMetadata[number of parameters];
params[0] = new JExprParamMetadata (
EDataType.STRING, // data type
20, // precision
0 // scale
);
...
params[number of parameters - 1] = new JExprParamMetadata (
EDataType.STRING, // data type
20, // precision
0 // scale
);
...
return defineJExpression(String expression,params);
}