Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
claus_wallacher
Active Participant
0 Kudos

1&nbsp The Problem



Most problems in mapping from a source structure to a target structure are due to the different structure of the source and the target message. One of the common issues is the need to map different node structures of the source message to only one node structure of the target message. This can easily be achieved through the duplication of subtrees, but what do you do if, for example, you also need to deal with the following issues:


    1. Not all of your source message items should end up in your target message (easy to solve).
    2. You need to number all line items in the target structure independent of the source it came from (easy to solve as a standalone problem, a little more tricky in conjunction with the bullet point above).


There are a number of solutions possible for this problem. In this weblog I will show two different possibilities:

    1. One solution that uses an advanced user defined function utilizing the global container.
    2. One solution that works with the available standard functions of the graphical mapping tool only.


I show these different options since the best choice may depend on the requirements of your specific scenario you work on (or the specific requirements of your customer).






2&nbsp An Example



In our example we receive with the source message a work order that can contain three different item types:

    1. Material
    2. Labor
    3. Others

Each of these types is realized via a different segment in the source document.



The target message only has one common structure containing all three different work order types. To make this exercise a little more interesting, we also have the following requirements for the target message:

    1. Not all material items of the source message should appear on the target message.
    2. In the target message we need to number the work order items. This number is not available in the source message.


2.1&nbsp The Source Structure



The structure of the source message is defined as in the following picture:




2.2&nbsp The Target Structure



The structure of the target message is defined as in the following picture:




3&nbsp A Solution Using a User Defined Function


To solve this problem for our specific example we need to take care of two issues:
    1. The target message needs to be set up to support the mapping from multiple source structures to one target structure. This can be done through the duplication of subtrees.
    2. The field mappings need to be defined such that all data are transferred correctly. The tricky part here is to get the counter of the work items work correctly.


3.1&nbsp Duplication of Subtrees



We have three sub-structures (Material, Labor, and Other) in the source message that needs to be mapped to the same structure (WorkItem) of the target message. Since the structure WorkItem is originally only displayed once in the graphical mapping tool, we only can realize the mapping from one source structure - unless we change the way the target message is displayed in the graphical mapping tool.


This can be realized by using the Duplication of subtrees functionality via the following steps:

  • Within the graphical mapping tool place your cursor on the target structure that need to be displayed multiple times (structure WorkList in our case).
  • Right mouse click on the selected structure.
  • Choose Duplicate Subtree.









    1. Repeat the previous steps until the display of the structure is duplicated the desired number of times (in our case we need to go through the process twice in order to get three occurences of the structure).




3.2&nbsp The Field Mappings



We need to create the field mappings for the node WorkItem and all the fields underneath. Since we had to duplicate this node twice, we have to do this mapping three times (once for each source structure).


3.2.1&nbsp Field Mappings Related to Source Structure Material



First we look at the field mappings that relate to the source structure Material.


3.2.1.1&nbsp Mapping for WorkItem



Based on the requirements only materials of the category Final should be mapped into our target structure.
Therefore the mapping for the structure WorkItem looks like in the picture below, where the following values need to be adjusted in the mapping:

    1. For field Category the context needs to be set to WorkOrder.
The property Value of the function Constant needs to be set to Final.







As we can see we first check if the Category of the segment Material is equal to Final and only then we create a node in our target message.



3.2.1.2&nbsp Mapping for ItemNo



The field ItemNo contains a line number for each work order item of the target message. To retrieve this number we need to count the work items and assign the appropriate number to this field.



Since we need to carry the number count over to the next message mapping (related to the next source structure), we can take advantage of the global container functionality available in the user defined functions.



For this solution we create an advanced user defined function indexGlobal

with the Cache set to Context and with one input parameter a.
The coding for this user defined function looks as follows:









Using this function the mapping for the node ItemNo looks like in the picture below, where the following values need to be adjusted in the mapping:
    1. For field Category the context needs to be set to WorkOrder.
The property Value of the function Constant needs to be set to Final.







As we can see the user defined function indexGlobal only counts the items that ultimately end up in our target message. In addition the object nextCount containing the next number to be used (4 in this particular case) is moved into the global container and available to be picked up with another call of this function.



3.2.1.3&nbsp Mapping for Type



This particular mapping is related only to items coming from the source structure Material. For all of these items the value of the field Type is Material, which can be realized with a simple mapping of a constant value:




</p>


3.2.1.4&nbsp Mapping for Description



The value for the description of items coming from the source structure Material comes from the source field MaterialID and can be realized with a simple mapping:




</p>


3.2.2&nbsp Field Mappings Related to Source Structure Labor



Now we look at the field mappings that relate to the source structure Labor.


3.2.2.1&nbsp Mapping for WorkItem



