Start of Content Area

Function documentation createIf  Locate the document in its SAP Library structure

Use

You use createIf() to create a tag in the target structure independently of a condition.

Example

In the example below, a mapping is required between two different formats for a list of messages. The attribute type is used in the source structure to classify the message as either internal (type="internal") or external (type="external"). However, in the target structure the tag internalRequest or externalRequest is used:

Source Structure (left) and Target Structure (right)

Field Name

minOccurs

maxOccurs

Field Name

minOccurs

maxOccurs

RequestListMsg

1

1

RequestListEIMsg

1

1

  request

0

unbounded

 internalRequest

0

unbounded

   type (Attr.)

1

1

   initiator

1

1

   creator

1

1

   contact

1

1

   contact

1

1

   issue

1

1

   description

1

1

 externalRequest

0

unbounded

     

   initiator

1

1

     

   contact

1

1

     

   issue

1

1

You use createIf() to create the respective target field independently of attribute type:

Message Mapping Using createIf()

Target Field Mapping

Value of Constant()

/RequestListEIMsg=/RequestListMsg

 

/RequestListEIMsg/internalRequest=
createIf(
  equalsS(
    removeContexts(/RequestListMsg/request/type),
   Constant()))

internal

/RequestListEIMsg/internalRequest/initiator=
/RequestListMsg/request/creator

 

/RequestListEIMsg/internalRequest/contact=
/RequestListMsg/request/contact

 

/RequestListEIMsg/internalRequest/issue=
/RequestListMsg/request/description

 

/RequestListEIMsg/internalRequest=
createIf(
  equalsS(
    removeContexts(/RequestListMsg/request/type),
   Constant()))

external

/RequestListEIMsg/externalRequest/initiator=
/RequestListMsg/request/creator

 

/RequestListEIMsg/externalRequest/contact=
/RequestListMsg/request/contact

 

/RequestListEIMsg/externalRequest/issue=
/RequestListMsg/request/description

 

Note

The function removeContexts() is required because the attribute type is mapped in place of the source field request. Therefore, there is no target field for request and no context in the target structure. However, the type queue has nevertheless saved the request context so that processing would terminate early if you did not delete this context.

Example

Source Instance

Result

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

<RequestListMsg>

  <request type="internal">

    <creator>
      creator1
    </creator>
    <contact>
      contact1
    </contact>
    <description>
       description1
    </description>

  </request>

  <request type="external">

    <creator>
      creator2
    </creator>
    <contact>
      contact2
    </contact>
    <description>
       description2
    </description>

  </request>

</RequestListMsg>

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

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

 <internalRequest>

    <initiator>
      creator1
    </initiator>
    <contact>
      contact1
    </contact>
    <issue>
      description1
    </issue>

 </internalRequest>

 <externalRequest>

    <initiator>
      creator2
    </initiator>
    <contact>
      contact2
    </contact>
    <issue>
      description2
    </issue>

 </internalRequest>

</ns0:RequestListEIMsg>

 

 

 

 

End of Content Area