Simple XML Processing in ABAP Part IV. – Create Framework Program to Process XML Files



Main responsibilities

We did a great job with the Simple Transformations, so from now on we are ready to call it from the framework program. To make it simpler, first I am going to introduce the main responsibilities of the framework program: first let's upload the content of the XML file, then parse this content into an SAP internal format, and at last insert the parsed data into the database. I like to write transparent codes, so we are going to use subroutines to separate these different responsibilities, and keep our code readable. We are going to construct three subroutines, namely UPLOAD_XML, PARSE_XML, and INSERT_INTO_DATABASE.


Global declarations

Above in the code, we used two variables that we haven't declared yet: the CUSTOMERS_XML, and the CUSTOMERS. The CUSTOMERS will contain the customers, so it's going to be an internal table with our previously created table type, ZCUSTOMER_TT.

The CUSTOMERS_XML will hold the content of the XML document in a flat string format. We need to provide the content of the XML document in this format, since the Simple Transformation requires the input in flat string format.


Upload the content of the XML document

We have a sample XML document in the root of C drive, called customers.xml. Our first task is to upload the content of this XML, using the standard function module, GUI_UPLOAD with a file path and a result table parameter.

The GUI_UPLOAD will read the content of the XML line-by-line, and save them into an internal table. So, after we get the XML content in the internal table, XML_CONTENT_TABLE, we have to make some preparation to fulfill the requirements of the Simple Transformation. We are going to loop through on the internal table, and in each iteration, we are going concatenate the actual line into the flat string, CUSTOMERS_XML, so as a result we get a long, flat string with the content of the XML.


Parsing the XML content

As we get the content in flat string format, we are going to call our Simple Transformation, called ZCUSTOMER_ST, and send the flat string as an input parameter. The simple transformation will use the transformation logic that we have implemented, and produce a list of customers that we get back in the internal table, called CUSTOMERS.


Insert the parsed data into the database

As a last step, we are going to insert the received parsed data into the database, using simply the INSERT...FROM TABLE statement.


Result

After running the framework program, we got the following records in the database. That's it, we are ready! From now on, you are able to process XML files easily in ABAP using Simple Transformations.


Source Code

Here, you can get the complete source code:


Table of Contents

  1. Part I. – Overview
  2. Part II. – Create ABAP Dictionary Objects
  3. Part III. – Create Simple Transformation to Parse XML Content
  4. Part IV. – Create Framework Program to Process XML Files
  5. Part V. – Processing XML Attributes


If you have any further question or you want share your experiences, please don’t hesitate to leave me a comment, and I am going to answer it as soon as possible.
blog comments powered by Disqus