In the previous post, I have already introduced a high-level development workflow, so now there is nothing left then perform the first step, namely creating the ABAP Dictionary objects.
Basic Building Blocks
To create these ABAP Dictionary objects, we need some basic building blocks like Domains and Data Elements. If you want to learn more about Domains and Data Elements, check out my latest post, called How to build flexible, consistent, and centralized database in SAP via Domains and Data Elements.
To make it easier, I have already collected the domains and data elements for you that I am going to use during the demonstration (I used similar names like in the received XML file). On the right side, I listed the different domains with their id, type, and length that you have to create. On the left side, I listed the different data elements with their id, and the referenced domain that you have to create. The MANDT data element, and domain are already exist in the system, so you don’t have to create them. Now, it’s your turn, let’s create these objects!
Create the Structure
Our next task is to create a simple structure in the ABAP Dictionary that we are going to name it as ZCUSTOMER_STR. With this structure, we define the structure of the XML document, so as you can see we use the table fields such as CUSTOMER_ID, FIRST_NAME, LAST_NAME, and so on. Here, I would like to mention that I highly recommend you to create and use domains and data elements instead of ABAP built-in types to push lower the further maintenance costs. At last, let’s save and activate it!
Create the Table Type
Now, we have the structure, and the following task is to wrap it into a table type, called ZCUSTOMER_TT that will help us to create an XML Simple Transformation in an easy way. To create a table type is very easy, only we have to set the line type, which is going to be the previously prepared structure, ZCUSTOMER_STR. As you could see, the XML file contains the same structure in several times (<CUSTOMER></CUSTOMER>), so we have to use this table type, because we will store the same structure of the data in many times in an internal table. At last, let’s save and activate it!
Create the Database Table
We were asked to store the data of the XML document in a database table, in our SAP ERP system. So, our next task is to create a database table in the ABAP Dictionary. As I said before, if we use domains and data elements instead of ABAP built-in types we can save a lots of time with maintenance tasks, so we are going to reuse the same data elements again that we used the previously constructed structure. Only one thing differs, here we have to set the key fields, the MANDT and the CUSTOMER_ID.