Create XML Files XSD-compliant exploiting SPROXY functionalities and XSLT transformation
In large enterprise environments, it happens more and more frequently to deal with XML files for a large variety of purposes. I won’t list here the benefits of this self-explanatory files, since there are already many blogs around talking about this.
Speaking about concrete cases, in recent times SEPA pain formats within EU payment gave a huge boost into the adoption of XML for communication between partners and authorities. For them, the recommended technology to use, often with pre-build templates like CGI_XML_CT, are DMEE trees.
But what about other formats that are not related to payments or for which we cannot use the ‘new’ Payment Medium Workbench? It may happens that what we get is simply an XSD and we’d need to carefully adhere to it to produce a file. XSD normally are complex (to adapt to different situations) and strict (to minimize the errors at the destination), so building a file manually is definitely not recommended.
Investigating the possibilities within our ECC 6.05 environment, we targeted three possibilities:
– DOM/SAX technology to build in memory the tree and then render it into an output stream via iXML classes
– passing through SAP PI via an ABAP Proxy
– use SPROXY to automatically load the XSD into the system and generate the ABAP structures, as well as the XSLT transformation to be used in our program
In this BLOG, I will focus on the third option, since DOM/SAX technology require lots of custom code and the usage of PI may not be possible for all customers because:
– direct connection to the external partner is not possible/convenient
– we don’t want to introduce an additional point of failure (PI is down, I cannot produce my file?)
– or simply we would like to give back the file to the user immediately for manual processing
Following are the main steps to achieve the result:
- load the External Definition of the XSD on SAP PI and create an Outbound Service Interface in PI, using the new External Definition
- VARIANT: transform the XSD into a WSDL and then load the WSDL into SAP via SOAMANAGER. For this there are many solution available online or you can try the ABAP report SPROX_XSD2WSDL. One BLOG for ALL: https://scn.sap.com/community/pi-and-soa-middleware/blog/2012/10/24/creating-a-service-consumer-proxy.
- Generate the proxy in SPROXY on the backend
All ABAP structure are automatically generated inside the system:
- Take the generate XSLT transformation name and use it in your program to pass from the (automatically generated) ABAP structures to the XML
- OPTIONAL: Fine tune the parameters of the proxy to be compliant with your external partner specifications
In case XSD is changed, you’ll just need to re-upload it into PI (or SOAMANAGER), regenerate the proxy and adjust your ABAP code to fill out new fields.
That’s all Folks ????