Start of Content Area

Function documentation removeContexts  Locate the document in its SAP Library structure

Use

You can use removeContext() to delete all the top contexts for an element. This deletes 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 following example, a list of debtors that lists one or more payments made in the field payment is to be transformed into a list that only contains payments made. The payments and the debtors also have the attribute id in each case 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 in which you want the contents of payment to be copied to, 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