XSL and ABAP
I’ve seen some complaints lately that there isn’t enough about ABAP around here. Now my ABAP might be a little rusty but I can still remember a thing or two, so let’s start talking about it.
If you do care about ABAP its likely that you also care about moving data between systems. What you might not realize is that as of release 6.20 you can map external data in XML format to ABAP data structures using XSLT. From good old SE80 select the context menu from the root of your object tree and choose Create -> More… -> XSL Transform and you’ll get a dialog to Create XSL Program. This is where you should enter your xsl.
Well what would you put here? Well you are probably looking to map from an external xml schema to an internal data structure so type mappings would help. Look up the reference on ABAP data serialization at ifr.sap.com.
To apply your transform use CALL_TRANSFORMATION giving it the name of your XSL program, your xml source and a variable to hold the result. Such as:
CALL TRANSFORMATION
xslprogram
SOURCE XML
xmlfile
RESULT
NAME = var
Specifying XML after source indicates a transform into an ABAP data structure. XML before source would indicate that the result will be XML. NAME in this example is the element name that wraps the XML representation of the ABAP data in the XSL.
Now the above is omitting quite a bit of detail but hopefully gives you the idea that you can do this and some pointers to get started. Don’t forget to read the help files. Of course the real credit goes to a wonderful article on this topic, “From XML to ABAP Data Structures and Back” from the July/August 2002 issue of the SAP Professional Journal.
Please note that the IFR link relates to earlier, weaker mechanisms (which use, however, a mostly similar XML format). The SDIXML* functions are outdated and should not be used in 6.** systems. Also, XRFC and the BC are unrelated to CALL TRANSFORMATION.
The easiest way to find out how the XML representation of a particular data structure looks like is as follows: Populate the data structure with typical values and invoke the identity "id" (part of the basis delivery):
CALL TRANSFORMATION id
SOURCE root = my_data_structure
RESULT XML my_xml_string.
The resulting XML document shows what source format your ABAP-to-XML XSLT program (to be used in place of "id") must expect, and what result format your XML-to-ABAP XSLT program must produce.
As soon as we find time, we will provide more detail on this topic in SDN.
Best regards,
Karsten Bohlmann (SAP TechDev / XML technology)
Best regards,
Stefan Schumacher
Article.
It answers most questions on the XSLT/ABAP topic, including the previous one.
Thanks,
Mark Browne.