Show TOC

Background documentationData Mapping Rules Locate this document in the navigation structure

 

Data mapping defines rules for transforming the source context to the target context. Each context consists of one or more nodes representing the data that is transformed. You use drag and drop to specify which nodes are mapped to each other in the mapping editor. You use expressions based on the XPath grammar to specify how the transformation between the nodes is done. For more information about expressions, see Creating Expressions.

In this section you will find information that you must know to perform data mapping tasks successfully:

  • How to define mappings between parent and (or) child nodes

  • How to assign static values to target context nodes

  • How to refer to parent or root nodes in an expression

  • What is the meaning of the context nodes decorations

  • What is the meaning of the different mapping lines

  • Which are the supported data types

Mapping Parent and Child Nodes

Nodes can be of simple type, which means that the node has no children or of complex type, which means that the node has child nodes. If you define data mapping from the source context to a child node from the target context, all of its parent nodes are also included in the mapping and this mapping is visualized with an asterisk (*) next to the parent node in the target context.

Depending on whether you define mappings between parent nodes or between their child nodes only, you can achieve different mapping results. The results also depend on the cardinality of the parent node. If the cardinality of the parent node is 1 and you map only the child nodes, the mapping engine creates the parent target node (B), even if the source context is empty.

Example Example

  1. A     B
  2.  A1  -> B1
  3.  A2  -> B2
End of the code.

If you map the parent nodes and the source structure is not initialized, then the target structure is not created.

Example Example

  1. A  ->  B
  2.  A1  -> B1
  3.  A2  -> B2
End of the code.

If the cardinality of the source parent node is greater than 1, which means that the source is a list, you have to map the parent nodes of the source and the target. Thus, for each of the elements of the source, an element is created in the target context and the mapping between child nodes is executed. If no mapping between the source and the target parent nodes exists, the mapping editor shows an error. You need to specify how the elements of the source context are transformed to the target with an expression.

Example Example

  1. A[] -> B[]
  2.  A1  -> B1
  3.  A2  -> B2
End of the code.
Mapping Individual Child Nodes

When you define data mappings between parent nodes of the same type, all their child nodes are also mapped to each other. This default behavior is called deep copy and means that the source context is copied to the target context. A plus sign (+) appears on the mapping line between the parent nodes. You can expand the mapping and see the mappings between the child nodes when you click the plus sign.

Example Example

  1. A -[+]-> B
  2.  A1       B1
  3.  A2       B2
End of the code.

Note Note

If you have created deep copy mappings with the mapping editor in enhancement package 1 for SAP NetWeaver CE 7.1, you can migrate these mappings in higher releases of SAP NetWeaver to improve the overall performance. The mapping editor in higher releases reduces the number of persisted data mappings. As a result, you have only one mapping, whereas in CE 7.1.1 the mapping editor created all the child mappings. To do the migration, you proceed as follows:

  1. Open the mapping containing the deep copy mapping you want to migrate, such as the input mapping of a human activity.

  2. Delete the old deep copy mapping and create it again. You can also change other mapping in the same data context to start the migration.

The migration is started automatically.

End of the note.

In case you want to map only individual child nodes and not the whole structure, you can switch the mapping editor to one of the following options:

  • 1:1

    This option allows you to select individual child nodes from the source context and map them to child nodes from the target context.

  • n:m

    This option is available when the parent nodes are lists. It allows you to select several child nodes from the source context and map them to a child node from the target context.

The switch options are available in the context menu of the collapsed mapping line between the parent nodes.

Assigning Static Values to Target Context Nodes

You can directly assign a static value to a target context node, which means that no data transformation from the source context is performed. To do that, you double-click the target context node and specify in the expression editor the value that you want to assign.

Example Example

You can enter, 5 for numeral constants, true or false for boolean constants, "abc" for text constants, 2009-08-11 for date, 14:05:00 for time, and 2009-08-11Т14:05:00 for date and time.

End of the example.

To assign a list with static values, you enter the elements of the list between parentheses ((...)) and separate them by a comma (,).

Example Example

(ElementOne, ElementTwo, ElementThree)

End of the example.
Using Axes in Data Mappings

When you define data mappings, you can use additional axes for selecting parent and root nodes in the expression editor. Using additional axes is useful when you want to define data mappings between lists or between their child nodes. The following axes are available:

  • Root selector

    In the expression editor it is presented as “/” and selects the root node of a context node.

  • Parent selector

    In the expression editor it is presented as “../” and selects the direct parent node of a context node.

For example, you have the source and target structures of nodes as described below.

Example Example

  1. SourceRoot -> TargetRoot
  2.  A[] -----------> B[]
  3.   A1 ------------> B1
  4.    A11 -----------> B11
  5.   A2  -------/
End of the code.

In the source structure, the node A is a list and has two child nodes A1 and A2. The child node A1 also has one child node A11.

You want to map A11 and A2 nodes from the source structure to B11 node in the target structure.

For example, you have the following data in source context:

Syntax Syntax

  1. XML Structure of source context
  2. <SourceRoot>
     <A>
      <A1>
       <A11>a11</A11>
      </A1>
      <A2>a2</A2>
     </A>
     <A>
      <A1>
       <A11>a11'</A11>
      </A1>
      <A2>a2'<A2>
     </A>
    </SourceRoot>   
End of the code.

You can use the string-join function to aggregate the values of the source to the target. Depending on whether you use the parent or root selector, you have different results after the mapping.

Root Selector

Syntax Syntax

  1. string-join( (A11, /SourceRoot/A/A2), "_" )
End of the code.

The result of the mapping to the target node B11 consists of two elements: [a11_a2_a2'] and [a11'_a2_a2'].

Parent Selector

Syntax Syntax

  1. string-join( (A11, ../A2), "_" )
End of the code.

The result of the mapping to the target node B11 consists again of two elements: [a11_a2] and [a11'_a2']

Mappings with Optional and Mandatory Nodes

If you create a mapping between optional nodes and the source node is missing or it does not contain any content and nested nodes, the target node is removed from the target structure and the structure is still valid.

For example, you have the source and target structures as described below.

Example Example

  1. SourceRoot      ->     TargetRoot
  2.   r_man_1 ------------> r_man_1
  3.   r_opt_2               r_opt_2
  4.   r_man_3               r_man_3
  5.     oi_opt_1              oi_opt_1
  6.       si_man_1 ---------->  si_man_1
  7.     oi_man2               oi_man2
End of the code.

Syntax Syntax

XML Structure of the source structure:

  1. <input>
          <r_man_1></r_man_1>
          <r_man_3>      
             <oi_opt_1></oi_opt_1>
          </r_man_3>  
    </input>
    
End of the code.

Syntax Syntax

XML Structure of the target structure:

  1. <result>
          <r_man_1></r_man_1>
          <r_man_3></r_man_3>
    <result>
    
End of the code.

The mapping is between mandatory child nodes (<si_man_1>), whose parent is an optional node (<oi_opt_1>). This optional node is removed from the target structure because its child mandatory node does not receive data from the source. When mapping is executed, only the mandatory nodes <r_man_1> and <r_man_3> are created in the target structure and the structure is valid.

Context Nodes Decorations

When you define data mappings, you may see the following decorations on the context nodes:

  • Question mark (?)

    The question mark (?) decoration at the upper right corner of a node means that the mapping to this node is optional.

  • At sign (@)

    The at sign (@) decoration at the bottom right corner of a node means that the node is an attribute and is always of simple type.

  • Stack icon

    A node decorated as a stack icon means that this node may contain multiple nodes or values.

A text() child node may be also presented in the source or target context. When you define data mapping from a text() node, the text() node selects the text value of its parent node. The parent node is of complex type with simple content. When you define data mapping to a text() node, the text value is assigned to the parent node as a text value. Note that the text value is not necessary of type string but can be also of type integer, and so on.

Mapping Lines

In the mapping editor, the following mapping lines are available, which have different meanings:

  • Solid lines

    They show actual mappings between source and target nodes and you can change these mappings.

  • Dashed lines

    They show actual mappings whose source or target node, or both, lies out of the visual area of the screen or is hidden. You can change these mappings.

  • Dotted lines

    They show implicit mappings that you cannot delete or update. Implicit mappings are defined in one of the following ways:

    • You use deep copy to map nodes having the same complex type assigned to them. As all child nodes are mapped to each other implicitly, the mapping lines between them are dotted, when mapping between parent nodes is expanded.

    • You apply a reusable mapping function. All children mappings are done implicitly and the mapping lines between them are dotted when parent mapping is expanded.

Supported Data Types

The data mapping does not support all data types. For information about the limitations of data types, see SAP Note 1468084.

You need to consider the data type compatibility when you define data mappings .For more information, see Data Type Compatibility.