Messge Mapping
Messge Mapping
need to any changes Prod level how we update version and Meta data
Target queue
Mapping enables you to define an association between fields of messages with a different structure.
Context
SAP CPI handles message mappings as XML messages in queues. The queue contains all source data in
XML format. In queue, ะ้ำ elements under the same parent node are considered as the same context.
Whenever the parent node is changed, the context change is put into the queue (as highlighted in dark
gray color).
For example, an employee has multiple positions at a company. And let use the following XML
structure/data as an example.
<?xml version="1.0" encoding="UTF-8"?>
<Employees>
<Employee>
<PERNR>1000</PERNR>
<Name>Mr. A</Name>
<Position>
<PositionID>300</PositionID>
<PositionName>Position A</PositionName>
</Position>
<Position>
<PositionID>400</PositionID>
<PositionName>Position B</PositionName>
</Position>
<Position>
<PositionID>500</PositionID>
<PositionName>Position C</PositionName>
</Position>
<Position>
<PositionID>600</PositionID>
<PositionName>Position D</PositionName>
</Position>
<Position>
<PositionID>700</PositionID>
<PositionName>Position G</PositionName>
</Position>
</Employee>
</Employees>
The “PositionName” value of each “Position” element is assigned to separate contexts. Or we can also
say that the context changes are based on the “Position” element.
For example, instead of having “Position” context changes, we can change it to the “Employee” element.
As a result, the “PositionName” values of each “Employee” element are put in the same context. The
context changes are now based on the “Employee” element.
Map With Default
Function: Maps a source field to a target field with a default value if the source field is empty or
missing.
Use Case: Helps in ensuring that target fields are populated with default values when the source
field does not contain any data.
Exists
Use One As Many is about creating multiple target elements from a single source element,
whereas Map With Default ensures default values for missing data.
Function: Converts a single source element into multiple target elements or vice versa.
Use Case: Useful for scenarios where you need to replicate a single data element into multiple
elements in the target structure.
Splitbyvalue:its simply to insert context changes based on each value changes by default
Remove Context:to remove all the context changes and put the values in same context so that we can
sort them -ie., single record
From every record it will take all the values and put it in single record
Createif –is to create target node based on certain condition it will take input as true or false if its true
it will create an target node otherwise it will suppress
Example 1:
Second example : 1356 will come in same record output is same for remove context and collapse
context
Split by value:
Input
Output:
We use the following mapping functions to accomplish the end result.
removeContext: To remove all context changes and put the dates in the same context so we can
sort them.
dateTrans: This step is straightforward. It's used to convert the date format from YYYY-MM-
DD to YYYYMMDD.
sort: Set the sort order as descending.
splitByValue: It’s simply to insert context changes based on each value changes by default.
Source side :one order has multiple items ..there can be any number of items
As order number is coming only once in sender we need to use OneasMany function to display order
number for each item at target for this
UseoneAs many takes three inputs – one input for which field need to be repeated second field is how
many times it need to be repeated (how many times item comes that many times order number has to
shown at target side ) and third input is the context change ..oka value ki oka record
Split by value – oka oka record lo oka value vundali
Generally
1.createIf,
2.removeContexts,
3.replaceValue,
4.Exists,
5.SplitByValue,
6.collapseContexts,
7.useOneAsMany,
8.sort,
9.sortByKey,
10.mapwithDefault,
11.formatByExample
removeContexts
Removes all higher-level contexts of a source field. In this way, you can delete all hierarchy levels and
generate a list.
replaceValue
Replaces the value I with a value that you can define in the dialog for the function properties.
exists
O = true, if the source field assigned to inbound channel I exists in the XML instance. Otherwise, false.
SplitByValue
collapseContexts
Deletes all values from all contexts from the inbound queue except for the first value. Empty contexts (=
ResultList.SUPPRESS) are replaced by empty strings. Only one queue remains, which consists of contexts
that contain just one value each. Finally, all internal context changes are deleted, so that all values
belong to one and the same context.
useOneAsMany
Replicates a value of a field occurring once to pair it as a record with the values of a field occurring more
than once.
sort
Sorts all values of the multiply-occurring inbound field I within the existing or set context. The sorting
process is stable (the order of elements that are the same is not switched) and it sorts the values in
O(n*log(n)) steps. Using the function properties, you can specify whether values are to be sorted
numerically or lexicographically (case-sensitive or non case-sensitive) and in ascending or descending
order.
sortByKey
Like sort, but with two inbound parameters to sort (key/value) pairs. The sort process can be compared
to that of a table with two columns.
● Using the first parameter, you pass key values from the first column, which are used to sort the
table. If you have classified the key values as numeric in the function properties, they must not be equal
to the constant ResultList.SUPPRESS. See also: The ResultList Object
● Using the second parameter, you pass the values from the second column of the table.
If there is a discrepancy between the number of keys and values, the mapping runtime triggers an
exception. The function returns a queue with the values sorted according to the keys.
mapWithDefault
Replaces empty contexts in the inbound queue with a default value, which you specify in the function
properties.
formatByExample
This function has two inbound queues, which must both have the same number of values. To generate
the result queue, the function takes the values from the first queue and combines them with the context
changes from the second queue.
1. remove context:
You use removeContexts () to delete all the top contexts for an element. This removes all top hierarchy
levels, so that all elements of the target queue are assigned to a root element of the source queue.
Advanced user-defined functions can import either just one context into the input arrays, or complete
queues. Make your selection by selecting or deselecting the Save Entire Queue in Cache checkbox in the
function editor.
2. split by value:
The SplitByValue() function is the counterpart to removeContexts(): Instead of deleting a context, you
can insert a context change in the source value queue. You then receive this element for each inserted
context change instead of a top node element. However, for this to be possible, the top node source
field must be assigned a top node target field and minOccurs must be >0. You can insert a context
change in the queue after each value, after each change to the value, or after each tag without a value.
3. collapse context:
Using collapseContexts() puts the first values of all contexts into a context. Empty contexts are replaced
with an empty string:
This can be useful if an upper-level node is to be created each time a lower-level node exists, for
example. The function is useful in combination with the SplitByValue function.
You require the function useOneAsMany() if a field that only occurs once needs to be replicated as often
as another field occurs in the outbound message so that the fields can be written to the target structure
in pairs as a record.
6.copyValue
You use CopyValue() for a frequently occurring element to copy the value of a position in the source
structure and assign it to a target field. The value is copied each time the target field occurs in the target
structure. However, it is copied a maximum of maxOccurs times
7.createIf
You use createIf() to create a tag in the target structure depending on a condition.
8.exists
You use this function to determine whether a particular source field exists in the XML instance to be
processed. If it does, exists() returns the value true, otherwise it returns the value false.
9.Use
You use this function if you need to synchronize two queues of equal length with reference to their
context change. The mapping runtime takes the values from the first queue, and the context change
from the second queue. If the two inbound queues do not have the same number of values, the
mapping runtime triggers an exception.
Source xml:
Target xml
removeContext: To remove all context changes and put the dates in the same context so we can sort them.
dateTrans: This step is straightforward. It's used to convert the date format from YYYY-MM-DD to YYYYMMDD.