Creating Message Mapping Objects

Objectives

After completing this lesson, you will be able to:
  • Display a message mapping
  • Create message mappings

Message Mapping

In Message Mapping, you realize the actual message mapping between two XML files. You build the mapping with the Graphical Mapping Editor. In the Mapping Editor, you select the source and the target structure to be mapped.

You can create a mapping program using the Enterprise Services Repository perspective in NWDS. Mapping programs that you create using this perspective are known as message mappings. You can reference message types, imported interfaces, or imported SAP interfaces, that is, Intermediate Document (IDoc) types or Remote Function Call (RFC) signatures as the source and target structures.

Hint

You can also import external XML or XML Schema Definition (XSD) files into the message mapping as structure templates. However, you must make all interfaces available in the Enterprise Services Repository (ESR).

Graphical Mapping Editor

The Graphical Mapping Editor offers different standard tools and out-of-the-box functions to realize simple and complex mappings. You also have the choice to build your own Java based user-defined functions (UDFs).

Use either the Add button or search the structure in the tree of the ESR to select the source and target message type. Select the types by using the mouse and move them to the editor. Then you can define the structure mapping by selecting a field in the source structure and moving it to the corresponding field in the target structure. If you require conversions for fields in the target structure or need to assign constants, use the functions available in the expression editor in the lower part of the Enterprise Service Repository perspective.

Structure View of a Source or Target Structure

The source or target structure is shown as a tree. The icons indicate which fields are obligatory fields. The structure also shows the cardinality. The cardinality defines how often an element or node is permitted to occur.

Icons in the Mapping Editor

The figure shows the most important icons of the mapping editor and what they mean. Beneath the source and target structures, there is a window containing the expression editor. In the expression editor, you can display and edit the target field mapping for any target field.

SAP GUI Functions in NWDS for Message Mapping

If the elements of a particular node in the source structure have the same name as elements in the target structure, you can use the mass assignment option. To do so, drag the source node with the right mouse button and drop it to the target source node. Select Execute Default Matcher from the context menu. All lower-level fields with the same name are then assigned to each other.

In the Message Mapping Definition screen select Definition tab to see the field assignments (structure mapping) using connection lines, which are displayed between the source and target elements.

Alternatively you can display the mapping rules as text. To do so, do the following steps:

  1. Close your Message Mapping screen.

  2. In the menu select: WindowPreferencesWeb ServicesEnterprise Service Browser.

  3. Set flag Use Expression Editor for Mapping.

  4. Choose Apply.

  5. Choose OK.

  6. Open your Message Mapping.

    Now you can open the text based expression editor either by clicking on a target element or by clicking on the mapping function.

The figure shows the place, at which the flag Use Expression Editor for Mapping can be set.

Message Mapping, Test

XML file

To test your Message Mapping you need to create first an XML file with test data in the Enterprise Service Repository perspective.

The figure illustrates the steps described below.

To do so:

  1. Open the context menu of your message mapping (click right mouse button).

  2. Select GenerateXML File from the Context menu.
  3. Maintain the required fields in the XML Generation Wizard.

  4. Choose Finish.
  5. Maintain the Data in the XML and save your settings.

Note

The created XML File will be stored in folder My Documents\JAxxx\RemoteSystemsTempFiles of the corresponding user.

Test Case

Once you have created the XML File with your test data, you have to create a test case.

The figure illustrates the steps to create a test case for message mapping.

To create a test case, do the following:

  1. Open again the context menu of your message mapping.

  2. Select Run AsRun Configurations...-.

  3. In the Run Configurations Wizard double click ESR Message Mapping.

  4. Maintain the required fields and select the Message Mapping you want to test in Object Details area.

  5. Specify the Test Data Details.

  6. Apply and Run your Test.

How to Use the Functions of the Graphical Mapping Editor

Show the editor functions in the system so that customer can see both tools (NWDS versus Enterprise Services Builder)

Steps

  1. Use the functions of the Graphical Mapping Editor.

    1. In the browser, go to http://nwktdc00.wdf.sap.corp:50000/dir.

    2. On the Enterprise Services Builder screen, navigate to SAP BASISSAP BASIS 7.5http://sap.com/xi/XI/Demo/Agency.

    3. Under Message Mappings, double-click BookingOrder_Agency2Airline.

    4. Use this example to explain the elements, the SAP GUI elements, and the functions of the graphical mapping editor.

    5. On the Display Message Mappingscreen, choose the Test tab to show the test settings.

    6. On the Display Message Mapping screen, choose the Definitions tab.

    7. Choose the Switch between Display and Edit Modes button.

    8. Double-click one object on the sender message side (left side) to bring it into the working area.

    9. Do this with another object on the receiver side (right side).

    10. Explain the linking.

Mapping Functions

The mapping editor has numerous standard functions that you can use to convert a field.

Combining two text fields into one text field and the standard function for converting dates are both examples of mapping functions.

Concat Function

Perform the following steps to use the concat function:

  1. Select the target field in the target structure in which the result is to be entered.
  2. To display the field in the expression editor, double click it.
  3. Select the two fields in the source structure that are to be joined to form the target field.
  4. To display the fields in the expression editor, use drag and drop.
  5. Select the function type Text and choose concat.
  6. To join the objects, choose the blue bubble in one of the source fields, keep the mouse button pressed, and drag the arrow across to the standard function.
  7. Repeat the procedure with the remaining objects.

DateTrans Function

When you need to map data fields, use the function DateTrans to define transformations that transform one date format to another.

Perform the following steps to use the DateTrans function:

  1. Choose the function type Date.
  2. In the functions tree, choose TransformDate().
  3. Join the objects.
  4. Double-click the function to maintain the properties.
  5. Specify the required date format.

Target Field Mapping

On a technical level, a mapping tool must provide a solution for the following challenges:

  • A unique result needs to be determined for each target field that is to be completed. In a message mapping, this is achieved by defining target field mappings.
  • Optional nodes are only created if a rule is defined that specifies when an instance of the target structure is to be created. This creation can be achieved by assigning it to a source field or a source node. In the case of cardinalities > 1, you need to create rules to define how many instances of the target structure need to be created. If the source fields belong to a node with multiple instances, you need to define which instance of the source structure the field values are to be copied from, and to which instance of the target structure they are to be copied.

In a target field mapping, you create rules for each target field. These rules define the source fields used to determine the result value. The rules are not attached to the source field, but to the target field. Each source field can be reused in any number of target field mappings. However, there is only one target field mapping for each target field.

Mapping with the If-function

Functions of various types can be used within message mapping.

The mapping in the figure, Mapping with the If Function, shows whether the MaterialGroup tag is available in the source structure. If it is, the value is transferred to the target field; if not, a constant with the value Missing is entered.

Mappings for Documents with Multiple Nodes

If a structure is used more than once (multiple nodes) in a mapping, the structure is also relevant for the structure fields. To ensure that the source document is processed efficiently, the source document is placed in queues at runtime of message mapping. For every source field (and every source structure), a queue is created. This queue contains all values that appear. These queues are the basis for the mapping and are also created and used for all intermediate steps, such as standard functions. The queues also contain context information, for example, on which node the information about a value is contained.

Additional node functions are available for more complex mapping tasks; these node functions enable you to control the structure of the queue. You can display the queues for the current test instance in the data-flow editor.

Create a Message Mapping

Business Scenario

You want to define a message mapping between two message types. The sender and receiver message types are already available and your task is to complete the message mapping between these two outbound and inbound message types.

Exercise Information

Note

In this exercise, when the values include ##, replace the character with a two-digit number (01–30).

Exercise Options

You can perform this exercise in two ways:

  1. Live Environment: choose Start Exercise, and from the entry page choose Open PDF Document. Follow the steps described in this pdf in your own system landscape.
  2. Simulation: choose Start Exercise, and from the entry page choose Start Tutorial. Watch the step-by-step instructions within the simulation.

Note

We recommend running the simulation first.

Task 1: Create a Message Mapping Between MT_Material and MT_Materials_B

Steps

  1. Open NWDS 7.5 and open Enterprise Service Repository Perspective. Log on with your user ID and password if required.

    1. Navigate to WindowPerspectiveOpen PerspectiveOther. Select Enterprise Service Repository Perspective.

    2. If required, log on with your BIT500-## credentials.

  2. Create a message mapping MM##_MaterialA_MaterialsB.

    1. Navigate to SC_BIT500_##_B of education.comSC_BIT500_##_B of education.com and select your namespace, http://education.sap.com/scb##.

    2. Right-click http://education.sap.com/scb## and choose NewMessage Mapping.

    3. Choose Finish.

  3. Select message type MT_Material from software component SC_BIT500_A_## as the source message type.

    1. On the Message Mapping Overview screen choose the Browse button and change the Software Component Version to SC_BIT500_A_##.

    2. Then choose the Add button for the Source Messages.

    3. In the Select Message dialog box choose MT_Material | http://education.sap.com/sca##

    4. Choose OK.

  4. Select the message type MT_Materials_B from software component SC_BIT500_B_## as the receiver target message type.

    1. On the Message Mapping Overview screen press the Add button for the Target Messages.

    2. In the Select Message dialog box choose MT_Materials_B | http://education.sap.com/scb##.

    3. Choose OK.

  5. Assign the segment MT_Material in the sender interface to the segment Material in the receiver interface. Assign the identically named fields without converting them.

    1. Switch to the Definition tab.

    2. Select the source Message Type MT_Material with the right mouse button.

    3. Choose the right mouse button and move segment MT_Material to the target segment Material.

    4. Choose Execute Default Matcher in the context menu.

    5. Select the source segment MT_Material with the left mouse button and move it to the target segment Material.

  6. Define a target field mapping for the Date field. Use the date functions to transfer the date to the Date field at runtime.

    1. To move the Date field to the Expression editor, double-click the Date field in the target structure.

    2. Expand Date in the Functions Tree. The Functions tree is the right box on the lower right corner of the screen. A list of possible Date functions displays.

    3. Choose the currentDate function and move it into the expression editor. Alternatively double-click the currentDate function.

    4. Drag the mouse to draw a line between the small bubble on the right-hand of the currentDate box and the small bubble on the left-hand of the Date box to assign the currentDate function to the target field. Optionally, you can set the parameters of the currentDate function to define the data format.

    5. To set the format in this way, choose the currentDate box in the expression editor.

    6. Double-click the currentDate box and maintain the parameters as you like.

  7. Assign the segment Description in the sender interface to the segment Description in the receiver interface. Assign the fields with the same name without converting them and assign the source field MaterialID to the target field MaterialID.

    1. Select the segment Description with the right mouse button.

    2. Choose the right mouse button and move segment Description to the target segment Description.

    3. Choose Execute Default Matcher in the context menu.

    4. Drag the MaterialID field from the source structure and drop it to the MaterialID field of the target structure.

    5. Select the source segment Description with the left mouse button and move it to the target segment Description.

    As the source segment Description was not mapped to the target segment Description by the Default Matcher, you have to do this manually, as described in Step above.

  8. Activate the message mapping.

    1. Save your mapping.

    2. Expand your change list.

    3. Choose your Message Mapping. In the context menu choose Activate.

    4. Close the confirmation box.

Task 2: Test Your Message Mapping

Steps

  1. Test your Message Mapping in the test environment of the NWDS

    1. To create an XML-File select your Message Mapping in the Enterprise Service Brower Tab.

    2. Choose the right mouse button and select GenerateXML File… from the context menu.

    3. In the XML Generation Wizard, choose RemoteSystemsTempFiles and enter a file name. The file name must be unique and must end with .xml

    4. Choose Finish..

    5. The created XML opens in the main screen. Switch to the Design tab. Enter the values from the table

      Field NameValue
      MaterialID001
      IndustrySectorMarketing
      BaseUnitpc
      MaterialGroupBicycle
      MaterialTypeMountain bike
      LanguageEN
      DescriptionBike
    6. Save your test case.

    7. Open the context menu of your message mapping in the Enterprise Service Browser tab.

    8. Select Run AsRun Configurations….

    9. Choose ESR Message Mapping and choose the New button.

    10. In the Name field, enter the name Test_Configuration_##.

    11. In the Object Details area, choose the Browse button and select your message mapping.

    12. Choose the Workspace button in the Test Data Details field to select the Input Data.

    13. In the File Selection window expand RemoteSystemsTempFiles and select your *.xml file.

    14. Choose OK.

    15. Choose Run.

    16. A new window Test_configuration_## [Test-Result] appears, with the mapping result.

    17. Check if the result corresponds to your created message mapping MM##_MaterialA_MaterialsB.

    If the Test-Result window is empty, your message mapping is faulty. In this case check your message mapping, if all required fields are mapped correctly.

Log in to track your progress & complete quizzes