Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
Active Participant

I started off with GW learning as part of my new UI5 project .As you all know Gateway is a framework to expose the rich backend   SAP data  in the form of ODATA protocol.I am not going to give so many motherhood statements as it is well documented elsewhere

Now .. The Problem Statement

During so many scenarios, I came across a common requirement to pass some HTTP request header parameters .

To tell one sample scenario, there is an entity type Exemption .This entity type Exemption can be 'Requested'   or 'Approved' from a business perspective from a UI application . The 'Request' or 'Approve' action can be done in batch for the Exemption record .If we model this as a property(I will call it the BusinessAction) in entity type Exemption, the problem is that the payload will have to repeat this property for all the records that it is sending. :sad: . All the more from a modelling perspective it does look silly to have BusinessAction in that entity type :razz:

Then I came across a blog from ron.sargeant2. This involved changes to both the GW Hub system layer and the backend BEP layer. In our case we did not have developer authorisation in GW hub system . The GW hub system is just used for registration of backend service..

So whats the option we have ??

Welcome Mr Trial & Error ...

I just tried a sample scenario where in I send a sample HTTP request header parameter and see how does it reach our Broker GW and then ultimately to Uncle backends  home..

I tired to send a Custom parameter via request header parameter for a sample Entity type.Now I put the break point in the our DPC class corresponding entity GET_ENTITYSET.The values

This part of debugging is called 'Happy Debugging'

.I was happy to see the  values appear in the importing parameter io_tech_request_context :lol:

When I checked in debugger the io_tech_request_context is of type /IWBEP/CL_MGW_REQUEST with protected attribute MR_REQUEST

The attribute MR_REQUEST has deep structure TECHNICAL_REQUEST which has attributes like below and has a attribute REQUEST_HEADER

When we went inside we have the request header parameter that  we set on the journey...

Now I thought its just a matter of reading the values .Its matter of reading values from io_tech_request_context->mr_request->request_header...(So simple)

This part of debugging is called 'Not so happy Debugging'

I realised the attribute MR_REQUEST is a protected attribute and cannot be accessed by simple assignment to local variable. :cry:

So Whats the workaround?

I made a subclass of the standard class /IWBEP/CL_MGW_REQUEST..

I  wrote a method GET_REQUEST_HEADER_VALUE where in takes the request context object, header parameter and returns back the value

The code inside the method for reading the  header parameter is as below


         lt_request_headers TYPE tihttpnvp,

         ls_request_header like LINE OF lt_request_headers.

     lo_request = io_tech_request_context->mr_request.

     lt_request_headers = lo_request->technical_request-request_header.

     READ TABLE lt_request_headers into ls_request_header with key name = iv_request_parameter.

     if sy-subrc eq 0.

       rv_request_value = ls_request_header-value .


Reading the value

Now I just need to use the utility method  GET_REQUEST_HEADER_VALUE of subclass to get the custom parameter value.

Use the following code in your CRUDQ method to read the request header

DATA:     lo_tech_request     TYPE REF TO /iwbep/cl_mgw_request,

               lo_tech_request_sub TYPE REF TO zcl_gw_mgw_request,

               lt_headers          TYPE tihttpnvp,

               lv_request_header type string,

               lv_request_header_value type string.


**Casting and Assigning  importing parameter to local variable

  lo_tech_request ?= io_tech_request_context.

***Instantialte subclass with some dumy header parameters

CREATE OBJECT lo_tech_request_sub


         it_headers = lt_headers..

lv_request_header_value  = lo_tech_request_sub->get_request_header_value( EXPORTING io_tech_request_context = lo_tech_request

                                                                                                               iv_request_parameter = 'customparameter).

Testing the code -Final showdown..

Now in GW client in the GW hub system I run the below URL with HTTP header request custom parameters

Now in the debugger of GET_ENTITYSET...