Blogs

Daniel Graversen

SAP PI XML Mappings using groovy
Daniel Graversen
Business Card
Company: Figaf ApS
Posted on Jul. 03, 2009 05:12 AM in Ruby, SAP Process Integration (PI), Scripting Languages

Subscribe.Subscribe
Print. Print
Permalink Permalink

Creating XML mapping in Java have for me always been difficult, it has been possible but I would prefer other tools. An example on how to create XML in java with dom is created by Madan Agrawal. I was looking at scripting languages like Ruby/JRuby or Groovy for creating some web apps. Those languages seem quite hot right now. On the SCN Wiki a group has implemented the Grails (groovy on Rails) on the Netweaver system, as Composition on Grails. With this tool it is possible to applications with a Webdynpro look and feel. Grails is a framework for creating webapps with less coding.

 

Groovy is a scripting language designed on the basis of Java. Groovy script is compiled into Java classes, and both Java and Groovy can be mixed. This makes the implementation easier, just start writing Java and when you feel like use some of the smarter features of Groovy you can use them.

While I was looking at Grails, I thought that I would be possible to use it in PI. One place could be in java mappings. I'll describe the steps that I have taken to implement this.

  1. Download and install the groovy library
  2. Get the Groovy plugin to Eclipse, this make developing much easier.
  3. Create a new Eclipse project
  4. Insert the aii_map_api.jar in the project, to be able to implement Streamtransformation service.
  5. Create a new Groovy file in the source folder, with the name GroovyMapIdoc.groovy, then Eclipse know that it is a groovy file.
  6. Create the mapping of your file. I have attached my example code bellow.
  7. Compile the Groovy files using the context menu on the GroovyMapIdoc.groovy file.
  8. Zip the content of the bin-groovy in the project folder and upload it, as an imported archive in the Integration builder. Alternative use ant build to create the zip files.
  9. Upload the two files Groovy-1.6.1.jar and asm-2.2.3.jar as imported archives. They can be found in <GROOVY_HOME>\lib
  10. Activate and use the mapping.

I would expect people trying this to have a good knowledge of using XI or PI Java mappings, because it is a requirement for the development of mappings.

One example I always have considered, was my first challenging mapping experience. Posting financial post with more than 1000 lines to the FIDCCP02 idoc. The FIDCCP02 only accepts 999 lines. The posting can be created multiply idocs with 998 lines and the post a balance on each item. This way all documents will balance.

The document is transformed from the left document to the right. I have for this example used a max size of 3 to make testing easier.

image image

 

The code that I have used for the mapping is.

 

Behind the scenes the Groovy file is changed in to java classes. Because Java does not support Closures natively different subclasses are created. Try to have a look on them using a decompiler like jad. The imported archive look like the following.

image

Conclusion

Groovy could be a way to improve the how java mappings are created. The XML generation is easier to handle then how it would have been created in Java and it is more powerful than XSLT. It takes some effort to get use to the closures concept of Groovy and the other notation, but it seems to work real well.

I don't think the performance issue with the mapping is a problem. There is an overhead to load the groovy libraries and the code is probably not as optimized if it was written directly in java. I have not made any measurements for this.

 

 

Daniel Graversen is founder of figaf.com and PI hacker/consultant. He has developed the PI documentation tool. He is founder of Masteringwave, which experiments with Enterprise applications and Google Wave.


Add to: del.icio.us | Digg | Reddit


Comment on this articleIs this useful and would you like to see more the same.
Comment on this weblog
Showing messages 1 through 3 of 3.

Titles Only Main Topics Newest First

  • Great!
    2009-07-03 05:52:06 Paolo Romano Business Card [Reply]

    Love this, thanks for such a wonderful (and really useful) blog.


    Regards,
    Paolo

  • Really useful information but,
    2009-07-10 04:08:28 Volker Janzen Business Card [Reply]

    which PI version do you use? In my interface mapping tests i get always a linkage error:



    java.lang.UnsupportedClassVersionError: groovy/lang/GroovyObject



    If i use older versions of groovy there is an error of type "CustomMetaClassCreationHandle.class not found".



    Regards,
    Volker


Showing messages 1 through 3 of 3.