Use of Context Objects with Example

Context Objects are a great alternative to Xpath expressions in SAP PI/PO. When creating Xpath based (Content Based) Receiver Rules or Receiver Conditions in Integration Directory, sometimes rules can becomes unreadable and complex due to the long Xpaths. Context Objects allows us to represent a Xpath with easily readable Context Names and reuse them in Receiver Rules and Receiver Conditions.

SAP Versions used in the illustration:

  • SAP PO 7.5

Example Use of Context Object.

Lets assume we have a XML file sender and we want to create a Content Based Receiver Rules or a Condition based on Xpath ‘FlightBookingOrderRequest/AgencyData/AgencyID’.

If Xpath ‘FlightBookingOrderRequest/AgencyData/AgencyID’ equals to ‘AA’ receiver should be ‘Test_B’.

 

Step 1: Create Context Object for ‘AgencyID’.

Create Context Object and assign the Reference Type property based on the XML element. AgencyID is a String element, therefore we assign the reference Type of the Context Object as xsd:string.

Create Context Object with Reference Type xsd:String
Create Context Object with Reference Type xsd:String

 

Step 2: Assign Context Object to Outbound Service Interface.

Assign the Context Object created in step 1 to corresponding Xpath of the Message Type or External Definition in Outbound Service Interface. Make sure your Outbound Service Interface is of Interface Pattern ‘Stateless (XI30 – Compatible)’. Context Objects are only compatible with Interface Pattern ‘Stateless (XI30 – Compatible)’.

Assign Context Object to Outbound Service Interface. Only compatible with Interface Pattern 'XI30 - Compatible'
Assign Context Object to Outbound Service Interface

 

Use the drop down list to select the Context Object. Once Context Object is correctly assigned, it would be shown under Context Object Column with the data element.

Assignment of Context Object to Xpath element of Outbound Service Interface
Assignment of Context Object to Xpath element of Outbound Service Interface

 

Step 3: Use the Context Object in Integration Directory for Receiver Rule or Content Based Rule.

Now you can use Context Object ‘AgencyID’ instead of full Xpath for Content Based Receiver Determination in Integration Directory. Use the down down list to select the Context Objects created in Enterprise Service Repository (ESR).

If you cannot view the Context Objects created in ESR in ID, make sure you have assigned the Context Object assigned to the Outbound Service Interface and Interface is in Interface Pattern XI30 – Compatible as shown in Step 2.

Use Context Object AgencyID in Content Based Condition in Expressions Editor
Use Context Object AgencyID in Content Based Condition in Expressions Editor

 

Condition Editor with Context Object
Condition Editor with Context Object

 

Receiver Determination with Context Object based condition
Receiver Determination with Context Object based condition

Please leave a comment if you have any questions on Context Objects.

TECH GADGETS I USE EVERY DAY

These are some of the tech gadgets I use every day. If you make a purchase through these links I will earn a small comission at absolutely no extra cost to you.

11 thoughts on “Use of Context Objects with Example

    • Isuru Fernando says:

      Hi Sai, I will try to include a post about Java Mappings in the future. Just to give a basic idea, java mapping is mostly used for complex mapping which cannot be handled by graphical mapping alone or if the performance is a main priority. Also if you have a complex mapping, you can handle the complex logic first using a java mapping and then do a graphical mapping as the step 2.

      • gupta says:

        Thank you Sir eagerly waiting for some more interesting blogs.please cover all the topics which are difficult to understand in SAP PO/PI.

  1. Kishore says:

    Hi Fernando,

    Can we use Context Objects for two fields with the same Service Interface?
    Example: I want to determine Receiver when A=1 and B=2 with very long Xpath, can I use Context Objects in this requirement.

    Best Regards,
    Kishore.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest tips and tricks on SAP!