Start of Content Area

Function documentation removeContexts  Locate the document in its SAP Library structure

Use

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.

Example

In the example below, a list of debtors with a payment field containing one or more payments made for each debtor is to be transformed into a list that only contains payments made. The payments and the debtors also each have the attribute id to help identify them.

Source Structure (Left) and Target Structure (Right)

Field Name

minOccurs

maxOccurs

Field Name

minOccurs

maxOccurs

DebitorListMsg

1

1

AllDebtsMsg

1

1

  Debitor

0

unbounded

  debt

0

unbounded

    id (Attr)

 

 

    id (Attr)

1

1

    payment

1

unbounded

 

 

 

      id (Attr)

 

 

 

 

 

To delete the top hierarchy level Debitor, connect the element payment to the function removeContexts(). Specify as the target field the field into which you want the contents of payment to be copied, in this case debt.

Message Mapping Using removeContexts()

Target Field Mapping

/AllDebtsMsg=/DebitorListMsg

/AllDebtsMsg/debt=removeContexts(/DebitorListMsg/Debitor/payment)

/AllDebtsMsg/debt/id=/DebitorListMsg/Debitor/payment/id

Example

Source Instance

Result

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

<DebitorListMsg>

 <Debitor id="1">

   <payment id="1">
      50$
   </payment>
   <payment id="2">
      30$
   </payment>
   <payment id="3">
      90$
   </payment>

 </Debitor>

 <Debitor id="2">

   <payment id="4">
      150$
   </payment>

 </Debitor>

 <Debitor id="3">

   <payment id="5">
      1150$
   </payment>
   <payment id="6">
      2230$
   </payment>
   <payment id="7">
      3390$
   </payment>

 </Debitor>

</DebitorListMsg>

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

<ns0:AllDebtsMsg
 xmlns:ns0="workshopDemo">

 

   <debt id="1">
      50$
   </debt>
   <debt id="2">
      30$
   </debt>
   <debt id="3">
      90$
   </debt>

 

 

   <debt id="4">
      150$
   </debt>

 

 

   <debt id="5">
      1150$
   </debt>
   <debt id="6">
      2230$
   </debt>
   <debt id="7">
      3390$
   </debt>

 

</ns0:AllDebtsMsg>

 

 

 

 

End of Content Area