Netweaver Gateway Development

How to get image through SAP Netweaver Gateway

How to get image through SAP Netweaver Gateway

System Requirements:  SAP Net weaver Gateway Release 2.0 Support package >= 05

Step By Step Procedure    : In this EPM model we are going to display employee image from the backend of the systemWe are using bapi_employee_get_list to get employee data .

Step 1 : Open SEGW  .

               Create a new project by clicking create button on the application tool bar provide to application details and click ok button.

Step 2: Expand the project , Right click on  DATA MODEL ->  CREATE -> ENTITY TYPE to create a entity type in data model

Step 3 : In the Create Entity Type popup window enter the entity type name and select the check box Create Related Entity Set and Press OK to continue.

Step 4:  In the Entity Type Detail screen, enter the ABAP structure type name as ZDEMO_S_IMAGE and SELECT CHECK BOX UNDER MEDIA (in order to make it a media entity ) column.

Step 5:  Save the service till now. Now add the properties to the entity type . To do so right cclick on entity type  (EmployeeData)->Import->Properties

Step 6:  In the import properties window select the EMPLOYEE_ID,FIRST_NAME,LAST_NAME , EMPLOYEE_PIC_URL and PICMIMETYPE fields and click on NEXT button.

Step 7:  In this window set EMPLOYEE_ID as key and press Finish . SAVE and press on Generate button to create DPC and MPC classes.

Step 8:  Clicking on media check box (in step -4)  is not enough to pass media . we need to redefine DEFINE in MPC extension class

Step 9: Now we need to implement EMPLOYEEDATASET_GET_ENTITYSET in DPC Extension class. Expand the service implementation node and right click on GET_ENTITYSET (Query)àGo To Workbench to implement the method

Step 10: Write the following code in EMPLOYEEDATASET_GET_ENTITYSET to get the details of employees with Employee’s picture URL and mime type.

Step 11: As of now we are ready to test the service. SAVE and GENERATE the service. Now to go to SERVICE MAINTANCE àSAP GATEWAY CLIENTàand press EXECUTE now you should be able to see output like below.

Step 12 : We have successfully got the image URL but to get the raw data we need to implement method GET_STREAM so we can use $value in the output URI to get the RAW data . Redefine the method in the DPC extension and write the code.

Step 13: Now test the service again by calling the service


You have successfully created and implemented service to get employee image from through SAP Netweaver Gateway

Please feel free to comment and give feedback

If you enjoyed this post, I’d be grateful if you’d help it spread by sharing.Thank you! See you soon


  1. Hello Toney,

    thank you for your post. I have a requirement for which i can’t unfortunately find a solution yet.
    I want to provide a ZIP file for downloading based on a complex data selection from the backend with a lot of filter parameters.
    Unfotunately your solution only works in combination with the get_entity method and $value request.
    My requirement is to provide a ZIP file based on the result of the get_entityset method with filter parameters which are not necessarily key attributes of the entity. I would appreciate your help a lot.

    Best Regards,

    1. Hi Eskender,
      Have you ever came across this thread scn discussion
      Since get_stream method doesn't allow multiple filters ,passing multiple filters through a string may be a useful workaround.
      hope this helps

  2. Hello Rajeesh,

    thank you for your reply. Yes, i think you are right. With the current URI convention it is probably the only option to do it.
    I found the method CL_CLB2_TOOLSO=>ODATA_FILTER2SELECT_OPTION for parsing the SearchString. It seems to work with a simple test. Although the method is not used by any other SAP program. Do you know whether there are any oficially released SAP classes for parsing OData strings?

    Best regards,

    1. Hi Eskender,
      For parsing query strings we can make use of parameter IO_TECH_REQUEST_CONTEXT.
      for example try below query:
      /sap/opu/odata/SAP/ZDEMO_READ_IMAGE_SRV/EmployeeDataSet('2')/$value?$filter=EmployeeId eq '01'
      you can access the filter query in the form of select options structure by using
      io_tech_request_context->get_filter( )->get_filter_select_options( ) method

    2. Hello Rajeesh,

      You just made my day. Thank you very much. I didn't expect I would find any other interfaces in the IO_TECH_REQUEST_CONTEXT object rather than the interface /IWBEP/IF_MGW_REQ_ENTITY in the method GET_STREAM. I wouldn't even call this solution a workaround. It is a confusing interface type in the GET_STREAM method but it is exactly what I was looking for.

      Thanks and regards,

    3. Hi Eskender,
      You are welcome


Powered by Blogger.