SAP GW Serie: Retrieve Attachment with GW (GET_STREAM )

SAP GW Serie: Retrieve Attachment with GW (GET_STREAM )

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. 

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 matadata 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 an attachment (file or picture) using SAP GW oData Service.

Get Employee’s Photo using SAP GW

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

Note that in order to read the 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:

/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

You may Also like: