Skip to Content

Newcomers guide to reading XML with ABAP

Let me share an experience. I was challenged with a task to read huge XML into ABAP and use it for mass upload of some information. It was not my first time with XML in ABAP, I am regularly using CALL TRANSFORMATION to generate formatted Excel files (I don`t want to import ABAP2XSLX, what would be the first option to produce nicely formatted outputs to Excel, into my customers` systems. Can you tell me how you use ABAP2XSLX not being a customer?). But it was my first time to upload into ABAP.

Side note: If you don`t know the ABAP2XSLX project, check abap2xslx Code Exchange homepage here. If you want to start with a fancy video introduction of the project, check the blog by Rui Nogueira here. If you don`t want to import Z-code into your or your customer`s system and would like to know more about my transformation way of exporting to Excel, check my blog which describes it here: Happy reporting with Excel II.

So back to the topic: you have an XML file you`re supposed to read into ABAP structures and tables and you don`t know where to start. One could use a wizard to help with the task, right? Fortunately there is such a thing. Look for the magic wand icon in the transformation screen in SE80 (or alternately go to XSLT_TOOL transaction, open or create a transformation and go from there). Note that this blog is about SIMPLE TRANSFORMATIONs, not about XSLT programs (your transformation object in SE80 or XSLT_TOOL must be of type simple transformation).

XSLT_TOOL wizard

What you see here are two panes: left for data structures in ABAP and right for the XML tags in the file. First thing you`re supposed to do is to specify a root. Ugh? Root? What is that?

You need to have ABAP dictionary structures and tables defined which will hold the information after you read it from the XML file. These you have to create manually. So before you start using the XML wizard, I suggest you start creating your structures in SE11 or SE80. Combine the data dictionary objects into a tree, that will approximately look like the XML file you`re going to read into it. The more it “emulates” the input file the better. Natural, no special description needed.

Now let me explain why I suggest the use of the XML tool. Those informed about CALL TRANSFORMATION know there is the “standard” transformation called “id”. “Id” stands for “identity” here. That means that the XML file content and the DDIC structures fit together 100%. With my task that was not the case.

Parts of XML dealing with similar things were “implemented” differently, some nodes had attributes, some didn`t, some elements were obligatory, some not. I didn`t have XSD, I didn`t have any other information except the “example file”. When you want to use the “identity” transformation, you anyway need to create your DDIC structures, so this part stays with both options. To make it as clear as possible: this blog helps you with mapping the XML nodes to DDIC structures.

Let`s assume you have your structure created in ABAP dictionary now and want to create a mapping. You now have a structure you can use as the new root in XSLT_TOOL (right mouse click on the left pane > Insert New Root > provide root name and type you created as the “main/ top-level” type). Left pane gets populated according to your structure defined. You don`t have a thing on the right side yet.

It`s a mapping. Have you ever used attributes mapping in WebDynpro for example? Drag and drop works. So you drag the root from the left pane and drop it on the right. Now the program creates what I mentioned above as “identity” transformation. It created a “program” that would read the XML file where every tag is called the same as your DDIC type. But as I said: ours is not the case. We need to be able to change the names of the tags (and other “attributes”) so the transformation fits on our XML. To do that double-click the node on the right and you can change its name.

Another typical task is to map your ABAP field to an attribute of a XML tag rather than to its value. Then you need to right click on the node and say: “Change to Attribute”.


Not a replacement for a documentation, but a shortcut for sure

You might be asking yourself why I explain something that can be read in the documentation. Easy: I had to learn the hard way despite the existence of the documentation. I also realized that I need less that 5% of the available features. So if I went and read the whole documentation, I would spend a week reading about cloud castles, something that can be very tricky to imagine. With this blog I am hoping to spare the Community the time and effort of reading through everything plus… I want to add some “typical needs”.

Typical problem: You use the wizard, save, activate and when want to start the wizard again or activate again, you get a success (???) message saying “Namespace prefix “” is not defined”. Then you need to go to the source code tab of the transformation and note that there are two similar, but somewhat strange lines at the beginning. You need to delete the second line (with extra space before the question mark) to make the thing work again.


Typical wish will also be the need to mark some nodes optional. Here I admit I didn`t find a way how to do it via the wizard (it must be possible, I just didn`t have enough time to look for it). So I went to the transformation source code tab and change the thing there.

The code goes like this: (if there is something to be bound to the node, process it, and otherwise carry on; note that you have to “process” every tag that appears in the XML input stream, which means if you don`t care, ok, but you have to process it too).


            <tt:cond check=”exist($REF.XX.YY)”>

            < MyTagB >

              <tt:loop ref=”$REF.XX.YY”>

