on 05-14-2008 12:28 PM
Hi,
Being am a trainee i didnt understand much about the user-defined functions at my training period..
Will you plz tell about them with best examples as u developed in real time and their requirement in scenario..
I tried for them very much in SDN..that is not statisfactory
Regards
guna
UserDefined Function types:
Simple functions
*******************
1) process individual field input values for each function call.
2) expect strings as input values
3) return a string.
eg
function myudf(String a, Container container)
{
if (a.equals("Business"))
return "B";
else if (a.equals("Private"))
return "P";
else
return "X";
}
Advanced functions
**********************
1) process nonsingle string field input values for each function call
2) pass either all field values of a context or the whole queue
3) input field is passed as string array
4) returned values are stored in a string array, ResultList
function myudf(String a[], ResultList result, Container container)
{
for(int i=0;i<a.length;i++)
if(!a[<i>].equals(""))
result.addValues(a<i>);
}
=> This is to add non empty values to target structure.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks for the answers
regards
guna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Guna,
In order to create UDFs, you need to have a basic idea about using Core Java. Also, based on the kind of functonality of the code, you will need to know if you require any extra jar files.
To create a UDF, all you need to do is click on LHS icon in the graphical mapping editor. Also, keep in min that the input and otput of a udf is always in strings.
To test your functions, you can either use the test tab present in the mapping editor or you can even use the following editor(blog by Sravya):-
/people/sravya.talanki2/blog/2006/07/24/integrating-java-editor-in-xi-integration-stack
I think info will be enough for you to start off with creating and using UDFs:)
Check the Teched 2004 presentation of our mapping gurus:
/people/vijayasarathy.raghunathan/blog/2005/12/28/java-editor-inside-abap
Check this SAP help :
http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/frameset.htm
Reward points if this helps
Regards
Vani.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Guna,
There are 2 types of UDF - Simple and Advanced.
Simple UDFs uses Value, wherein we can manipulate only one value (input is one String). Therefore a single string is expected as input and the output would also b a single string.
Advanced UDFs uses Context or Queue, where you manipulate many values (input is an array of Strings).
Refer this link:
http://help.sap.com/saphelp_nw04/helpdata/en/40/7b8e40496f6f1de10000000a1550b0/content.htm
User-Defined Functions
Use
If the standard functions for a target field mapping do not fulfill your requirements, or if the graphical representation becomes unclear due to the complexity of the mapping, you have the option of creating your own user-defined functions. You can create Java source text in this function. The function is included in the Java coding that is generated for the message mapping as a Java method.
Activities
1. To create a new user-defined function, choose Create New Function () in the data-flow editor at the bottom of the screen, on the left-hand side. Choose Simple Function or Advanced Function in the menu.
2. Specify the attributes of the new function in the subsequent window:
Label:
Text that appears in the function chooser and on the data-flow object to identify the new function.
Name:
Technical name of the function.
Argument Count:
The number of input values that should be transferred to the function.
Description:
Description of how the function is used.
3. In the subsequent window you can create Java source code:
a. You can import Java packages to your methods from the Imports input field, by specifying them separated by a comma or semi-colon:
You do not need to import the packages java.lang., java.util., java.io., and java.lang.reflect. since all message mappings require these packages and therefore import them. You should be able to access standard JDK and J2EE packages of the SAP Web Application Server by simply specifying the package under Import. In other words, you do not have to import it as an archive into the Integration Repository. You can also access classes of the SAP XML Toolkit, the SAP Java Connector, and the SAP Logging Service (see also: Runtime Environment (Java Mappings)).
Besides the standard packages, you can also specify Java packages that you have imported as archives and that are located in the same, or in an underlying software component version as the message mapping.
b. If you want to import input field queues before you call the function, in advanced functions select the Cache Entire Queue checkbox. If you do not, the current input field context will be imported.
Note that saving the entire queue in the cache in the case of large messages will require a lot of memory at runtime. In such cases it is therefore better to work with contexts.
c. Create your Java source text in the editor window or copy source text from another editor.
4. Choose OK to confirm.
5. User-defined functions are limited to the message mapping in which you created the function. To save the new function, save the message mapping.
6. To test the function, use the test environment.
The new function is now visible in the User-Defined function category. When you select this category, a corresponding button is displayed in the function chooser pushbutton bar. To edit, delete, or add the function to the data-flow editor, choose the arrow next to the button and select from the list box displayed.
Will you plz tell about them with best examples as u developed in real time and their requirement in scenario?
Padded zeros which is removed need to be replaced by spaces
Thanks,
Satya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gunashekar,
UDF user defined function in graphical mapping if ur business requirements are not fulfiled by std functions.
UDF's are user defined functions are of two types,simple UDF which takes in one input and gives out one output and the second one is advanced UDF where in u can access more than one fields,and the result is passed on to ResultList.
UDF can be used in graphical mapping depends upon the requirement.
1) If u wanted to do manuplication in data which can not be done by using the standared XI function that time we go for UDF.
2) For doing Lookup we write the code in UDF and pass the value to R3 system.
Lookup - /people/alessandro.guarneri/blog/2006/03/27/sap-xi-lookup-api-the-killer
DB lookup - /people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler
SOAP Lookup - /people/bhavesh.kantilal/blog/2006/11/20/webservice-calls-from-a-user-defined-function
3) If u need to compare the input value and pass the other value based on comparision that time can go for UDF.
here u need to write
if(A.equals("somevalue"))
{
output Somevalue
}
else
{
output different value
}
4) IF u have a requirement where u need to dynamically take the value from file adapters then u write UDF.
/people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14
/people/william.li/blog/2006/04/18/dynamic-configuration-of-some-communication-channel-parameters-using-message-mapping
There are many different requirement for which we can go ahead with UDF.
For business requirement and business logic we have to write UDFs.check some exaples.
UDF
http://flickr.com/photos/8764045@N06/
Example 1
http://www.flickr.com/photo_zoom.gne?id=544183191&size=o
http://www.flickr.com/photo_zoom.gne?id=544183195&size=o
http://www.flickr.com/photo_zoom.gne?id=544183225&size=o
http://www.flickr.com/photo_zoom.gne?id=544183233&size=o
Example 2
http://www.flickr.com/photo_zoom.gne?id=545133789&size=o
http://www.flickr.com/photo_zoom.gne?id=545133791&size=o
http://www.flickr.com/photo_zoom.gne?id=545133801&size=o
http://www.flickr.com/photo_zoom.gne?id=545133807&size=o
http://www.flickr.com/photo_zoom.gne?id=545133811&size=o
http://www.flickr.com/photo_zoom.gne?id=545138911&size=o
http://www.flickr.com/photo_zoom.gne?id=545138913&size=o
http://www.flickr.com/photo_zoom.gne?id=545138915&size=o
http://www.flickr.com/photo_zoom.gne?id=545138917&size=o
http://www.flickr.com/photo_zoom.gne?id=545138947&size=o
http://www.flickr.com/photo_zoom.gne?id=545138951&size=o
http://www.flickr.com/photo_zoom.gne?id=545005958&size=o
Example 3
http://www.flickr.com/photo_zoom.gne?id=549186611&size=o
http://www.flickr.com/photo_zoom.gne?id=549186651&size=o
http://java.sun.com/j2se/1.5.0/docs/api/
/people/krishna.moorthyp/blog/2006/07/29/documentation-html-editor-in-xi
/people/sap.user72/blog/2006/02/06/xi-mapping-tool-exports
http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm
/people/stefan.grube/blog/2005/12/30/test-user-defined-functions-for-the-xi-graphical-mapping-tool-in-developer-studio
http://help.sap.com/bp_bpmv130/Documentation/Operation/MappingXI30.pdf
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d046c490
Regards,
Vinod.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
you will need udfs if the standard functions can't fulfill your requirements.
For example if you have boolean values in a context and want to know if at least one of them is true you will need a udf.
Example1:
input:
false
false
true
false
output:
true
Example 2:
input:
false
false
false
false
output:
false
Regards
Patrick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This is frequently used UDF in all XI Projects
Iam getting the Material Number from SAP system as 00000123 and i need to post this material number to Target File system by removing Zeros as 123
then we will use this small peace of code t remove the leading zeros
if (a == null) return null;
int i = 0;
int n = a.length();
while (i < n)
{
if (a.charAt(i) != '0') break;
++i;
}
String b = a.substring(i);
return b;
Steps to write the UDF
Activities
1. To create a new user-defined function, in the data-flow editor, choose Create New Function (This
graphic is explained in the accompanying text), which is located on the lower left-hand side of the
screen. In the menu, choose Simple Function or Advanced Function.
2. In the window that appears, specify the attributes of the new function:
Name
Technical name of the function. The name is displayed in the function chooser and on the data-flow
object.
Description
Description of how the function is used.
Cache
Function type (see above)
Argument Count
In this table, you specify the number of input values the function can process, and name them. All
functions are of type String.
3. In the window that appears, you can create Java source code:
...
a. You can import Java packages to your methods from the Imports input field, by specifying them
separated by a comma or semi-colon:
You do not need to import the packages java.lang., java.util., java.io., and java.lang.reflect. since
all message mappings require these packages and therefore import them. You should be able to
access standard JDK and J2EE packages of the SAP Web Application Server by simply specifying the
package under Import. In other words, you do not have to import it as an archive into the Integration
Repository. You can also access classes of the SAP XML Toolkit, the SAP Java Connector, and the
SAP Logging Service (see also: Runtime Environment (Java-Mappings)).
In addition to the standard packages, you can also specify Java packages that you have imported as
archives and that are located in the same, or in an underlying software component version as the
message mapping.
b. Create your Java source text in the editor window or copy source text from another editor.
4. Confirm with Save and Close.
5. User-defined functions are limited to the message mapping in which you created the function. To
save the new function, save the message mapping.
6. To test the function, use the test environment.
The new function is now visible in the User-Defined function category. When you select this category,
a corresponding button is displayed in the function chooser pushbutton bar. To edit, delete, or add the
function to the data-flow editor, choose the arrow next to the button and select from the list box
displayed.
Regards
Seshagiri
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI,
Activities
1. To create a new user-defined function, in the data-flow editor, choose Create New Function (This
graphic is explained in the accompanying text), which is located on the lower left-hand side of the
screen. In the menu, choose Simple Function or Advanced Function.
2. In the window that appears, specify the attributes of the new function:
Name
Technical name of the function. The name is displayed in the function chooser and on the data-flow
object.
Description
Description of how the function is used.
Cache
Function type (see above)
Argument Count
In this table, you specify the number of input values the function can process, and name them. All
functions are of type String.
3. In the window that appears, you can create Java source code:
...
a. You can import Java packages to your methods from the Imports input field, by specifying them
separated by a comma or semi-colon:
You do not need to import the packages java.lang., java.util., java.io., and java.lang.reflect. since
all message mappings require these packages and therefore import them. You should be able to
access standard JDK and J2EE packages of the SAP Web Application Server by simply specifying the
package under Import. In other words, you do not have to import it as an archive into the Integration
Repository. You can also access classes of the SAP XML Toolkit, the SAP Java Connector, and the
SAP Logging Service (see also: Runtime Environment (Java-Mappings)).
In addition to the standard packages, you can also specify Java packages that you have imported as
archives and that are located in the same, or in an underlying software component version as the
message mapping.
b. Create your Java source text in the editor window or copy source text from another editor.
4. Confirm with Save and Close.
5. User-defined functions are limited to the message mapping in which you created the function. To
save the new function, save the message mapping.
6. To test the function, use the test environment.
The new function is now visible in the User-Defined function category. When you select this category,
a corresponding button is displayed in the function chooser pushbutton bar. To edit, delete, or add the
function to the data-flow editor, choose the arrow next to the button and select from the list box
displayed.
http://help.sap.com/saphelp_nw04/helpdata/en/d9/718e40496f6f1de10000000a1550b0/content.htm
http://java.sun.com/j2se/1.5.0/docs/api/
/people/krishna.moorthyp/blog/2006/07/29/documentation-html-editor-in-xi
/people/sap.user72/blog/2006/02/06/xi-mapping-tool-exports
http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm
UDF -
http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.