SAP GW Serie: Retrieve Attachment with GW (GET_STREAM )

How to Retrieve Attachment with GW ?
The OData Channel provides a generic solution for exposing binary data that is stored in an SAP Business Suite backend system and should be accessible using a media link entry.

Here the definition of the DPC method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM in order to retrieve the media.

Also, you will find some useful sample of GET_STREAM method implementation. 

Retrieve Attachment with GW : Signature of GET_STREAM

  • IV_ENTITY_NAME Importing STRING
  • IV_ENTITY_SET_NAME Importing STRING
  • IV_SOURCE_NAME Importing STRING
  • IT_KEY_TAB Importing /IWBEP/T_MGW_NAME_VALUE_PAIR
  • IT_NAVIGATION_PATH Importing /IWBEP/T_MGW_NAVIGATION_PATH
  • IO_TECH_REQUEST_CONTEXT Importing /IWBEP/IF_MGW_REQ_ENTITY
  • ER_STREAM Exporting DATAES_RESPONSE_CONTEXT Exporting /IWBEP/IF_MGW_APPL_SRV_RUNTIME=>TY_S_MGW_RESPONSE_ENTITY_CNTXT

The last parameter ER_STREAM with contain the Attachment.

/IWBEP/ Prerequis for GET_STREAM

In order to use an entity as Stream, you should make some change in the metadata definition of the service in order to set the Entity Type to Stream.

Go to your Service’s MPC_EXT class and redefine your DEFINE method.
You have to set The property for the EntityType to ‘ContentType’.
Use then lo_property->SET_AS_CONTENT_TYPE.

Here a sample code of how to set the entity EmployeePhoto to Stream in order to send Employee’s photo through SAP GW oData Service: (source)

Most common Method GET_STREAM Sample Implementations

Here a sample implementation of the the method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM to Retrieve Attachment (file or picture) using SAP GW oData Service.

Retrieve Attachment (Employee’s Photo) using SAP GW

Maybe the most famous scenario for GET_STREAM method is to retrieve attachment (Photo) of SAP Employee.
Here the implementation of GET_STREAM for EmployeePhoto : (source)

Note that in order to retrieve attachment (photo, file), add $value to service [/getPhotoSet(EmpId=’1′)/$value]

Media Link in SAP GW

The following is an example of the source code for the software component IW_BEP for the redefined method DEFINE of class/IWBEP/CL_MGW_ABS_MODEL and /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM of class /IWBEP/CL_MGW_ABS_MODEL.

Redefined method DEFINE of class /IWBEP/CL_MGW_ABS_MODEL to retrieve attachment in SAP GW

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM of class /IWBEP/CL_MGW_ABS_MODEL:

Source: SAP Gateway Foundation (SAP_GWFND): Media Links

Going Further with SAP Gateway Odata Service