How to convert xml to ABAP data?
I need to write a transformation and convert an XML file into ABAP data.
The XML looks like following:
I have no knowledge in transformation. Can some one help me on this or provide deatail guideline on the conversion of XML to ABAP data.
Thanks in advance,
Best Regards, Johnney.
Rainer Lindemann replied
It's actually not that difficult. For that little XML of yours, I would suggest a Simple Transformation, because it's . simple. And fast.
You should do some reading in the online documentation, and then it's trial-and-error. To accelerate your trialling, I've prepared a little example for you. Which you can use as follows.
Call SE80, and go Workbench > Edit object. , and create a "Transformation" (you give it a suitable name, and click on the "Create" button; in the pop-up, you specify Transformation type = "Simple transformation").
In the source code, you replace everything between "<tt:transform>" and "</tt:transform>" with the following bit of code:
Your simple transformation is ready; all you have to do is call it from a little program, more or less as follows:
The variables starting with "l_" should be character fields of appropriate length, or character strings, while "lt_arguments" should be a standard table with a single field called "ARGUMENT" (otherwise you'd have to change the name in the transformation, in the line that says "<tt:value ref="$Arguments.ARGUMENT"/>").
There's more pitfalls for you, like the encoding of the XML string, but you'll find examples of how to handle that if you look for class CL_ABAP_CONV_IN_CE, either here in the forum or in your system (or in the online help, of course).
Oh, and you should definitely catch and handle CX_ST_ERROR - transformations dump easily if something is wrong with the data.
Hope this helps - sure took longer than planned.