Example: Mapping UN/EDIFACT to XML

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Data Sources and Targets > EDI > UN/EDIFACT >

Example: Mapping UN/EDIFACT to XML

This example shows how to map data from UN/EDIFACT messages to an XML schema, in order to produce an XML instance file for further processing. The mapping created in this example is available at the following path: <Documents>\Altova\MapForce2019\MapForceExamples\EDI_Order.mfd.

 

Step 1: Add the UN/EDIFACT component to the mapping

1.Create a new mapping and select one of the following transformation languages: Java, C#, C++, or BUILT-IN. In this example, Java is selected as transformation language.
2.On the Insert menu, click EDI.
3.On the EDI collections dialog box, select the EDIFACT collection, then select the ORDERS message type, and click OK.

edifact2xml_example_01

4.When prompted to supply a sample EDI file, click Browse and open the ORDERS.EDI file from the <Documents>\Altova\MapForce2019\MapForceExamples\ directory. After you open the file, the Component Settings dialog box opens. This enables you to review the settings of the EDI component before adding it to the mapping. You can change these settings at any time later if required (see EDI Component Settings ). Notice that the ORDERS.EDI file appears as Input EDI file.

edifact2xml_example_03

5.Click OK. The EDI component is now displayed in the mapping area. Double-click the Message_ORDERS node to view its children items. To resize the component, click and drag the lower-right corner of the component window.

edifact2xml_example_04

 

Step 2: Add the target schema component to the mapping

1.On the Insert menu, click the XML Schema/File, and open the Order.xsd file from the <Documents>\Altova\MapForce2019\MapForceExamples\ directory.
2.When prompted to supply a sample XML file, click Skip and select Order as the root of the target document.

edifact2xml_example_05

At this point, both the source EDI component and the target XML schema are on the mapping area, so we are ready to start drawing the mapping connections.

edifact2xml_example_06

 

Step 3: Map the EDI items

The EDI component displays the structure of a message based on the collection (ORDERS) we selected. Typically, not all of the nodes will actually contain data, so you must be sufficiently familiar with the EDI documents being worked on, to locate the relevant nodes.

 

In MapForce, you map a source item and a target item by drawing a connection between them. For step-by-step instructions on how to create mapping connections in MapForce, see Working with Connections.

 

In this example, the following nodes (starting from the Group/Message_ORDERS node) will be mapped (connected) first:

Source

Target

BGM/C106/F1004

Order/Header/Number

SG2/NAD/C082/F3039

Order/Customer/Number

SG2/NAD/C080/F3036

Order/Customer/CompanyName

SG2/NAD/C059/F3042

Order/Customer/Address/Street

SG2/NAD/F3164

Order/Customer/Address/City

SG2/NAD/C819/F3229

Order/Customer/Address/State

SG2/NAD/F3251

Order/Customer/Address/ZIP

SG2/SG5/CTA/C056/F3412

Order/Customer/ContactName

At this stage, the mapping should look similar to the image below:

 

edi-8

 

Continue the mapping process and map:

Source

Target

SG29

Order/LineItems

SG29/LIN/C212/F7140

Order/LineItems/LineItem/Article/Number

SG29/IMD/C273/F7008

Order/LineItems/LineItem/Article/Name

SG29/QTY/C186/F6060

Order/LineItems/LineItem/Article/Amount

SG29/SG33/PRI/C509/F5118

Order/LineItems/LineItem/Article/SinglePrice

 

Step 4: Format the date

Drag the to-datetime function from the edifact library into the Mapping area. For instructions on how to work with functions in MapForce, see Working with Functions.

 

By supplying as arguments to this function the F2380 and F2379 components of the DTM/C507 element, we can create an appropriately formatted Received datetime.

 

We therefore map the following fields:

Source

Target

DTM/C507/F2380

The F2380 input of the to-datetime function

DTM/C507/F2379

The F2379 input of the to-datetime function

The result of the to-datetime function

Order/Header/Received

edi-10

 

Step 5: Filter the buyer purchase orders

At this point we want to filter the "Buyer" purchase orders. These can be identified by the party function code qualifier of the NAD (Name and address) segment. In this case, the value 'BY' indicates a "Buyer" (Party to whom merchandise and/or service is sold).

 

1.Drag the equal function from the core library into the Mapping area.
2.Add a filter to the mapping (On the Insert menu, click Filter: Nodes/Rows).
3.Add a constant to the mapping (On the Insert menu, click Constant). Assign to the constant the value "BY" by entering "BY" into the text field:

edifact2xml_example_07

Map the following items:

 

Source

Target

SG2/NAD/F3035

The b input of the equal function

The constant "BY"

The a input of the equal function

The result of the equal function

The bool input of the filter component

SG2/NAD

The node/row input of the filter component

The on-true result of the filter component

Order/Customer in the schema

The aim here is to only map data if the NAD node refers to a 'Buyer', as identified by the party function code qualifier 'BY'.

edi-12

 

Step 6: Calculate pricing and tax

The final step in this task is to calculate the pricing and tax costs.

 

1.From the core library, drag two multiply and one divide function into the Mapping area.
2.Insert a Constant component (Insert | Constant). Make sure "Number" is selected as type, and enter 100.0 into the text field.
3.Map the following items:

Source

Target

SG29/QTY/C186/F6060

value1 of the first multiply function

SG29/SG33/PRI/C509/F5118

value2 of the first multiply function

The result of the first multiply function

Order/LineItems/LineItem/Article/Price

SG29/SG40/TAX/C243/F5278

value1 of the divide function

The constant "100.0"

value2 of the divide function

The result of the first multiply function

value1 of the second multiply function

The result of divide function

value2 of the second multiply function

The result of the second multiply function

Order/LineItems/LineItem/Article/Tax

Your mapping should now look like this:

edi-14

Clicking the output tab performs an "on the fly" transformation and presents you with the XML document result:

edi-15


© 2019 Altova GmbH