Skip to Content

XML processing in ABAP Part 4


I proposed a TechEd-talk about XML programming in ABAP with focus on dealing with generic XML frameworks and huge XML documents. In this issue of my blog I present an outlook to topics of my proposed talk: iXML best practices and tips for ST programming as well as a comparison of different XML APIs.

Comparison of XML APIs

Beside Simple Transformation (in short ST) there are more APIs for XML transformation: iXML library and XSLT.  I think now it’s the time to write about some of my personal experiences with these APIs and the power of combination of used techniques. 

Simple Transformations

Perhaps you are a little bit afraid to use ST in your programs but I hope this weblog can convince you that ST programming isn’t that difficult. If you didn’t read the previous issues let me show a small example that assigns the value of an element <A> to an ABAP variable referenced by ROOT. During serialization we create that element with the value given by ROOT:

If you want to start with ST I suggest to study the examples SSTDEMO_BOOKING, SSTDEMO_BOOKINGS, SSTDEMO_FLIGHTS and the report STRANSDEMO on your SAP system. SAP library offers a complete  description of ST. And perhaps the last issues of my blog can help if you should have some problems with basic conditions and namespaces.

I’m convinced that these examples will enable you to write your own ST programs. Of course there are more ST commands and some of them I want to discuss in further issues of this blog: mapping, modularization, variables, parameters and so on.

If you look at the program above you can imagine that ST programs can be very fast: consider deserialization,  the XML input can be read in stream order with lookahead 1 during parsing, the rest consists of matching expressions and copying values to data nodes resp. variables.

As a rule of thumb you can’t assume that your XML data model ought to match to your application’s data structure. In every case you will  \ have to invest further work in ST as well as in any other technique. So don’t be disappointed that the expressive power of ST (see this weblog for example)


XSLT is a functional programming language in XML syntax. It should be your choice if you want to transform XML documents into general (unicode) byte streams: just think of XML HTML documents or even source code. You will find lots of books about XSLT programming. I guess you already know the book “ABAP fortgeschrittene Techniken und Tools” and you are familiar with asXML used for ABAP integration – if you don’t, I suggest to order this book right now. XSLT is Turing complete and offers ABAP and even Java enhancement. These are the good news.

But there are disadvantages: XSLT is hard to maintain and not every programmer is familiar with functional programming style. Mixing a functional programming language with a procedural programming language like ABAP or Java offers \ new possibilities to SAP itegration  but usually creates code that is hard to maintain.

Nearly all processors need lots of ressources because they build up the complete DOM tree from a document. If you are involved in data exchange using XML technologies I guess you will make two experiences very soon: at first the expressive power of W3C XML schema is limited, you can’t describe arithmetic constraints for instance. Therefore you will start to define programs that check those constraints using XSLT. For small documents this will work fine but for mass data it’s too slow in my opinion. But it’s the right choice for difficult conversions, HTML and code generation etc.

iXML Library

iXML offers two APIs for XML processing: a superset of DOM 1.0 and an event-based parser. An event-based parser is pushing events to a consumer. It is fast, memory efficient and available in every SAP release. So there may be good reasons to use it.

Best practices for iXML programming

One part of my proposed talk at SAP TechEd will be discussion best practices for reusable, maintainable and  efficient ABAP code for XML processing using iXML library.

Wrapping iXML events

SAX, the Simple API for XML (see for example) offers a class DefaultHandler for XML deserialization. The programmer has to extend this class and implements following methodes in Java:

  • public void startElement (String uri, String local, String qName, Attributes atts)
  • public void endElement (String uri, String local, String qName)
  • public void characters (char buf [], int offset, int length)

I will present and discuss ABAP OO wrappers for the if_ixml_event interface of iXML library.

Datastore components

Datastore components are software modules that offer access to data. They can be used as a cache to grant fast access in GUI programming as well as in data exchange. I discuss implementations suitable to store data that are read while stream-based processing.

You can use datastore components to implement fast checks on data quality that can’t be done with W3C XML schema (think of arithmetical calculations for example).  Even if you decide to rewrite your iXML using ST programming you’ll still need to transform your data to the desired relational data model and perhaps you want to test the data quality. I want to discuss how to reuse your old datastore components.

If you are confronted with reused schemas in generic XML frameworks composition and encapsulation of different datastore components will offer you possibilities to reuse your code.

Rule based frameworks for event processing

An important advantage of Simple Transformation is that you have a simple method for mapping ABAP variables  to XML resp. vice versa. If you use iXML you have to code this mapping on your own. I want to discuss best practices for implementing datastore components using generic and rule based programming.

Modular Simple Transformations – modular datastore components

Adding ST commands to an existing XML document will produce an ST program in a sloppy way. If we define corresponding ABAP data structures we can do serialization and deserialization. Unfortunately those programs are not modular and as consequence not reusable, because in general we deal with generic XML frameworks. Those use 

  • type libraries,
  • standardized elements (like headers),
  • that sometimes are complex types inherited using extension or restriction.

I want to show how to create modular transformations and modular ABAP code to support reuse. In further issues of this blog I will introduce ST modularization techniques we need for this task.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.