<!– process the lines if there are any –>





And that is enough for you to process complex XML files into ABAP. At least it was enough for me. Happy XML parsing.

Cheers Otto

You must be Logged on to comment or reply to a post.
  • Indeed, a useful approach trying to compress everything into a DDIC-Structure beforehand, if possible. The wizard looks fun too, albeit I cannot judge its usefulness since I only developed XML-Structures which needed XSLT since the ST-Format simply doesn’t allow for enough flexibility.

    What I really miss, is a useful coding editor with at least text highlighting 😏 . When coding an XSLT (no graphical Wizard available like in ST) without having XML-Spy or the like at hand, you’ll just want to bite somebody in the face at some point 😛

  • I use the IF_IXML interface to deal with XML files. Somehow don’t trust either XSLT or ST 😛 Debugging is helluva pain as well!

    Just a suggestion 🙂 In addition to mentioning the wizard is applicable for ST programs, you can also mention that this feature(read: wizard) is available from ABAP Release > 7.0



    PS: I’ve checked on Release 640(Patch level 24) and this feature is not available.

  • Hi Otto, Thanks for sharing. I have below query.

    I need to send out xml to other system. Here, i have “userid” as attribute and name as element.

    My requirement is to have “id”(employee id) as attribute, but i cant change in XSLT_TOOL (gives error “Attributes must not occur after Elements”).

    Any other way to achieve this. Appreciate your help.


                <staff userid=””>


                            <employee id=””></employee>    “>>>> need to be same as “userid”





    • Hi saslove,

      long time no see. I love the spirit of your comment. The positive energy that you radiate. How you motivate people and share your knowledge 😉

      Now seriously. I am not saying this is perfect and at the time of writing the blog I didn’t know anything better (maybe I don’t know anything better even now). If you know better, you’re welcome to write a blog to share it with the others. You’re also welcome to link my blog as a negative example and you can use it to explain why and how is your approach better. But do something useful FIRST, ok? 😉

      See you around.

      Cheers Otto

      • well I am seriously stayed out of this SCN because of its new version which is horrible to get updates for my self comments until I found this link again 🙂 ….I really missed the old SDN and friends too ///

        On the other note I thought you know the way without SE11 .its as simple we create the structure in the abap as structure and we have to pass to CALL Transformation This structure which will reduce the pain on unncessary STRUCTURE created in SE11 .

        Instead of creating another blog you can improvize the single blog with stating 2 diff ways of mapping.

      • The below reply I have intend taking your comments in negative 😉 but taking it in a funny manner you are strained alot to create a post of which you have no idea is damn good job dude…if you dont know either you should have gathered infromation from gurus or even you tried to keep on looking for improvments like what thomas jung does ….replying answers in the threads…I hope this answers your questions & please dont rate me and harm me again…  🙂 Good luck

  • Hi

    I wanted to contribute with a little example in case there is a field (and not a structure/table) which is optional. The wizard generates usually a line looking as follows

       <Remarks tt:value-ref=”REMARKS”>

    if the field REMARKS doesn’t always appear in the XML to be transformed to ABAP, you could add a condition to this line:

      <tt:cond check=”exist(REMARKS)”>

       <Remarks tt:value-ref=”REMARKS”>


    in my case this solved my problem…