Skip to Content
In PI 7.0 and XI 3.0, one of the most often requested features (or complaints) is the capability (or lack of) to share user-defined functions (UDFs) across multiple message mappings. As a result, we often had to duplicate the code of frequently used UDFs to multiple message mappings.

This feature is now available with PI 7.1. The only restriction is that the library containing the UDFs has to be in the same Software Component Version (SWCV) as the message mapping. Therefore, if we wish to share the library in more than 1 SWCV, then we will need to create dependencies in the System Landscape Directory (SLD).

In this blog, I will discuss how to created and use UDFs that can be shared with multiple message mappings.

For demostration purposes, I will create a UDF to calculate the factorial of a number in a function library. Then, use this function library’s UDF in a message mapping.

Below is the simple procedure:

  1. Create a Library and an User-Define Function to be shared.

    A Function Library can be create in any namespace under a SWCV. The Function Library, then, can be referenced from any namespace under the SWCV.

    I am going to create a function library in the namespace, http://test.com/shared, called “myUdfLibrary”.

    Right-click on the namespace and select “New”:
    image

    Select “Function Library”, enter the name “myUdfLibrary”, and click on “Create”:
    image

    The following screen will appear. Then, follow the procedure below:

    1. Click on the “+” in “Functions and Java Area”.
    2. Enter the function name, “ComputeFactorial”.
    3. Enter “ComputeFactorial” as the Title.
    4. Enter the java code.
    5. Save and Activate.

    image

  2. Use the User-Defined Function in the Function Library.

    Here, we are just going to do a simple one-to-one mapping, and use the UDF to compute the factorial. But, first, we will have to reference the function library.

    Click on the new icon “Show Used Function Libraries”, as below:
    image

    With the following screen.

    1. Click on the “+” in “Used Function Libraries”.
    2. Click on the “down arrow” to select the function library from the value list.

    image

    Select the function library and click “Apply”:
    image

    Now, we can select the function library, “myUdfLibrary”, from the Message Mapping:
    image

    Now, we can use the UDF, “ComputeFactorial”, just as though we had developed it in the message mapping locally.
    image

    When testing it, we get the following:
    image

To report this post you need to login first.

9 Comments

You must be Logged on to comment or reply to a post.

  1. Chris Williar
    Great Blog. This feature was definitely needed. Could you explain a little bit about sharing the library across multiple SWCVs, as you mentioned in the blog – “if we wish to share the library in more than 1 SWCV, then we will need to create dependencies in the System Landscape Directory (SLD)”.

    Thanks!

    (0) 
    1. William Li Post author
      Hi,
      The how-to and advantages of using dependencies can be an article by itself.  Anyway, in a nutshell, by creating a dependency in the SLD of one SWCV to another allows the 1 SWCV to see all the objects, as its own, of another SWCV.  This is applicable in the case here, when common libraries can be shared.  In other cases, meta data from IDOCs and RFCs can be stored in one SWCV and shared by other SWCVs, so that imports of those meta data will be centralized in one location, instead of spreading (and duplicated) across the Repository.  You can also centralize commonly used message types and data types in one SWCV to allow better maintenace and administration.  Dependencies can also be used for versioning, e.g. when you have completed release 1 of your development, you can create a release 2 SWCV with a dependency to release1.  This way release 2 will continue to use the objects from release 1 except for those you have modified.

      You can get more information on this in the following link (Enterprise Services Enhancement Guide):
      https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c0bb5687-00b2-2a10-ed8f-c9af69942e5d

      Regards,
      Bill

      (0) 
  2. Nirmal kumar V

    Hi Experts,

    How to do UDF for single values, all values of a context and all values of a queue in this global method.  I dont see these being set anywhere.

    (0) 

Leave a Reply