With the release of PI 7.31, the NWDS tool is becoming robust enough to replace the Swing tools used in the Enterprise Service Repository (ESR) and the Integration Directory (ID). One of the main focuses in PI, with each new SP release, is on improving the NWDS tools.
In developing an integration scenario, we may spend as much as 80-90% of our time in the development of mapping/transformation. The Swing tool provides us with Message Mapping, which also includes a graphical tool for us to create user-defined function (UDF). UDF is very important to the development of mapping programs. It is impossible to expect the default Message Mapping tool to meet 100% of our mapping requirements. As a result, UDF is there to help us fill the gaps of the special mapping needs which cannot be met with the default tool.
The ability to create UDF is available with the NWDS tool beginning in PI 7.31 SP4. But, there has been a lack of documentation of how to create an UDF. So, in this blog I will provide the steps on how to create UDF in NWDS. In addition, I will use the GUI mapping tool in NWDS to demonstrate it. This GUI mapping tool is going to be available in PI 7.31 SP6, which is scheduled for release in the beginning of 2013.
With NWDS, UDF must be created in a Function Library. In our mapping program we can specify the function library(s) we want to use. Then, the UDFs created in the Function Library will be available to us during mapping.
One big advantage of using NWDS to create UDF is the availability of the Java development environment, e.g. syntax checking, auto-display of methods in a class, etc. I think these features have been frequently requested for the Swing tool.
In this blog, I am assuming the reader is already familiar with using NWDS with ESR. If not, please reference the blog: Eclipse Tool for ESR in NW PI
To use as an example for this blog, I am going to write a simple UDF to extract the nth element of a comma-delimited string. For example, for the string "element1,element2, element3", the 1st element is "element1", the 2nd is "element2", the 3rd element is "element3".
Steps to create and use an UDF:
Details of the steps:
The code for the method is below. Please note:
(you will need to make the appropriate changes to your own UDF based on the above information)
You may need to resolve the undefined references by importing the following:
import com.sap.ide.esr.tools.mapping.core.Argument;
import com.sap.ide.esr.tools.mapping.core.ExecutionType;
import com.sap.ide.esr.tools.mapping.core.LibraryMethod;
Java code for the method “getElement”:
@LibraryMethod(title="getElement", description="", category="MyUDF", type=ExecutionType.SINGLE_VALUE)
public String getElement (
@Argument(title="") String num,
@Argument(title="") String source,
Container container) throws StreamTransformationException{
String delimiter = ",";
int n = Integer.valueOf(num).intValue();
String[] temp;
temp = source.split(delimiter);
if (n > temp.length)
return "ERROR";
return temp[n-1];
}
Sample screenshot:
Save and close the “MyUDF.java” tab.
Select the UDF and click “OK”.
The UDF should now show up under “Function Libraries”.
(Please note on the right-hand side, the “MyUDF” with the method “getElement” is now available for mapping.)
The constant for fld_1 = 1 (to get the 1st element)
The constant for fld_2 = 2 (to get the 2nd element)
Input:
Output:
From my perspective, I still have the following questions. Once I find the answers, I will update this blog:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
25 | |
17 | |
15 | |
12 | |
9 | |
9 | |
8 | |
8 | |
8 | |
7 |