XSLT
Having made a web service work via ABAP has been only one part of what I’ve set out to do. The next step is to use XSLT transformations to parse incoming XML payloads. I’ve had some dealings with XML, but nothing like this before! The biggest issue is understanding the structure of the transformation coded in SAP, the ABAP program that is used to convert it into one or more tables and the actual XML payload. Needless to say, the payloads I’m dealing with are fairly complex and nested to the nth degree. Little wonder then that all initial attempts failed.
Some hints for those of you trying this out. There are many resources on the SAP SDN. As usual, not one of them will match a real-world case. Not in my case, at least! I’ve found it easiest to start defining the transformation and its associated target tables from the inside out. Keep your wits about you and remember that XML is case-sensitive. Contrary to popular belief, ID and Id are not the same. With a large XML document and many tags, it’s easy to foul one or more of them up. Syntactically, everything will look great. Except the ABAP won’t return any values to the table. A good XML editor and debugger is very useful. Altova XML Spy is good, but very expensive. I’m presently using oXygen, whose XSLT debugger is intuitive to use. A simple XML viewer is handy too.
The most frustrating part of the exercise is managing to make the relevant structures identical and provide identical names. So, for exampe the XML tag HEADER requires a variable named header. For each set of tags or data, a for-each select statement is needed. And don’t underestimate the need to declare a record type that matches the structure – if you forget the clause OCCURS 0 when defining types, the table within a table of that type will never receive any values. No amount of debugging will indicate where to look…