Since all items of the source structure Labor need to be moved to the target structure WorkItem, the mapping for this structure simply looks as follows:




</p>


3.2.2.2&nbsp Mapping for ItemNo



Since the user defined function indexGlobal stored the next number to be used as our counter in the global container we can simply use this function to continue with the numbering of our work items.



Since all items related to the source structure Labor are carried over to the target structure, the mapping looks simply as follows:








Note that the Display queue feature will not return the correct result since it cannot simulate the first call of the function indexGlobal.



3.2.2.3&nbsp Mapping for Type



This particular mapping is related only to items coming from the source structure Labor. For all of these items the value of the field Type is Labor, which can be realized with a simple mapping of a constant value:




</p>


3.2.2.4&nbsp Mapping for Description



The value for the description of items coming from the source structure Labor comes from the source field LaborID and can be realized with a simple mapping:




</p>


3.2.3&nbsp Field Mappings Related to Source Structure Other



Last we look at the field mappings that relate to the source structure Other.


3.2.3.1&nbsp Mapping for WorkItem



Since all items of the source structure Other need to be moved to the target structure WorkItem, the mapping for this structure simply looks as follows:




</p>


3.2.3.2&nbsp Mapping for ItemNo



Since all items related to the source structure Other are carried over to the target structure, the mapping is analogue to the mapping for the source structure Labor:








Note that the Display queue feature will not return the correct result since it cannot simulate the previous calls of the function indexGlobal.



3.2.3.3&nbsp Mapping for Type



This particular mapping is related only to items coming from the source structure Other. For all of these items the value of the field Type is Other, which can be realized with a simple mapping of a constant value:




</p>


3.2.3.4&nbsp Mapping for Description



The value for the description of items coming from the source structure Other comes from the source field ID and can be realized with a simple mapping:










4&nbsp A Solution Using Standard Functions Only



In the first solution we described the complete mapping of every single field. Now we only need to look at those fields that are different to the first solution. Everything else can be simply taken over.



Since we now want to offer a solution that only uses standard functions available in the graphical mapping tool, we only need to change the mappings for those fields that used the user defined function indexGlobal. These fields are


    1. Mapping of field indexNo related to source structure Material.
    2. Mapping of field indexNo related to source structure Labor.
    3. Mapping of field indexNo related to source structure Other.


Everything else in this solution is identical to the first solution.



4.1&nbsp Mapping of indexNo Related to Source Structure Material



The field ItemNo contains a line number for each work order item of the target message. To retrieve this number we need to count the work items and assign the appropriate number to this field.



One function to look at is the statistical function index. This function counts the line items within one context, but since not all of the material items are moved to the target message, this function does not give us the desired result. In our example we would need the following result for the number count:







The function index however returns the following result:








That means that the function index counts all occurences within the context, including the value SUPPRESS.




Another function to consider is the arithmetic function counter. This functions returns a counter that gets updated with each call of the function itself. As we can see in the picture below, it actually is possible to define a mapping for the node ItemNo using this function. In this mapping the following values need to be adjusted:


The property Value of the function Constant (that serves as input for function equalS needs to be set to Final.
The proproperty Value of the second function Constant can be set to any value.







You need to be aware that the result of the Display Queue can be erratic in this mapping since value of the function counter depends on the number of times this function is called. Since this may also depend on the context of the mapping (e.g. how often is the superior node being called) the result of the test tool Display queue can give an incorrect result.



4.2&nbsp Mapping of indexNo Related to Source Structure Labor



To derive the correct line numbers for the field ItemNo we need to the following:


  1. Get the total number of line items created in the previous block (from source segment Material).
  2. Number the line items created based on the source segment Labor.
  3. Adjust the numbering based on the number of line items already created.


This can be realized with a mapping as shown below where the following values need to be adjusted in the mapping:
    1. For field Category the context needs to be set to WorkOrder.
The property Value of the function Constant needs to be set to Final.







As we can see the function count gives us the correct number of line items created from the source structure Material, while the function add adds the two values in the proper way.



4.3&nbsp Mapping of indexNo Related to Source Structure Other



To derive the correct line numbers for the field ItemNo we need to the following:


  1. Get the total number of line items created in the first block from source segment Material (the portion circled in red of the mapping below).
  2. Get the total number of line items created in the second block from source segment Labor (the portion circled in blue of the mapping below).
  3. Number the line items created based on the source segment Other (the portion circled in green of the mapping below).
  4. Adjust the numbering based on the number of line items already created.


This can be realized with a mapping as shown below where the following values need to be adjusted in the mapping:
    1. For field Category the context needs to be set to WorkOrder.
The property Value of the function Constant needs to be set to Final.










2 Comments