Skip to Content
The function useOneAsMany() is used when a field that only occurs once needs to be replicated as often as another field occurs in the outbound message.

For example, in the source XML document, there is 1 header segment and many detail segments. We want to create an output XML document of just as many detail segments, but included in each detail segment is an element from the header segment. This means that the 1 header element will have to be mapped to every detail segment in the target XML document.

The function useOneAsMany() is used for this purpose. However, this function can be very memory intensive when there is a large number of occurences of the detail segment. As a matter of fact, J2EE memory exception can occur when the occurences are extremely large, especially when the OS is a Windows 32-bit system. Such an error situation actually occurred in one of our interfaces where the number of details approached 100000.

Here is an example of using the function useOneAsMany():

image

Executing a test, results in the following:

image

The reason large amount of memory is used is because the “context” of the element, orderid, is used, which will allocated a large array in memory.

To get around this problem and to actually simplify the mapping, we can use global memory instead. Global memory configuration is an enhancement with SP14, but similar capability can also be achieved using the global container object.

  1. Create a variable to save the custid.

    image

  2. Create and use a simple user-function to save the value into custid.
    image
    The user-function can be used with the “root” element, as an “initializing section”.
    image
  3. Create and use a simple user-function to copy the value saved in custid.
    image
    Note that there is no input parameter for the function.
    Use the function to assign value to the target element.
    image
    This will produce same test result, but will use significantly less memory.
To report this post you need to login first.

2 Comments

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

  1. Praveen Sirupa
    In the example, the src message has got only one occurrence of Header. The recommended approach is a sensible one and avoids bottlenecks.

    But, when you have the header kind of node with multiple occurrences, can we do away with useOneAsMany? For eg..take the case of the example which is explained in the documentation of useOneAsMany.

    (0) 
    1. William Li Post author
      Yes.

      You can create more “global variables”, e.g. name and address.  Then, in the “initialization” user-function, add the corresponding elements to the input parameters of the user-function.  And, in the mapping, you can use those global variables to assign to other target elements.

      Regards, Bill

      (0) 

Leave a Reply