首页 > SAP > ABAP > Get employee image through SAP Netweaver Gateway
2019
08-29

Get employee image through SAP Netweaver Gateway

Hello everyone, in this SAP Netweaver Gateway tutorial, we will learn how to read/get image through SAP Netweaver Gateway from backend system using OData service These images can be of employee photo or product images etc.. Before proceeding further we assume you know how to build OData service, if not please check out our step-by-step tutorials here,which will give you good understanding of SAP OData service. So lets get started.

1.Supported System Version

SAP NetWeaver Gateway Release-采购向厂商下P/O之后,必须透过一定权限经由主管对此张P/O做 release后才能收料 2.0 Support Package >=05

2.Business Example

In SAPUI5 application, you want to display employee image (or) display product image.

3.Step-by-Step procedure to implement the service

In this example i am using Enterprise Procurement Model(EPM) model data to demonstrate the scenario and we are going to display the photo of employee from the backend system.We are using BAPI_EPM_EMPLOYEE_GET_LIST to get employee data.

1. Go to Gateway Service Builder, transaction code SEGW. Create a new project by clicking on the create button in the application toolbar, provide the project details and hit OK button.

2. Expand the project, Right click on the Data Model → Create → Entity Type to create an entity type in the OData service.

3. In the Create Entity Type popup window, enter the Entity Type Name and select the check box Create Related Entity Set to create a default entity set. Hit OK button to create entity type and entity set.

4. In the Entity Type detail screen, enter the ABAP structure type name as ZDEMO_S_IMAGE and select the check box under Media column.

Mandatory Note : A normal entity type will act as media entity type when you flag it is media by selecting the check box.

[adsenseyu1]

5. Save the service till now.Now add the properties to the  entity type.To do so right click on entity type → Import → Properties.

6. In the Import Properties window, select EMPLOYEE_ID, FIRST_NAME, LAST_NAME and EMPLOYEE_PIC_URL and PICMIMETYPE fields and click on Next button.

7. In the next window, select EMPLOYEE_ID as key and click Finish.Save and click on generate button to generate DPC and MPC classes.

8. Setting Entity Type as Media in the step-4 is not sufficient we also need to set manually via coding.To do so, go to the MPC extension class and redefine the method DEFINE and write the below code inside it.

8.Now we need to implement the method EMPLOYEEDATASET_GET_ENTITYSET in DPC extension class.Expand the Service Implementation node and right click on GetEntitySet(Query) → Go to Workbench to implement the method.

9.Write the below code in EMPLOYEEDATASET_GET_ENTITYSET to get the list of employees using BAPI with employee’s picture URL and mime type.

10. As of now we are ready to test the service.Save and generate the service and make sure that DPC and MPC extension classes are active. Go to transaction SAP Netweaver Gateway Client – /IWFND/GW_CLIENT to test the service.You should see the output like below.

11. We have successfully got the image URL in the output, but to get the raw data of the image we need to implement method GET_STREAM so that we can use $value in the output URI to get the raw data.Redefine the method in DPC extension class and write the below code.

12. Now test the service again by providing the URI as below

/sap/opu/odata/sap/ZDEMO_READ_IMAGE_SRV/EmployeeDataSet(‘2’)/$value

You have successfully created and implemented service by which you get employee image through SAP Netweaver Gateway. Stay tuned to us for more SAP Netweaver Gateway tutorials.

Please feel free to comment and let us know your feedback.

Thank you.

最后编辑:
作者:yangsen
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。