Skip to Content
Technical Articles
Author's profile photo Francois Apfelbacher

Download File through NetWeaver Gateway with OData Version 4

Introduction

In this blog post I would like to show you how you can download a file through NetWeaver Gateway with OData Version 4. The next sections contain following topics:

  1. preliminary work
  2. implementation of a model provider
  3. implementation of a data provider
  4. register and publish OData Service
  5. test
  6. conclusion

In my case the system conditions were during the implementations as follows:

Component Release SP-Level Support Package Short Description
SAP_GWFND 754 0000 SAP Gateway Foundation
SAP_UI 754 0002 SAPK-75402INSAPUI User Interface Technology

Embedded Gateway Scenario

Preliminary work

Before we start with the OData Implementation, we will create a data base table.

Data%20Base%20Table%20-%20ZDEMO

Data Base Table – ZDEMO

  • NAME is the name of the file
  • CONTENT is from type RAWSTRING and contains the content of the file
  • CONTENT_TYPE is our MIME_Type

Afterwards I created a structure

Structure%20-%20ZSDEMO_ODATAV4

Structure – ZSDEMO_ODATAV4

In a separate blog post I will explain you how you can fill this table via POST URL Request which generates an Adobe Form. We assume that we have already an entry. In our example it is a PDF File.

PDF%20File%20in%20ZDEMO

PDF File in ZDEMO

OData V4 Model Provider Class

OData Version 4 Model will be implemented by creating a class that inherits from /IWBEP/CL_V4_ABS_MODEL_PROV.

Model%20Provider%20Class

Model Provider Class

The Method /IWBEP/IF_V4_MP_BASIC~DEFINE will be redefined.

Model%20Provider%20Class%20-%20Define%20Method

Model Provider Class – Define Method

I recommend calling for each entity an own private method.

Model%20Provider%20Class%20-%20Define%20File%20Download%20Method

Model Provider Class – Define File Download Method

We use here the type Stream for property CONTENT.

That’s all. The Model for File Download is finished.

OData V4 Data Provider Class

OData Version 4 Data Provider will be implemented by creating a class that inherits from /IWBEP/CL_V4_ABS_DATA_PROVIDER.

Data%20Provider%20Class

Data Provider Class

In this class we redefine the method /IWBEP/IF_V4_DP_BASIC~READ_ENTITY

Data%20Provider%20Class%20-%20Read%20Entity%20Method

Data Provider Class – Read Entity Method

Delegate to a private Method

Data%20Provider%20Class%20-%20File%20Download%20Method

Data Provider Class – File Download Method

This method reads the entry of our data base table ZDEMO according to key which comes from the URL Request.

The OData Version 4 Implementation for File Download is finished. Now we have to register the Service and publish it.

Register and Publish OData Service

Two activities are needed before you can call the URL and test the request. Register the service and publish it.

Register Service Group and assign service

Call Transaction Code /IWBEP/V4_ADMIN for creating a Service Group. First Add a Register Group.

Register%20Service%20Group

Register Service Group

And register the service

Register%20Service%20-%20Part%20I

Register Service – Part I

Register%20Service%20-%20Part%20II

Register Service – Part II

Here we enter our created classes. Finally, we assigned it to our Service Group

Register%20Service%20-%20Part%20III

Register Service – Part III

Here the result:

Register%20Service

Register Service

Publish Service

Call Transaction Code /IWFND/V4_ADMIN to publish the Service Group that we created in Step 4

Publish%20Service

Publish Service

Mark the entry and publish it. Result:

Published%20Service

Published Service

Test

Now let test our File Download Demo. For that Mark Line 2 and execute “Service Test”. SAP Gateway Client will be opened. Type request FileDownloadSet(0050560C-0A03-1EEB-98CC-EA223BCD9E8D)/Content

SAP%20Gateway%20Client%20-%20Test

SAP Gateway Client – Test

PDF File opened

Conclusion

This example shows you how you can implememt a file download through SAP Gateway with OData Service 4.0. The crunching point is the use of EDM Data Type stream in the model provider class.

I hope you liked it.

Please, let me know what you are thinking about it.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.