35
creatIf removeContexts replaceValue exists splitByValue collapseContexts useOneAsMany sort and sortByKey mapWithDefault formatByExample

Sap pi 10 nodes

Embed Size (px)

DESCRIPTION

sap pi

Citation preview

Page 1: Sap pi 10 nodes

creatIf

removeContexts

replaceValue

exists

splitByValue

collapseContexts

useOneAsMany

sort and sortByKey

mapWithDefault

formatByExample

createIf 

Page 2: Sap pi 10 nodes

Description:” I have criteria for existing”. It is used when you want to create target node or element based on some condition. 

Fig.1 

Figure depicts createIf node functionality. ID is mapped to MT_Reciever_Minor using createIf function. 

Page 3: Sap pi 10 nodes

Fig.2 

Figure depicts result of mapping in Fig.1.As, the value of ID is less than 25, MT_Reciever_Minor node is created in target side. 

Page 4: Sap pi 10 nodes

Fig.3 

Figure depicts createIf node functionality. ID is mapped to MT_Reciever_Major using createIf function. 

Page 5: Sap pi 10 nodes

Fig.4 

Figure depicts result of mapping in Fig.3.As, the value of ID is greater than 25, MT_Reciever_Major node is created in target side.

Page 6: Sap pi 10 nodes

removeContext 

Description: Removes all immediate level contexts of a source field. In this way, you can delete all hierarchy levels and generate a list. 

Fig.5 

Figure depicts removeContexts functionality.  

Page 7: Sap pi 10 nodes

Fig.6 

Figure depicts result of mapping in Fig.5.By applying removeContexts, all the Cust_NAME fields came in one context. 

Page 8: Sap pi 10 nodes

replaceValue 

Description: Replaces the value of element with a value that you can define in the dialog for the function properties. 

Fig.7 

Figure depicts replaceValue functionality.

Page 9: Sap pi 10 nodes

Fig.8 

replaceValue will replace the value of Cust_NAME element with the value defined i.e.20Name.

Page 10: Sap pi 10 nodes

exists 

Description: This is the most frequently needed when mapping IDoc structure to file structure. Lot of times we come across a scenario where the fields (occurrence=0) are not mandatory in the IDocs are not populated in the source XML and they are required in the target XML (occurrence =1) which gives a mapping run time exception that target element cannot be created. We can handle the error by checking whether the source tag exists and if it does not we can pass an empty value, which generates the required target field. 

Fig.9 

Figure depicts exists functionality. ID (source field) is checked for its existence by using exists function. 

Page 11: Sap pi 10 nodes

Fig.10

Figure depicts the existence of ID (source field), so same value is populated in target file. 

Page 12: Sap pi 10 nodes

Fig.11 

Figure depicts the non-existence of ID (source field), so same the constant value defined is populated in target file.

Page 13: Sap pi 10 nodes

splitByValue

Description: splitByValue() is the counterpart to removeContexts(): Instead of deleting a context, you can insert a context change in the source value queue.

You can insert a context change in the queue after each value or after each change to the value, or after each tag without a value.

splitByValue can be achieved in following three ways:

1. EACH VALUE

 

Fig.12 

Figure depicts the splitByValue(Each Value) functionality. 

Page 14: Sap pi 10 nodes

Fig.13 

Figure depicts the splitByValue (Each Value) mapping result. 

Page 15: Sap pi 10 nodes

2. VALUE CHANGE

 

Fig.14

 

Figure depicts the splitByValue (Value Change) functionality.

 

Page 16: Sap pi 10 nodes

Fig.15 

Figure depicts the splitByValue (Value Change) mapping result. 

Page 17: Sap pi 10 nodes

3. EMPTY VALUE 

Fig.16

 

Figure depicts the splitByValue (Empty Value) functionality. 

Page 18: Sap pi 10 nodes

Fig.17

 

Figure depicts the splitByValue (Empty Value) mapping result.

Page 19: Sap pi 10 nodes

collapseContext 

Description: It takes the first value from all the contexts and put them into a context on the target side, So that all values come under one context.

Empty contexts are replaced by empty strings.

 

Fig.18 

Figure depicts the collapseContexts functionality. 

