Skip to Content
Purpose

Typically there are 3 issues we face in legacy-legacy integration with interfaces

1) Creating Hierarchical structure for Target

2) Using Multimapping to split source XML into multiple target XML structures and thereon into multiple files

3) Handling the target filenames based on Sourcefilename, or value in the source payload structure.

This weblogs talks about how we can use XSL mapping with calls to Java code to resolve these 3 issues through a simple scenario

The approach

Let suppose the source structure is

image

and target is

image

Target Message Structure

How do we make the simple flat structure into a hierarchy and multimap every Header record into a new IDOC XML message in the target.
Note: The filename column is to be used in fetching the srcf filename, which will be done by calling a Java function.

image

For hierarchical split

XSL provides +following-sibling + axis which can be used to check the next tag in the source within the same context and create the ‘detail’ hierarchy in the target as shown below by calling the ‘generateDetails’ template.

For a Multimap split

tag in message header.For more details visit The specified item was not found.which details it lucidly.

As mentioned in the XSLT mapping documentation,create a Java class, let’s name it say FileNamingClass with a function GetFileName to get the source fileName.
Note: Make sure the function GetFileName returns a ‘static’ value or else you will be having a nightmare debugging the XSL call to the Java function.

Java Code for the FileName call

package Wipro;

import com.sap.aii.mapping.api.DynamicConfiguration;

import com.sap.aii.mapping.api.DynamicConfigurationKey;

import com.sap.aii.mapping.api.AbstractTrace;

import com.sap.aii.mapping.api.StreamTransformationConstants;

import java.util.Map;   

/**

  • @author

Sriram Vasudevan

Purpose : for Testing FileName retrieval using a Java Class

Version : 1.1

*/

public class FileNamingClass

{

    private static AbstractTrace trace = null;

    /** Creates a new instance of Main */

    public static String GetFileName(Map inputparam) 

    {

        DynamicConfiguration conf = (DynamicConfiguration)inputparam.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

        DynamicConfigurationKey key = DynamicConfigurationKey.create(“http://sap.com/xi/XI/System/File“,”FileName”);

        String ourSourceFileName = conf.get(key);

        

        trace = (AbstractTrace)inputparam.get(StreamTransformationConstants.MAPPING_TRACE );

        trace.addInfo(“GetFileName():
DConfig = ” + conf + ”
Key = ” + key + ”
FileName = ” + ourSourceFileName );

        return ourSourceFileName; 

    }

}

To Call this piece of Java code, use this function call javamap:GetFileName($inputparam) from xsl:value-of tag within ‘FileName’ tag of the target…

Note:

‘javamap’ is just a namespace definition in the XSL pointing to the Java class, it can be any other text.
$inputparam is an input parameter used to pass the config params from XI to the Java function call.

The entire XSL code used in this example is given below

<!……………………………….Program Details……………………………………………………………………..>

                    <xsl:variable name=”checkNext” select=”$nodeName/following-sibling::*“/>

                    

               <xsl:variable name=”checkNext” select=”$nodeName/following-sibling::*“/>

               

Also make sure while using variable substitution in your receiver adapter, you either append a timestamp or some sort of unique numbering to avoid errors,as I am sure you would very well know we cant create files with same srcfilename in the target directory 😉

TargetDirectory with split files using the source filenames appended with Timestamp

!https://weblogs.sdn.sap.com/weblogs/images/36050/output.jpg|height=262|alt=image|width=569|src=https://weblogs.sdn.sap.com/weblogs/images/36050/output.jpg|border=0!

Enjoy..

Conclusion

This example shows how XSL can be effectively used to cutdown complexities and effort involved with other mapping methods, in scenarios involving multimappings, hierarchies etc.Offcourse effective knowledge of use of editors like XMLspy would be a prerequisite to reduce effort and make life easier during development.But that just involves a few hours of fumbling around with the environment to get things working.

 

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply