SAP Netweaver Gateway and OData. Part XII. Media Handling using OData Gateways   

Media Handling using OData

Media Handling using OData-Gateways


The conundrum (confusion/difficulty) of handling media through gateway service is gone. If you have a requirement of showing PDF or sending images/music over the gateway, you can do it seamlessly. While in recent times we get a torrent of requirements of Smartforms printing, very fewer opportunities are there to pass image/music files. This article should give a fair idea about the tit-bits of handling PDF printing in the gateway.


Step-1: Create Entity to Handle Media Information

Create a gateway project (Follow the previous blogs for details of creating a project and subsequent actions). Create a separate entity to handle the media operations. Don’t forget to tick the ‘Media’ check box as this indicates the entity as media.

music in SAP
In figure ‘SoPrint’ entity is marked as Media.

Also Read: Using Media Queries in UI5 Application

Step-2: Generate the runtime artifacts

Generate the runtime artifacts of the project. All the required methods we will find in Data Provider Class and Model Provider Class. Remember we will start our development with Model Provider Class this time, unlike other CRUD operations. Let’s start with our development.

Step-3: Code in MPC

To make our media entity type work, we need to have some tweaks in MPC_EXT. Since media is a model attribute we need to explicitly redefine the DEFINE method in MPC_EXT.

media files in odata

Basic method coding is explained below. Remember, it is extremely important that you write the statement super->define( ) otherwise we would not be able to access the model object. From the MPC we want the entity “SoPrint” to work with. In my requirement, I need to have the ‘OrderNo’ property of the attribute ‘SoPrint’. You have to set the attribute as content type with set_as_content_type( ) method.

 Step -4: Create a Smartform to Print

Before we go and code in the DPC_EXT let’s create a Smartform which will simply show a Smartform with some text. Obviously, you will have your own Smartform with complex business logic and various importing parameters.  Our simple Smartform looks like below.

Also CheckExpose CDS Views as OData Service through Annotation

Step-5: Code in DPC_EXT

In DPC_EXT we have a separate method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM to handle the GET media operation. I know it is needless to copy the code for the readers of this blog as they have more acumen in doing the coding part compared to me.

Voila! You have done the required coding and you should be ready to test the solution.

URI: /sap/opu/odata/SAP/ZDEMO_GW_SRV/SoPrintSet(”)/$value

Note– You can pass any order no in the SoPrintSet attribute or the attribute keys you have used.

smartform in odata
Save or print the Smartform!

Also Read: Create your first Program in SAP HANA.

Tip of the day

In the DPC_EXT programming, you might face an issue of blank JOB_OUTPUT_INFO in Smartform calling function module, i.e. t_otf_from_fm will be blank.  I personally faced this problem and after a considerable amount of options found that the actual issue was with the DEFAULT output device configuration associated with my sap account. If you don’t have any output device configured in your account (can be checked through SU3 transaction) you will not get any value in JOB_OUTPUT_INFO table.

It is also important that you pass ls_control_parametersgetotf    =abap_true to get the other text format output.


So…Did you find this article useful?

Now we want to hear from you.

Do you think, this post is helpful?

Whether you feel positive or negative, in either case, please leave a quick comment below and help us improve.

Table of Content – SAP Netweaver Gateway & OData Services

SAP Netweaver Gateway and OData Services. Part I– Introduction
SAP Netweaver Gateway and OData Services. Part II– Create your first OData Service
SAP Netweaver Gateway and OData Services. Part III– Query Options in OData Service URI
SAP Netweaver Gateway and OData Services. Part IV– Association and Navigation in OData Service
SAP Netweaver Gateway and OData Services. Part V– CRUD Operations in OData Services
SAP Netweaver Gateway and OData Services. Part VI– Frequently Asked Questions
SAP Netweaver Gateway and OData Services. Part VII– Debugging, Trace, Cache Cleanup and F4 Help
SAP Netweaver Gateway and OData Services. Part VIII– SAP’s Love for OData – a Tale of the Friendly ABAPer
SAP Netweaver Gateway and OData Services. Part IX– How to Add Multiple Entities in One Operation in OData Service
SAP Netweaver Gateway and OData Services. Part X– How to Delete OData Service from Service Catalog?
SAP Netweaver Gateway and OData Services. Part XI– Query Options & HTTP Status Code Summary
OData Services and SAP Netweaver Gateway. Part XII– Media Handling using OData-GatewaysSAP Netweaver


Please enter your comment!
Please enter your name here