Page 20: Sap pi 10 nodes

Fig.19 

Figure depicts the collapseContexts mapping result.

Page 21: Sap pi 10 nodes

useOneAsMany 

Description:  As shown in the figure below the maximum occurrence of the header node in the source is 1 and the target is unbounded. So we have only one occurrence of MatNo & MatDesc, which has to be replicated for every line Item. 

Fig.20 

Above figure depicts, both source & target structures. 

Page 22: Sap pi 10 nodes

Fig.21 

Above fig depicts, mapping of usOneAsMany function 

In the above figure, useOneAsMany takes three arguments. 

1. First argument “what should be repeated”.2. Second argument “how many times, first argument should repeat”.3. Third argument “Should have same context of Item (Second argument)”.It maintains the context.

MatDesc field will also be mapped in similar way like MatNo. 

Page 23: Sap pi 10 nodes

Fig.22 

Number of time Item node appears (repeats), same number of time Header node will appear in target side. So, source Item node is mapped to Target Header node. 

Page 24: Sap pi 10 nodes

Fig.23 

In above fig, Item node is duplicated.  

Page 25: Sap pi 10 nodes

Fig.24 

In above fig, Item node is duplicated twice in the source structure. Accordingly, Header is repeating twice in the target side i.e. MatNo & MatDesc.

Page 26: Sap pi 10 nodes

sort & sortByKey 

Description: The element Cust_Name shall be sorted the same way as the element Cust_ID.but with two inbound parameters to sort (key/value) pairs. The sort process can be compared to that of a table with two columns

Sort and sortByKey: Have 3 options.

1)       Lexicographically 2) Lexicographically (Case Insensitive) and 3) Numeric. 

Fig.25 

Figure depicts the sort functionality. 

As the functions sort and sortByKey only sort the elements within the same context, we have to use the functionremoveContexts before sort. After sort we have to restore the original contexts. We do this with the node functionsplitByValue 

Page 27: Sap pi 10 nodes

Fig.26 

Figure depicts the sortByKey functionality. 

In the above fig The Cust_Name is sorted based on the Cust_ID.

sortByKey: take two arguments, first argument acts as key for sorting the second argument.  

Page 28: Sap pi 10 nodes

Fig.27 

In the above fig Cust_Name is sorted based on Cust_ID.  

Page 29: Sap pi 10 nodes

mapWithDefault 

Description: This function provides a default value, whenever the source element is not available. 

Fig.28 

Figure depicts the mapWithDefault functionality. 

Page 30: Sap pi 10 nodes

Fig.29 

Figure depicts the mapWithDefault mapping result.

Page 31: Sap pi 10 nodes

formatByExample 

Description: This function has two arguments, which must both have the same number of values. To generate the target, the function takes the values from the first argument and combines them with the context changes from the second argument. 

This function allows grouping of values of a tag (Cust_NAME) according to values of another tag (Cust_ID). 

Page 32: Sap pi 10 nodes

Fig.30 

In the Example, Cust_ID is repeated 5 times having 5 different contexts. By using removeContexts function,remove all the 5 contexts. Then split the Cust_ID in different context whenever value change occurs, that is achieved using splitByValue (Value Change).From each context, take first Cust_ID and put it in one context usingcollapseContexts. So, Creating number of Customers nodes based on result of collapseContexts. 

Page 33: Sap pi 10 nodes

Fig.31

In the Example, Cust_ID is repeated 5 times having 5 different contexts. By using removeContexts function,remove all the 5 contexts. Then split the Cust_ID in different context whenever value change occurs, that is achieved using splitByValue (Value Change).From each context, take first Cust_ID and put it in one context usingcollapseContexts. Again split into different context based on each value by using splitByValue (Each Value) .So, Creating number of Cust_ID fields based on result of splitByValue.

Page 34: Sap pi 10 nodes

Fig.32 

The figure above depicts formatByExample functionality. 

Page 35: Sap pi 10 nodes

formatByExample takes two arguments:

1. First argument: Field that is to be grouped.

2. Second argument: Base for grouping of first argument. 

Fig.33 

In the fig above, Cust_NAME is grouped in 2 context based on Cust_ID in the target structure.