skip to Main Content

Dev Tip: Use the Simple Transformation Tool to Create XML

To sign up and get your dev tips delivered to your inbox each week, click here!

Tip of the Week

Use the Simple Transformation Tool to Create XML

I was recently pulled into a Fiori project that involved sending XML files from the application to a backend system via the SAP Gateway.  When I looked at the service, I found that the other developer was manually creating the XML files via string concatenations.  I realized that they must not know about the built-in XML translation tool that SAP provides.

The tool itself is really powerful and usable for many different things (including a few unintended uses… but in good ways!).  Today’s dev tip is a simple scenario – I hope you find it useful!

Here’s the scenario.  I have a deep structure that contains an employee, each employee has one or more contacts, and each contact has one or more phone numbers.

With these data structures set up, we can easily create a simple XML transformation.  Please note that it is not a requirement to create structures to do the transformation, but for the purposes of this example, it’s just easier.  Navigate to transaction code STRANS.Name your transformation and click Create.
Click on the Edit Simple Transformation Graphically button. You can create the transformation manually, but this guided approach will be your friend.
Delete the ROOT node, then click on the menu to Edit -> New Root
Note:  ZMBHEADER is the name of my employee-level structure above.
After you expand each of the nodes, you can see your full hierarchical structure come to life!
Drag the ROOT node over to the right side (Simple Transformation)
Save and activate.The transformation is done!  Now to test it!

I wrote some simple ABAP to fill the fields of the various structures.  For the sake of saving some space, I won’t highlight that code here.  Here’s the statement to create the XML.

A little break-down of this statement.  “ROOT” was the name of my root node, “LV_HEADER” is the name of my local data structure that matches my root node, and “LV_XML” is a string variable.

Let’s run this and see the results!
Note: I drilled into the variable / XML Browser view to get here.

Pretty cool, eh?

You can also use the transformation tool to go from XML to internal format.  The transformation is the same, but the ABAP command changes slightly.

No big shocker – the source becomes XML and the result is your internal data structure.

As I eluded to before, there’s so much more you can do with this transformation tool.  It can be used to serialize and de-serialize JSONs.  I’ve used it to create on-the-fly HTML output.  This little tip can get you started – I’m excited to see what uses my fellow developers can come up with next!

 

 

If you have an interest in viewing similar content, visit our blog, here

View our LinkedIn, here

Mike Berg is a Senior SAP Developer at Mindset. He leverages his 18+ years of experience across various SAP technologies and functional areas to bring optimal solutions for customers to light. Mike focuses on bringing the best user experience possible to users, which in turn maximizes ROI for the organization. He does this by emphasizing the correct technology, be it Fiori, Personas, or other, and by optimizing application performance and ease-of-use. Mike is a regular contributor to Mindset’s blog and development tips newsletter, as well as a speaker at SAP Sapphire and ASUG events.

Back To Top