Creating an XML Format Mapping in “Map Format Data” Application
In this blog, you will learn how to define a simple XML format in incoming direction with Map Format Data app. You will be able to define the file structure, specify repetitions, output and define action nodes.
You can use the acquired knowledge, for example, when modifying CAMT.053 in the Map Format Data for Incoming Files from Banks application. To learn about the editing of incoming format mappings for XMLs , please refer to SAP Help Portal.
To showcase the solution, our task will be to map the content of the following XML file to the structure SMT_TEST_S_SCARR. This structure is typically used for ABAP trainings.
<airline name="Lufthansa"> <flight> <from>Mallorca</from> <to>Barcelona</to> <schedule> <flight_date>20221202</flight_date> <aircraft_type>727-200</aircraft_type> </schedule> <schedule> <flight_date>20221206</flight_date> <aircraft_type>737-400</aircraft_type> </schedule> </flight> <flight> <from>Mallorca</from> <to>Mao</to> <schedule> <flight_date>20221203</flight_date> <aircraft_type>A310-200F</aircraft_type> </schedule> <schedule> <flight_date>20221207</flight_date> <aircraft_type>CONCORDE</aircraft_type> </schedule> </flight> </airline>
Creating Format Mapping
To create a new format mapping, use the button ‘Create’ in the Map Format Data app. As we would like to read an XML input file, we must select the Data Format ‘XML Structure’. To map the content of our XML file to the SMT_TEST_S_SCARR structure, we must select the Mapping Type ‘TST1 – Airline and flights’. This mapping type is available strictly for testing purposes.
Creating the File Structure
When we open our newly created format mapping, we can see an empty mapping section. In there, we will create a structure that will map the content of our XML file to the SMT_TEST_S_SCARR structure.
To start mapping the first node of our XML file, create element as a subnode of mapping section. As the first node in our file is ‘airline’, we will start with this one. The name of the element in the mapping section must be the same as the one in our XML file (the name is case sensitive).
The airline node is mandatory and only appears once. The Minimum Occurrences field value must therefore be set to 1 (mandatory) and the Maximum Occurrences must be set to 1 (only one airline element is expected in the input file).
We have now finished the mapping of the first node and can continue with the rest of the file.
The next node in our file is the attribute ‘name’ under the ‘airline’ element. To map this attribute, we create attribute node as a subnode of the airline node. As it would not make sense to work with an unknown airline, this attribute should be mandatory and therefore we tick the Mandatory Node checkbox.
As the name attribute should me mapped to the SMT_TEST_S_SCARR structure’s CARRNAME, we use search help to find this component.
We can now build the rest of our mapping structure in a similar way. While some of the structure aspects are checked by the app, it is still necessary to follow the naming and the nesting level of the nodes.
The elements ‘from’, ‘to’, ‘flight_date’ and ‘aircraft_type’ should only appear once and therefore the minimum and maximum occurrences should be set to 1. The corresponding output fields for each of these elements are in the following table:
The occurrence of the elements ‘flight’ and ‘schedule’ should not be limited as there may be more than one flight scheduled in the XML file. There is also no need to set an output field for these elements because they have no value.
Defining the Action Node
We will use the append action to insert a new record to the output table to store the data and ensure that they are not overwritten when the next line is being processed. This relevant for our case, as we can have multiple ‘FLIGHTS‘ and for each ‘flight’ multiple ‘schedule’s.
To append each record of ‘flight’ and ‘schedule’, we need to define Append to Table action node. First, we will create an action node to append the content of element schedule to a table. Name the node and select Append to Table option in the dropdown of Add Action to define a new action. Select table FLIGHTS-SCHEDULES as the output table.
Once we have the append schedule defined, we can create a new action node to append the content of ‘flight’. This action node must be defined as a subnode of the ‘flight’ node because we first need to append the content of the ‘schedule’. Select table FLIGHTS at the output table for this action node.
The mapping should now be complete, and we can release and test the format mapping.
Testing Format Mapping
To test the format mapping, click the ‘Test’ button in the top-right corner of the screen to access Test Incoming Format Mappings app. A new tab with the Test Incoming Format Mappings will open.
First, we need to create a new test run via the ‘New Run’ button. In the subsequent dialog window, we will select our XML file from “Prerequisites” section (copy and save the file content locally to your machine).
When the test run is finished, click on the table row to open the detail page. The detail page provides the information about the Output Structure on the left side of the screen, where you can analyze the mapped data and their format. You can also use the Log tab to see the detailed information about the engine run itself. The right side provides the context with the file that you have used for the test run. As you can see in the following picture, in our case, the data are stored in the output structure according to our definition.
For more information about testing, you can see Test Your Custom Bank Statement Definitions in Map Format Data | SAP Blogs.
If you have any questions about Map Format Data application, you can use the Q&A area. You are welcome to provide feedback in the comment section below.