cancel
Showing results for 
Search instead for 
Did you mean: 

User defined functions

Former Member
0 Kudos

Please help me how to create user defined functions in pi 7.0 and what basic knowledge is require to create user defined functions?

If possible, please provide me already prepared user defined functions for understanding.

Accepted Solutions (1)

Accepted Solutions (1)

aashish_sinha
Active Contributor
0 Kudos

Hi,

A user-defined function is only visible in the message mapping in which you created it. You can insert the function in the data-flow editor as a standard function by using the User-Defined function category.You can use your Java programs from imported archives in user-defined functions if the Java programs are located in the same, or an underlying software component version as the message mapping.

You can use the following user-defined functions:

- Simple functions, which can process individual field input values for each function call. Simple functions therefore expect strings as input values and return a string.

- Advanced functions, which can process several field input values for each function call. You can import either all field values of a context or the whole queue for the field in an array before calling the function.

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

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.

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.

Example of an UDF :

This code will remove leading zeros. You can write you own UDF's like this.

public class test {

public static void main(String[] args) {

System.out.println(args[0].replaceAll("^0*",""));

}

}

Hope this will help you a lot.

Regards

Aashish Sinha

PS : reward points if helpful

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Bharath,

There is a notepad type icon on the left of functions which is for "create new fuction".click on dat. Then there will be options like queue,value context.

As per your requirements choose the appropriate option.Then also mention the number of arguments you require by clicking on the add icon.

Create the function.

You need to know simple fuctions of for,ifelse,break etc.As a suggestion whenever there is a context change it is identified by ResultList.CC.This is very useful when it comes to context changes.

It is not that difficult and even if you just know the basic java you can create the UDFs without much trouble.

Reward pionts if useful.

Thanks,

Sidhvin

Former Member
0 Kudos

Hi,

go through the following sap link.It takes you through the basics of mapping and also porvides information about various mapping techniques and how to go about it..

http://help.sap.com/saphelp_nw70/helpdata/en/6d/aadd3e6ecb1f39e10000000a114084/frameset.htm

Kindly reward with points if found helpful.

regards

madhu

Former Member
0 Kudos

Hi Bharath Nag ,

The following website contains Excellent document on UDF(from page 50..) which wil make u understand what is UDF:

SAP Exchange Infrastructure Mapping Functionality in XI

http://help.sap.com/bp_bpmv130/Documentation/Operation/MappingXI30.pdf

cheers!

gyanaraj

****Pls reward points if u find this helpful

Former Member
0 Kudos

Hi Bharath,

here you can find a few examples

Refer the below links for UDFs.....

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-0201-0010-84b6-9df523cb...

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

have a look at this also

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/be05e290-0201-0010-e997-b6e...

Regards,

Sarvesh

Former Member
0 Kudos

Hello Aashish and Sarvesh

Your answers is amazing, so many details, WOW.

I want to take this opportunity and suggest to create together public library of UDF.

Maybe can open new thread for that.

Elad

Former Member
0 Kudos

Hi Bharath,

To create UDFs, go to your message mapping, click on the Create New Function button on the bottom.

You need to have basic knowledge of Java for writing UDFs.

Regards,

Divija.

Give points if helpful