Entering content frameFunction documentation removeContexts Locate the document in its SAP Library structure

Use

You use removeContext() to delete the top context for an element. The top hierarchy level is therefore deleted.

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>

 

 

 

 

Leaving content frame