Blog > SAP CPI: Control your messages with custom header

SAP CPI: Control your messages with custom header

CPI_custom_header_Halicki
Andrzej Halicki SAP Integration Consultant
icon__calendar 2019-08-12

Introduction

Recently I encountered a basic router scenario. However the information I could use as a condition was not included in the message itself. I had to pass it to CPI, but didn’t want to enrich the message and mess it up. I figured out that custom header would be the great solution, however as it occurred, it wasn’t so easy (now it is of course).

Steps

So you would like to pass a custom header to CPI.

SoapUI

In SoapUI you would pass it on like this:

SAP CPI custom header SoapUISoapUI SAP CPI

 

ABAP

In ABAP it is possible thanks to the best library cl_http_client:


    lo_httpclient->request->set_header_field(
        name  CustomHeader
        value 100 ).

SAP CPI

This is the most important step – you need to enable custom headers so CPI can accept them. Just go to your iFlow, click on the white space behind the flow and you will be displayed a “Integration Flow” menu. Go to “Runtime Configuration” and fillAllowed Header(s)”.

SAP cpi integration flow

 

You could also type *. In this case CPI would accept all incoming headers.

Read your header

Now your custom header will be visible in CPI. In order to read the value use the expression

${header.CustomHeader}. Of course you could get access to any header using such expression. In my case I would use it in router step.

 

SAP CPI read header

Summary

I think it is a smarter and safer way to control your message flow. Instead of messing with payload you “hide” your controls in different part of message exchange. What do you think?

 

Andrzej Halicki SAP Integration Consultant
Andrzej Halicki is an SAP integration consultant and developer. He has strong experience in ABAP development across local and international projects. Andrzej works with the latest solutions like ABAP for HANA and Cloud Platform Integration. Author of many technical articles that are available online in the SAP Community and Int4 website.

Contact us

If for any reason, the thought of reaching out to us has crossed your mind, then by all means do not hesitate to get in touch with us, as we are more than happy to put to rest all of your concerns.