Skip to end of metadata
Go to start of metadata

Author: David Pietroniro
Submitted: 09/12/2008
Related Links:

Description

In this I will show how to map an item table where each item can have zero or three taxes. The result XML must have a structure where the item number and its taxes must be grouped in one node.
So, the structures that we have are:

And the result structure must be:

Example:

The item table has three items and the item one has the tax_1 and tax_3, the item two has the tax_1, tax_2 and tax_3 and item three doesn't have any tax.

ITEM_TAB

1

2

3

ITEM_EXT

NUMBER

TAX_NAME

VALUE

1

TAX_1

100

1

TAX_3

200

2

TAX_2

300

2

TAX_1

400

2

TAX_3

500

And the result XML must be:

ITEM

NUMBER

1

TAX_VALUE1

100

TAX_VALUE3

200

ITEM

NUMBER

2

TAX_VALUE1

400

TAX_VALUE2

300

TAX_VALUE3

500

ITEM

NUMBER

3

For this was necessary to create the following objects.

Data types:

The item and item extension:

The result:

Message types

For each data type was created a message:

  • MM_OUT for the DT_OUT data type;
  • MM_RESULT for the DT_RESULT data type.

Message mappings

It was created the following message mapping:

And the field mappings:

User-defined advanced function

It was created the following function:

public void my_function(String[] a,String[] b,String[] c,String[] d,String[] e,ResultList result,Container container){
  for (int i=0; i<a.length; i++) {
    boolean found = false;
    int j = 0;

    for (j=0; j<b.length; j++ ) {

      if (a[i].equals(b[j]) && c[j].equals(e[0])) {
        found = true;
        break;
      }
    }
    if (found == true)
      result.addValue(d[j]);
    else
      result.addSuppress();
  }
}

This function has the following importing attributes:

  • a - This is the NUMBER queue from the ITEM_TAB context ;
  • b - This is the NUMBER queue from the ITEM_EXT context;
  • c - This is the TAX_NAME queue;
  • d - This is the VALUE queue;
  • e - This is a constant that corresponds to the tax to be mapped.

So this function returns a queue with the values from the element VALUE considering the item number and the tax name.

Testing

To test the message mapping was created the following instance:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:MSG_OUT xmlns:ns0="http://test.com.br/item">
   <item_tab>
      <number>1</number>
   </item_tab>
   <item_tab>
      <number>2</number>
   </item_tab>
   <item_tab>
      <number>3</number>
   </item_tab>
   <item_ext>
      <number>1</number>
      <tax_name>TAX_1</tax_name>
      <value>100</value>
   </item_ext>
   <item_ext>
      <number>1</number>
      <tax_name>TAX_3</tax_name>
      <value>200</value>
   </item_ext>
   <item_ext>
      <number>2</number>
      <tax_name>TAX_2</tax_name>
      <value>300</value>
   </item_ext>
   <item_ext>
      <number>2</number>
      <tax_name>TAX_1</tax_name>
      <value>400</value>
   </item_ext>
   <item_ext>
      <number>2</number>
      <tax_name>TAX_3</tax_name>
      <value>500</value>
   </item_ext>
</ns0:MSG_OUT>

And the result is:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:MSG_RESULT xmlns:ns0="http://test.com.br/test">
   <item>
      <number>1</number>
      <tax_value1>100</tax_value1>
      <tax_value3>200</tax_value3>
   </item>
   <item>
      <number>2</number>
      <tax_value1>400</tax_value1>
      <tax_value2>300</tax_value2>
      <tax_value3>500</tax_value3>
   </item>
   <item>
      <number>3</number>
   </item>
</ns0:MSG_RESULT>

You can get more information about message mappings in SAP Exchange Infrastructure - Graphical Mapping - Advanced.