Skip to Content

Map Message Structure

test
0 %
Map Message Structure
Details

Map Message Structure

2019-12-17
Use the mapping step to convert the message structure to a structure desired by the recipient.

You will learn

  • How to map message structures
  • How to use the visual mapping editor
  • How to use standard mapping functions
  • How to create a custom groovy function in Message mapping
  • How to create a custom function with multiple outputs
  • How to simulate mappings
  • How to work with resources

In this exercise, you shall convert the message structure from:

<orders>
	<order>
		<orderID>BS00010023</orderID>
    <order>
  		<orderID>BS00010023</orderID>
      <code>KWA2PRBK5I</code>
    </order>  
		<OrderDate>11.04.2019</OrderDate>
		<CustomerName>Kiara</CustomerName>
		<CustomerLastName>Jain</CustomerLastName>
		<Address>23,Prime View,Redfield,Bangalore,Karnataka,560037,India</Address>
    <code>KWA2PRBK5I</code>
		<ContactNumber>0091-8437329849</ContactNumber>
		<items>
			<item>
				<ProductID>RPD4044543</ProductID>
				<ProductDescription>Wireless Mouse</ProductDescription>
				<Quantity>1</Quantity>
				<ItemValue>1057</ItemValue>
			</item>
		</items>
		<Shipping>200</Shipping>
		<OrderValue>1257</OrderValue>
		<ShippingType>Priority 2-day</ShippingType>
		<SpecialPackaging>None</SpecialPackaging>
		<PaymentType>CoD</PaymentType>
	</order>
</orders>

to:

<orders>
	<order>
		<orderID>BS00010023</orderID>
		<OrderDate>11.04.2019</OrderDate>
		<CustomerName>Kiara Jain</CustomerName>
    <HouseNumber>23</HouseNumber>  
    <AddressLine1>Prime View</AddressLine1>
    <AddressLine2>Redfield</AddressLine2>
    <City>Bangalore</City>  
    <State>Karnataka</State>  
    <Pin>560037</Pin>  
    <Country>India</Country>  
    <code>KWA2PRBK5I</code>
		<ContactNumber>0091-8437329849</ContactNumber>
		<items>
			<item>
				<ProductCode>RPD4044543</ProductCode>
				<ProductDetails>Wireless Mouse</ProductDetails>
				<Quantity>1</Quantity>
				<ItemValue>1057</ItemValue>
			</item>
		</items>
		<Shipping>200</Shipping>
		<OrderValue>1257</OrderValue>
		<ShippingType>Priority 2-day</ShippingType>
		<SpecialPackaging>None</SpecialPackaging>
		<PaymentType>CoD</PaymentType>
	</order>
</orders>

Step 1: Add message mapping
  1. Add a Message Mapping step to message processing pipeline:
    • Click on the design Palette.
    • Choose Mapping.
    • Choose Message Mapping.
    Choose MMap
    • Drag it on to the execution pipeline after the Content Enricher.
    Add MMap
    • Select the mapping step and click on Create.
    CreateMMap
    • In the pop-up dialog, enter ConvertOrder and click Create.
    Define MMap Str
    • Download the source and target on your filesystem.

    • On the following screen, upload the source and target XSD into your message map:

      • Click on Add source message.
      • Click Upload from File System in the next window.
      • Choose the file from the desired location.
      • Repeat the above steps for the target message structure.
    • Finally you should get the following screen:

    Source Target added
    • Map the following fields one-to-one by dragging a field from the source to the corresponding field on the target:

      • orders
      • order
      • orderID
      • OrderDate
      • ContactNumber
      • items
      • item
      • Quantity
      • ItemValue
      • Shipping
      • OrderValue
      • ShippingType
      • SpecialPackaging
      • PaymentType
      Add MMap Connections
    • Map the following fields:

      Source Target
      ProductID ProductCode
      ProductDescription ProductDetails
Log on to answer question
Step 2: Use Standard functions
  1. Link CustomerName on the source to CustomerName on the target.

  2. Link CustomerLastName on the source also to CustomerName on the target.

  3. Go to the visual mapping editor and look for the Concat standard function and drag it to the work area.

  4. Connect the following:

    concatCustomerName

    CustomerNamestring1

    CustomerLastNamestring2

    Delimiter string → space

    CustomerNameConcat
Log on to answer question
Step 3: Create a custom function with multiple output
  1. Connect Address on the source to the following fields on the target:

    • HouseNumber
    • AddressLine1
    • AddressLine2
    • City
    • State
    • Pin
    • Country
    Map Address
  2. Go to visual editor at the bottom and click on Create function.

  3. In the pop-up dialog, give SplitAddr as the Script Name and click OK.

    Add Script for Address
  4. Paste the following code in the script file:

    def void splitAddress(String[] Address, Output HouseNumber, Output AddressLine1, Output AddressLine2, Output City, Output State, Output Pin, Output Country)
    {
        String Addr = Address[0];
        def splitAddr = Addr.split(',');
        HouseNumber.addValue(splitAddr[0]);
        AddressLine1.addValue(splitAddr[1]);
        AddressLine2.addValue(splitAddr[2]);
        City.addValue(splitAddr[3]);
        State.addValue(splitAddr[4]);
        Pin.addValue(splitAddr[5]);
        Country.addValue(splitAddr[6]);
    }
    
  5. Click OK.

    script
  6. Click on Add functions.

  7. Choose splitAddr.groovy in the pop-up dialog.

  8. You will now see splitAddr added to the list of custom functions under the standard functions:

    AddCustom
  9. Click on splitAddr and drag the function splitAddress to the visual editor and connect the relevant fields.

Finally, you should see the following:

AddressMap

Once all the fields are mapped, your mapping should look like:

Map 1Map 2
Log on to answer question
Step 4: Simulate mapping

You will now use the Simulate functionality to test if the mapping is configured correctly and the desired output is generated.

Store the Input Message to you file system.

  1. Click on Simulate.

  2. Click on Browse and import the Input Message.

    Simulate
  3. Click on Test.

    Simulate
  4. After the system executed the test, the system generated the output on the left side of the screen:

    SimulateResult
  5. Validate the result to check if it is as expected. Make the necessary changes if needed.

  6. Once you are satisfied with the results, click on OK to return back to the integration flow:

    Done Mapping
Log on to answer question
Step 5: Explore resources

In the process of defining a message map, you created or uploaded a lot of artifacts, like XMLs, XSDs, scripts and message maps.

You can find each of the artifacts under the Resources view.

  1. Click on the Canvas.

  2. Go to the Properties Sheet.

  3. Go to the Resources tab.

    Find Resources
  4. You can find all the artifacts that belong to the integration flow listed here.

    You can upload an artifact once and reuse it multiple times in the same integration flows.

    Resources
Where can I see the list of all mappings, scripts, etc. used in an integration flow in SAP Cloud Platform Integration?
×

Next Steps

Back to top