Friday 16 July 2021

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

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.

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
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

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
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.

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
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.

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
Model Provider Class

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

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
Model Provider Class – Define Method

I recommend calling for each entity an own private method.

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
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.

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
Data Provider Class

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

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
Data Provider Class – Read Entity Method

Delegate to a private Method

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
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.

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
Register Service Group

And register the service

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
Register Service – Part I

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
Register Service – Part II

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

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
Register Service – Part III

Here the result:

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
Register Service

Publish Service

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

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
Publish Service

Mark the entry and publish it. Result:

SAP ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
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 ABAP Exam Prep, SAP ABAP Development, SAP NetWeaver Gateway, SAP ABAP Career, SAP ABAP Tutorial and Materials, SAP ABAP Prep
SAP Gateway Client – Test

PDF File opened

No comments:

Post a Comment