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():
Executing a test, results in the following:
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.
Create a variable to save the custid.
Create and use a simple user-function to save the value into custid.
The user-function can be used with the "root" element, as an "initializing section".
Create and use a simple user-function to copy the value saved in custid.
Note that there is no input parameter for the function.
Use the function to assign value to the target element.
This will produce same test result, but will use significantly less memory.