Вы находитесь на странице: 1из 58

Getting Started Newsletters

Hi, Guest

Log On

Search the Community

Join Us

Products

Services & Support

About SCN

Downloads

Industries

Training & Education

Partnership

Developer Center

Lines of Business

University Alliances

Events & Webinars

Innovation

More blog posts in

Activity

Communications

Actions

Browse

SAP Gateway

Actions

SAP Gateway

Lets code CRUDQ and Function Import operations in


OData service!
Previous
Next

Login to follow, like, comment, share and


bookmark content.

Login

Posted by Chandrashekhar Mahajan in SAP Gateway on Mar 6, 2014 7:42:38 AM


Share

Store

Like

Introduction
Scenario
Procedure
Coding
1) Query Operation
2) Read Operation
3) Create Operation
4) Update Operation
5) Delete Operation
6) Function Import
Save web pages as PDF manually or automatically with PDFmyURL

postpost

Filter Blog
By author:

Register

Closing Remarks
By date:

Introduction
In this blog I will explain creation of simple SAP NW GW OData service which will implement Create, Read, Update,
Delete, Query and Function Import operations.

By tag:
abap integrationgateway json mobile mobility netweaver

netweaver_gateway
Just to make it very simple, I will just have single entity and entity set. Here I will perform these operations on Z table. In
real scenarios, you will use BAPIs. RFCs to perform these operations.
I recommend to read below documents and SAP documentation for deep understanding.
How to Develop a Gateway Service using Code based Implementation by
Andre Fischer
How to Develop Query Options for an OData Service Using Code-Based Implementationby
Andre Fischer
How to Write an OData Channel Gateway Service. Part 2 - The Runtime Data Provider Class
SAP Help - SAP NetWeaver Gateway Foundation Developer Guide - SAP NetWeaver Gateway Foundation
(SAP_GWFND) - SAP Library
Code Snippet - 3.2 Data Provider Class (DPC) - SAP NetWeaver Gateway Foundation (SAP_GWFND) - SAP Library

odata openui5 rest

sap_mobile_developer_center

sap_mobile_platform
sap_netweaver_gateway sapui5
smp

Recent Posts
Step-by-Step Add a New Entity with Association and
Implement it

Scenario

Sneak Peek into SAP Gateway and API management


Program at SAP TechEd, 2015 at Las Vegas on Oct
19-23, 2015

We have User information table as ZUSERINFO containing below fields

Ogee plug in Eclipse for OData model consumption


from SAP Netweaver Gateway system
Pagination decrypted(Part 2).. Serverside paging
GW100 - SAP Gateway - Building OData Services
Pagination decrypted...
Trusted RFC creation between Gateway (Front End)
and ECC (Back end) servers
How to find OData performance trace and payload
trace functionality
Upcoming SAP CodeJam in Freiburg about SAP
Gateway
oData service, reload metadata error after DDIC
structure field delete - cleanup metadata cache

Incoming Links
Save web pages as PDF manually or automatically with PDFmyURL

Now let's create OData service which will insert, read, delete, update and query this table along with one custom
operation (UsersByCountry) as function import.

Re: How to fetch Data from backend system


through Fiori app?
Re: UI5 and OData using RFC

From an ABAPer perspective, This is what meant by OData operations.


OData
Operation

HTTP
Method

What it meant to an ABAPer

Re: oDATA invalid key predicate


Re: Odata POST operation
Function Import POST with multi line text

Create

POST

Insert <table> from <workarea>

Read

GET

Select Single * From <table> into <workarea>

Update

PUT/PATCH Update <table> set <workarea>

Delete

DELETE

Delete from <table>

Query

GET

Select * From <table> Into Table

Function
Import

GET/POST

Everything covered by GET and POST. But only use if scenario does not
fit into CRUDQ operations.

We can correlate Entity Set as Table Type, Internal table and Entity to work area, structure!
Entity Set

Table Type or Internal Table

Entity

Structure or Work Area

Procedure
Lets go to transaction SEGW and create project as ZUSERINFO.

Now right click on Data Model and Import --> DDIC Structure option, it will display popup window. Provide DDIC
Save web pages as PDF manually or automatically with PDFmyURL

Re: Hi... I am a beginner in gateway.. please


advise how to start

structure name. In this case table name ZUSERINFO. It will propose field and key mapping as well as object name
which will be your entity name.

We will ignore MANDT as key field and also overwrite object name. I want my field names in upper camel case format
so I will change it accordingly. Lets call entity type as User. It will look as below. Press enter.

finally our entity type User will look as below.

Now lets create Entity Set as UserCollection (or UserSet or Users). You can refer Creating High-Quality OData
Services - SAP NetWeaver Gateway Foundation (SAP_GWFND) - SAP Library
I will go with UserCollection as my entity set name.
Save web pages as PDF manually or automatically with PDFmyURL

Right click folder name Entity Sets and click create. Provide entity set name as UserCollection and Entity Type name
as User. It will display as below.

Now lets generate runtime artifacts. Click on generate runtime objects button. It will display popup as below. Keep the
default class names as-is and click on enter button.

On successful generation, you will see this kind of message log and generated artifacts. 4 classes will get generated. 2
for Data provider and 2 for Model provider.

Save web pages as PDF manually or automatically with PDFmyURL

Now register your service under service Maintenance folder. Click on Register button. Keep default values as-is and
hit enter button.

On successful registration, click Maintain button. This will open service catalog window along with option to call
Gateway Client. Click on Gateway Client button to test the service. (you can also call transaction /IWFND/GW_CLIENT
to open SAP NW Gateway client)
Append $metatda to base service URL and press execute button. If everything is fine then you will HTTP Response as
Save web pages as PDF manually or automatically with PDFmyURL

below. Metadata provides information such as Entity type, key property, properties and Entity Set name.

So far we just defined single entity type and entity set. Now its time to code CRUDQ and function import methods.

Coding
There is no specific order to implement these methods but it is always good to 1st implement query and read operation
as for Create and Update, you will need request data which you will get if you already have query/read implemented.
1) Query Operation
First we will start implementing query operation. Before that, I will add one record in my ZUSERINFO table as

Save web pages as PDF manually or automatically with PDFmyURL

Now open Runtime artifacts folder and right click on Class ZCL_ZUSERINFO_DPC_EXT and select Go to ABAP
Workbench option. Select edit mode and redefine method USERCOLLECTION_GET_ENTITYSET.

In the simplest form, this is what minimal coding will look like in GET_ENTITYSET method.
METHOD usercollection_get_entityset.
DATA: lt_userinfo TYPE TABLE OF zuserinfo,
ls_userinfo LIKE LINE OF lt_userinfo,
ls_entity

LIKE LINE OF et_entityset.

*Get data from ZUSERINFO table


SELECT * FROM zuserinfo INTO TABLE lt_userinfo.
*Fill ET_ENTITYSET
LOOP AT lt_userinfo INTO

ls_userinfo .

ls_entity-userid
= ls_userinfo-userid.
ls_entity-firstname = ls_userinfo-firstname.
ls_entity-lastname = ls_userinfo-lastname.
ls_entity-email
ls_entity-phone
ls_entity-country

= ls_userinfo-email.
= ls_userinfo-phone.
= ls_userinfo-country.

APPEND ls_entity TO et_entityset.


ENDLOOP.
ENDMETHOD.

We are selecting all data from table ZUSERINFO and appending the result to exporting parameter ET_ENTITYSET.
Now you can go to GW client transaction and execute URI /sap/opu/odata/sap/ZUSERINFO_SRV/UserCollection
Save web pages as PDF manually or automatically with PDFmyURL

which will display one record which we already added into Z table.

Observe the method signature. put external breakpoint in method and execute query. You will find important
information in method parameters in debugging mode.
Below table will provide brief explanation of method parameters, alternative approach to get the value of those method
parameters. Last column specifies if we need to code to implement query operation.
Here IO_TECH_REQUEST_CONTEXT refers to /IWBEP/IF_MGW_REQ_ENTITYSET
OData Query

Alternative way to get the


value

Method Parameter

Coding
required to
implement
Query
Operation

UserCollection?$filter=UserID
eq '123' and LastName eq
'Mahajan'

IT_FILTER_SELECT_OPTIONS DATA: my_filter_options TYPE


and IV_FILTER_STRING
/iwbep/t_mgw_select_option,
my_filter_string TYPE string.

Save web pages as PDF manually or automatically with PDFmyURL

Yes

my_filter_options =
io_tech_request_context>get_filter( )>get_filter_select_options( ).
my_filter_string =
io_tech_request_context>get_filter( )->get_filter_string( ).
UserCollection?
$select=FirstName,LastName

No method parameter

data: my_select_fields type


No
/iwbep/t_mgw_tech_field_names.
my_select_fields =
io_tech_request_context>get_select( ).

UserCollection?
IT_ORDER
$orderby=FirstName,LastName

data: my_orderby_fields type


/iwbep/t_mgw_tech_order.

OR

my_orderby_fields =
io_tech_request_context-

Yes

>get_orderby( ).
UserCollection?
$orderby=FirstName
desc,LastName desc
UserCollection?search='test'

IV_SEARCH_STRING

data: my_search_string type

Yes

string.
my_search_string =
io_tech_request_context>get_search_string( ).
UserCollection?$top=1

IS_PAGING-TOP

data: my_top type string.


my_top =
io_tech_request_context-

Yes

>get_top( ).
data: my_skip type string.
my_skip =
io_tech_request_context>get_skip( ).
In case if we had association
and navigation between 2
entities

IT_NAVIGATION_PATH

DATA: my_nav_path type


/iwbep/t_mgw_tech_navi.
my_nav_path =
io_tech_request_context>get_navigation_path( ).

Save web pages as PDF manually or automatically with PDFmyURL

Yes

2) Read Operation
Now lets implement GET_ENTITY method. Go to method USERCOLLECTION_GET_ENTITY and redefine it. Below is
the minimal code that we need to have in this method.
We need to read the key values passed from query URI and then fill the export parameter ER_ENTITY.
METHOD usercollection_get_entity.
DATA:

ls_key_tab
TYPE /iwbep/s_mgw_name_value_pair,
lv_userid
TYPE zuserinfo-userid,
ls_userinfo TYPE zuserinfo.

*Get the key property values


READ TABLE it_key_tab WITH KEY name = 'UserID' INTO ls_key_tab.
lv_userid = ls_key_tab-value.
*Get the single record from ZUSERINFO and fill ER_ENTITY
SELECT SINGLE * FROM zuserinfo INTO ls_userinfo WHERE userid = lv_userid.
IF sy-subrc = 0.
er_entity-userid
= ls_userinfo-userid.
er_entity-firstname = ls_userinfo-firstname.
er_entity-lastname
er_entity-email
er_entity-phone
er_entity-country
ENDIF.

= ls_userinfo-lastname.
= ls_userinfo-email.
= ls_userinfo-phone.
= ls_userinfo-country.

ENDMETHOD.

Here IO_TECH_REQUEST_CONTEXT refers to /IWBEP/IF_MGW_REQ_ENTITY


OData Query

Method Parameter

Alternative way to get the


value

Coding
required
to
implement
Query
Operation

UserCollection(UserID='Test') IT_KEY_TAB

DATA: lt_keys TYPE

OR UserCollection('Test'

/iwbep/t_mgw_tech_pairs.

Save web pages as PDF manually or automatically with PDFmyURL

Yes

lt_keys =
io_tech_request_context>get_keys( ).

In case if we had association IT_NAVIGATION_PATH DATA: my_nav_path type


and navigation between 2
entities

Yes

/iwbep/t_mgw_tech_navi.
my_nav_path =
io_tech_request_context>get_navigation_path( ).

UserCollection('Test')?
No
$select=FirstName,LastName

DATA: my_select_fields TYPE


No
/iwbep/t_mgw_tech_field_names.
my_select_fields =
io_tech_request_context>get_select( ).

UserCollection('Test')?
$format=json

No

No

No

Also note that you cannot use system query options else you will get an error as System query options
'$orderby,$skip,$top,$skiptoken,$inlinecount,' are not allowed in the requested URI
3) Create Operation
Now we will focus on create operation by redefining method USERCOLLECTION_CREATE_ENTITY. Below is the
code that will perform POST operation.
Here we are reading the request data and then filling the exporting parameter ER_ENTITY.
METHOD usercollection_create_entity.
DATA: ls_request_input_data TYPE zcl_zuserinfo_mpc=>ts_user,
ls_userinfo TYPE zuserinfo.
* Read Request Data
Save web pages as PDF manually or automatically with PDFmyURL

io_data_provider->read_entry_data( IMPORTING es_data = ls_request_input_data ).


* Fill workarea to be inserted
ls_userinfo-userid
= ls_request_input_data-userid.
ls_userinfo-firstname = ls_request_input_data-firstname.
ls_userinfo-lastname = ls_request_input_data-lastname.
ls_userinfo-email
= ls_request_input_data-email.
ls_userinfo-phone
= ls_request_input_data-phone.
ls_userinfo-country

= ls_request_input_data-country.

* Insert Data in table ZUSERINFO


INSERT zuserinfo FROM ls_userinfo.
IF sy-subrc = 0.
er_entity = ls_request_input_data. "Fill Exporting parameter ER_ENTITY
ENDIF.
ENDMETHOD.
To test POST operation, 1st execute GET operation and then press Use as Request button which will copy the
response to request window and then select operation POST and execute.
In case you execute GET operation i.e. GET_ENITITYSET and then try to perform POST operation then you will get
below kind of error. Hence make sure that you execute GET to read single entity i.e. GET_ENTITY operation and then
perform POST.

Save web pages as PDF manually or automatically with PDFmyURL

So correct steps are,


1) Execute GET to read single entity /sap/opu/odata/sap/ZUSERINFO_SRV/UserCollection('Test')
2) Click Use as Request button
3) Update your request properties.
4) Select HTTP method as POST
5) Query as /sap/opu/odata/sap/ZUSERINFO_SRV/UserCollection and execute

Here IO_TECH_REQUEST_CONTEXT refers to /IWBEP/IF_MGW_REQ_ENTITY_C


OData Query

Method Parameter

Coding
required
to
implement
Query
Operation

/sap/opu/odata/sap/ZUSERINFO_SRV/UserCollection DATA:
ls_request_input_data TYPE
zcl_zuserinfo_mpc=>ts_user.
io_data_provider>read_entry_data(
IMPORTING es_data =
ls_request_input_data ).
Save web pages as PDF manually or automatically with PDFmyURL

Yes

In case of Create operation, you cannot use system query options else you will get an error as
The Data Services Request contains SystemQueryOptions that are not allowed for this Request Type
This error message comes from method PROCESS_ENTITY_SET (/IWCOR/CL_DS_PROC_DISPATCHER). Just in
case if you are curious and want to know
4) Update Operation
Now we will implement update operation by redefining method USERCOLLECTION_UPDATE_ENTITY. We need to
put below code in this method.
METHOD usercollection_update_entity.
DATA: ls_request_input_data TYPE zcl_zuserinfo_mpc=>ts_user,
ls_key_tab
TYPE /iwbep/s_mgw_name_value_pair,
lv_userid
ls_userinfo

TYPE zuserinfo-userid,
TYPE zuserinfo.

* Get key values


READ TABLE it_key_tab WITH KEY name = 'UserID' INTO ls_key_tab.
lv_userid = ls_key_tab-value.
IF lv_userid IS NOT INITIAL.
* Read request data
io_data_provider->read_entry_data( IMPORTING es_data = ls_request_input_data
).
* Update fields of table ZUSERINFO
UPDATE zuserinfo SET firstname = ls_request_input_data-firstname
lastname = ls_request_input_data-lastname
email
= ls_request_input_data-email
phone
= ls_request_input_data-phone
country
= ls_request_input_data-country
WHERE userid = lv_userid.
IF sy-subrc = 0.
er_entity = ls_request_input_data. "Fill exporting parameter ER_ENTITY
ENDIF.
ENDIF.
ENDMETHOD.
Here also first we need to execute GET operation to read the entity and then copy the response to request using Use
as Request button and execute PUT operation after editing required data. Successful HTTP response will look as
Save web pages as PDF manually or automatically with PDFmyURL

below with status code as 204.

Here IO_TECH_REQUEST_CONTEXT refers to /IWBEP/IF_MGW_REQ_ENTITY_U


OData Query

Method Parameter

Alternative way to get the


value

Coding required
to implement
Query Operation

UserCollection('Test1') IT_KEY_TAB

DATA: lt_keys TYPE

Yes

/iwbep/t_mgw_tech_pairs,
ls_key TYPE
/iwbep/s_mgw_tech_pair.
lt_keys =
io_tech_request_context>get_keys( ).
UserCollection('Test1') IO_DATA_PROVIDER io_data_provider>read_entry_data(
IMPORTING es_data =
ls_request_input_data ).
5) Delete Operation
Save web pages as PDF manually or automatically with PDFmyURL

Yes

To implement Delete operation, you need to execute DELETE HTTP method for particular key. Below is the code for
method USERCOLLECTION_DELETE_ENTITY.
Here we are reading key value of the record to be deleted and executing Delete statement.
METHOD usercollection_delete_entity.
DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
lv_userid TYPE zuserinfo-userid.
* Read key values
READ TABLE it_key_tab INTO ls_key_tab WITH KEY name = 'UserID'.
lv_userid = ls_key_tab-value.
IF lv_userid IS NOT INITIAL.
* Delete record from table ZUSERINFO
DELETE FROM zuserinfo WHERE userid = lv_userid.
ENDIF.
ENDMETHOD.
On successful record deletion, you will see HTTP response code as 204.

Here IO_TECH_REQUEST_CONTEXT refers to /IWBEP/IF_MGW_REQ_ENTITY_D


OData Query

Method
Parameter

Alternative way to get the


value

UserCollection('Test1') IT_KEY_TAB DATA: lt_keys TYPE


/iwbep/t_mgw_tech_pairs,
ls_key TYPE
/iwbep/s_mgw_tech_pair.
lt_keys =
io_tech_request_contextSave web pages as PDF manually or automatically with PDFmyURL

Coding required to
implement Query Operation
Yes

>get_keys( ).
6) Function Import
As per SAP documentation, Function Imports - SAP NetWeaver Gateway Foundation (SAP_GWFND) - SAP Library
The Open Data Protocol (OData) includes standard CRUD (Create, Retrieve, Update, and Delete)
operations that map to the HTTP methods POST, GET, PUT/MERGE, and DELETE.
In addition, OData supports further service operations (function imports) that can be invoked by the HTTP
methods GET or POST for anything that cannot be mapped to the standard CRUD operations. You can
implement such additional service operations in the Service Builder by creating function imports within
your data model.
For example, you could create function imports for the following custom operations:
Confirm Work Item
Check Flight Availability
While it is simple to create new function imports to invoke custom operations, if the operation you want to
use can be invoked using a standard CRUD operation, you should not create a function import. That is,
you should only create function imports for custom operations that cannot be invoked using a standard
operation.

In simple terms, if an operation cannot fit into CRUD scenario then you can perform it by function import.
Suppose our ZUSERINFO table looks like below,

And we want to get users by specific country then we can implement function import. Lets call our function import as
UsersByCountry!
Right click on Data model and create function import. Provide proper name. Again refer Creating

High-Quality
OData Services - SAP NetWeaver Gateway Foundation (SAP_GWFND) - SAP Library
Save web pages as PDF manually or automatically with PDFmyURL

Provide required details such as mentioned below. Remember here we want to return collection of users and hence
we selected Return cardinality as 0..n with return entity set and HTTP method type as GET.

Now click on Function Import parameters and create import parameters as shown below. In this case we just want to
pass value of country and hence we will have one parameter as Country.

Finally save project, check project consistency and generate runtime objects. To check if everything is fine, in GW
client execute service metadata URL as /sap/opu/odata/sap/ZUSERINFO_SRV/$metadata which should show you
function import definition in metadata as below,

Now we will implement function import operation. Go to DPC_EXT class and redefine method
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION.
Save web pages as PDF manually or automatically with PDFmyURL

Put below code to implement function import.


METHOD /iwbep/if_mgw_appl_srv_runtime~execute_action.
DATA: ls_parameter TYPE /iwbep/s_mgw_name_value_pair,
lv_country
TYPE string,
lt_userinfo
TYPE TABLE OF zuserinfo,
ls_userinfo
ls_entity
lt_entityset

TYPE zuserinfo,
TYPE zcl_zuserinfo_mpc=>ts_user,
TYPE zcl_zuserinfo_mpc=>tt_user.

IF iv_action_name = 'UsersByCountry'. " Check what action is being requested


IF it_parameter IS NOT INITIAL.
* Read Function import parameter value
READ TABLE it_parameter INTO ls_parameter WITH KEY name = 'Country'.
IF sy-subrc = 0.
lv_country = ls_parameter-value.
ENDIF.
IF lv_country IS NOT INITIAL.
SELECT * FROM zuserinfo INTO TABLE lt_userinfo WHERE country =
lv_country.
LOOP AT lt_userinfo INTO ls_userinfo .
ls_entity-userid
= ls_userinfo-userid.
ls_entity-firstname = ls_userinfo-firstname.
ls_entity-lastname = ls_userinfo-lastname.
ls_entity-email
= ls_userinfo-email.
ls_entity-phone
= ls_userinfo-phone.
ls_entity-country = ls_userinfo-country.
APPEND ls_entity TO lt_entityset.
ENDLOOP.
* Call methos copy_data_to_ref and export entity set data
copy_data_to_ref( EXPORTING is_data = lt_entityset
CHANGING cr_data = er_data ).
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.

Save web pages as PDF manually or automatically with PDFmyURL

To test function import we need to query as /sap/opu/odata/sap/ZUSERINFO_SRV/UsersByCountry?Country='US'


If there are multiple parameters then it will be separated by comma.

Here IO_TECH_REQUEST_CONTEXT refers to /IWBEP/IF_MGW_REQ_FUNC_IMPORT


OData Query

Method
Parameter

Alternative way to get the


value

Coding
required
to
implement
Query
Operation

/sap/opu/odata/sap/ZUSERINFO_SRV/UsersByCountry? IT_PARAMETER DATA: my_parameter TYPE


Yes
Country='US'
/iwbep/t_mgw_name_value_pair.
my_parameter =
io_tech_request_context>get_parameters( ).
Save web pages as PDF manually or automatically with PDFmyURL

Closing Remarks
This is very simple example of an OData service. In real case scenarios, you will have multiple entities, relationship,
association and navigation between them but when it comes to coding in DPC_EXT class methods, you will find above
explanation of each method, parameters and alternative way to get the parameter values useful.

I hope you enjoyed reading this blog and now ready to develop your OData service! I request you to put
comments/suggestions. Please feel free if you have any different thought to improve any part of this blog as
well.
[Update - 9/25/2014] I have posted new blog which focuses more on association/navigation and data provider
$expand. You can access it at
Let's code association/navigation and data provider expand in OData
service!
Happy Learning & Coding

38310 Views
Products: sap_netweaver_gateway Tags: developer, gateway, odata, netweaver_gateway, crud, segw, crud_operations,
rest_webservice, function_import

Average User Rating


(28 ratings)

Share

Like

84 Comments

Syam Babu Mar 7, 2014 8:33 AM

Hi Chandra,
Save web pages as PDF manually or automatically with PDFmyURL

Excellent Blog and Nicely written each and every point and definitely will try this in my system.
Is it possible to create function import operation for Deep_Insert ?
Thanks,
Syam
Like (1)

Chandrashekhar Mahajan Mar 10, 2014 8:50 AM (in response to Syam Babu)

Hi Syam,
I don't think that deep_insert is possible with Function import. As per my understanding,
Deep insert will require kind of parent child entities with association between them and it will
be not suitable to pass this kind of information via function import parameters.
But again, I am not 100% sure as technically it may be possible but it will be very bad design
and should not be recommended. May be some expert can comment more on this.
Regards,
Chandra
Like (0)

faraz khan Mar 7, 2014 4:43 PM

Chandra Sir Once Again Extremely good blog.


Regards Faraz
Like (1)

Chandrashekhar Mahajan Mar 10, 2014 8:51 AM (in response to faraz khan)

Thanks

faraz khan !

Regards,
Chandra
Like (0)

Ajith Cheruvally Mar 12, 2014 10:56 AM

Hi Chandra,
I am a beginner in NW Gateway, and I found this document very useful. Thanks a lot!!!.
Like (1)

Save web pages as PDF manually or automatically with PDFmyURL

Chandrashekhar Mahajan Mar 12, 2014 2:22 PM (in response to Ajith Cheruvally)

Thanks for your comments


Ajith Cheruvally ! Yes my motive to write this blog was to
explain basics of SAP GW OData service in simple way so that anyone can start quickly
developing it
Regards,
Chandra
Like (0)

Sharada G Mar 17, 2014 11:49 AM (in response to Chandrashekhar Mahajan)

good one !!
Like (0)

Arindam Samanta Mar 18, 2014 8:57 AM

Hi Chandrashekhar,
Thanks for your great effort. Its very good stuff...
Regards,
Arindam Samanta
Like (1)

akshath lt Mar 18, 2014 11:01 AM

HI Chandrashekar,
I have used "Create Service (Method => FILE_UPLOAD_CREATE_ENTITY) from Service
Implementation" for update data to backend system and i have written logic for update back end
system.
When i test in SAP NW Gateway Client i am getting below error

Save web pages as PDF manually or automatically with PDFmyURL

Browser showing below output/error

I have refered http://scn.sap.com/community/netweaver-gateway/blog/2014/03/06/let-s-code-crudqand-function-import-operations-in-odata-service blog but i couldnt get any idea.


Kindly help me on this
Thanks,
Akshath
Like (0)

Atanu Mallik Mar 18, 2014 12:35 PM (in response to akshath lt)

The error is expected. You can not perform a post operation on the metadata document.
Neither you are passing any content to be created. check section
Lets code CRUDQ and
Function Import operations in OData service! carefully... specially the URL and the Payload
passed in the Gateway Client
Save web pages as PDF manually or automatically with PDFmyURL

Like (1)

govindu nagotla Mar 18, 2014 8:27 PM

Hello Chandra,
This blog is very helpful for us in understanding the GW odata services in the ABAPers point of view .
I want to know the performance of the Odata services in the real time HTML5 applications.
Could you suggest/Guide us in developing the best odata services in the performance point of view ?
Have you faced any time performance issues with Odata services ?
the above details will be very help for us in real time application developments.
Regards,
Govindu
Like (0)

Chandrashekhar Mahajan Mar 19, 2014 11:19 AM (in response to govindu nagotla)

Thanks Govindu for your comments!


For performance of OData services as well as best practices, you can refer
Performance Best Practices - SAP NetWeaver Gateway Foundation (SAP_GWFND) SAP Library
OData Best Practices - SAP NetWeaver Gateway Foundation (SAP_GWFND) - SAP
Library
and Creating High-Quality OData Services - SAP NetWeaver Gateway Foundation
(SAP_GWFND) - SAP Library
Regards,
Chandra
Like (0)

akshath lt Mar 19, 2014 5:55 PM (in response to Chandrashekhar Mahajan)

HI Chandra,
I have requirement to both upload/download PDF file into MIME repository or DMS
through SAP UI5.
I have tried to download PDF file from the MIME repository and I have followed
below steps.
1. Created FM for PDF download.
1.1 Default path 'SAP/PUBLIC/<File name> for MIME repository
Save web pages as PDF manually or automatically with PDFmyURL

1.2 Used below code for upload/ download


-------------------------------------------------------------Initiating class
-------------------------------------------------------------lr_mime_rep = cl_mime_repository_api=>if_mr_api~get_api( ).
-------------------------------------------------------------Reading file
-------------------------------------------------------------lr_mime_rep->get(
EXPORTING
i_url = p_path
i_content = lv_content
EXCEPTIONS
parameter_missing
=1
error_occured = 2
cancelled = 3
permission_failure
=4
data_inconsistency
=5
new_loio_already_exists = 6
is_folder = 7
OTHERS = 8 ).
-------------------------------------------------------------Converting XSTRING TO BINARY
-------------------------------------------------------------CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
input_length = lv_length
* first_line = 0
* last_line = 0
IMPORTING
buffer
= lv_content
TABLES
binary_tab = lt_data
EXCEPTIONS
failed
=1
OTHERS
= 2.
-------------------------------------------------------------Download file to desktop
-------------------------------------------------------------lv_filename = 'C:\ABC.PDF'.
cl_gui_frontend_services=>gui_download(
EXPORTING
filename = lv_filename " Name of file
Save web pages as PDF manually or automatically with PDFmyURL

filetype = 'BIN'
IMPORTING
filelength = lv_length " File length
CHANGING
data_tab = lt_data " Transfer table for file contents
EXCEPTIONS
OTHERS = 19 ).
----------------------------------------------------------------------------1. Created project in SEGW.
2. Used FM inside GET_ENTITY method.
Problem is CL_GUI_FRONTEND_SERVICE won't work in background so I can't
able to download file.
Is this correct way to download / Upload file to desktop ?
If you have any better solution please share with me..
Thanks,
Akshath
Like (0)

Chandrashekhar Mahajan Mar 20, 2014 8:02 AM (in response to akshath lt)

Hi Akshath,
To download pdf file from sapui5 application, you can refer my blog
Display Smartform (PDF) in SAPUI5
Regards,
Chandra
Like (0)

Lakhan Sarada Mar 31, 2014 2:24 PM

Very useful blog....More descriptive and understandable.


Thanks for this!
Like (1)

Syam Babu Apr 23, 2014 1:07 PM

Hi Chandra,
Does we have multiple input parameters in my RFC ..so how do i have to pass URI path
like for get_entityset we are passing when we have multiple inputs
Save web pages as PDF manually or automatically with PDFmyURL

?$filter=BankCtry eq 'IN' and BankKey eq '222'


Thanks,
Syam
Like (0)

Chandrashekhar Mahajan Apr 23, 2014 1:18 PM (in response to Syam Babu)

Hi Syam,
yes ?$filter=BankCtry eq 'IN' and BankKey eq '222' this is the correct way of passing
multiple input parameters.
Regards,
Chandra
Like (0)

Syam Babu Apr 23, 2014 3:21 PM (in response to Chandrashekhar Mahajan)

Yes..When we are using the function import also we have to pass like above URI?
Bit confusing here in your function import single parameter your not using any
$filter in URI
/sap/opu/odata/sap/ZUSERINFO_SRV/UsersByCountry?Country='US'...
Thanks,
Syam
Like (0)

Chandrashekhar Mahajan May 2, 2014 10:02 AM (in response to Syam Babu)

for function import multiple parameters will be separated by comma &. for
e.g
/sap/opu/odata/sap/ZUSERINFO_SRV/UsersByCountry?
Country='US',City='Pune'
it should be
/sap/opu/odata/sap/ZUSERINFO_SRV/UsersByCountry?
Country='US'&City='Pune'
Regards,
Chandra
Like (1)

Syam Babu Apr 23, 2014 3:50 PM (in response to Chandrashekhar

Save web pages as PDF manually or automatically with PDFmyURL

Mahajan)

Yes..Now I understood..
Thanks,
Syam
Like (0)

Syam Babu Apr 23, 2014 4:27 PM

Hi Chandra,
I have done the function import what you have done like..it's working fine...
When I am creating function import using complex type as Return type everything fine coding part.
But here how to to test the URI for complex type as a return type in function import ..any Specific
sample URI for complex type.

Thanks,
Syam
Like (0)

Chandrashekhar Mahajan Apr 23, 2014 4:59 PM (in response to Syam Babu)

Not sure about URI for complex type but you can refer this discussion thread
complex types in a odata url filter

How to use

Regards,
Chandra
Like (0)

Syam Babu May 2, 2014 8:03 AM

Hi Chandra,
Can I get the data as a JSON format from Function Import?
If yes,Give me sample URI for JSON format.
Save web pages as PDF manually or automatically with PDFmyURL

Thanks,
Syam
Like (0)

Chandrashekhar Mahajan May 2, 2014 10:04 AM (in response to Syam Babu)

Hi,
it will be /sap/opu/odata/sap/ZUSERINFO_SRV/UsersByCountry?
Country='US'&City='Pune'&$format=json
also note that multiple parameters will be separated by & and not comma. I corrected my
earlier response.
Regards,
Chandra
Like (0)

Syam Babu May 2, 2014 10:20 AM (in response to Chandrashekhar Mahajan)

Hi Chandra,
In my function import there is no input parameter,so that time I am passing to URI
given below as a json
Below of URI's i have tried without parameter.
/sap/opu/odata/sap/ZPROJ_FILES_SRV/FilesList?&$format=json
/sap/opu/odata/sap/ZPROJ_FILES_SRV/FilesList&$format=json
Still getting error says...HTTP 500 - Internal Server Error.
Where can i expect mistake in my development.
Note : Getting data for XML.
Thanks,
Syam
Like (0)

Chandrashekhar Mahajan May 2, 2014 11:30 AM (in response to Syam Babu)

it will be /sap/opu/odata/sap/ZPROJ_FILES_SRV/FilesList?
$format=json
Regards,
Chandra
Like (0)

Save web pages as PDF manually or automatically with PDFmyURL

Sunil Khemchand May 3, 2014 12:13 AM

Nice work Chandra!!


Like (0)

Hemendra Sabharwal May 7, 2014 11:43 AM

Great work Chandra.


Thanks & Regards
Hemendra
Like (1)

pavan jhawar May 11, 2014 8:30 AM

Hi Chandra,
It is an excellent blog for the beginners. I am trying the similar steps in my system, but getting the
below issue when i try to execute the service from the transaction /IWFND/GW_CLIENT. But that url
works in browser and i can see the metadata and entityset parameters working in chrome browser.
error: HTTP Receive failed: ICM_HTTP_CONNECTION_FAILED
What can be the issue?

Save web pages as PDF manually or automatically with PDFmyURL

Like (0)

Syam Babu May 11, 2014 9:29 AM (in response to pavan jhawar)

Hi Pavan,
Check with your basis team.they will help about this issue.
Thanks,
Syam
Like (0)

Ankit Maskara Oct 9, 2014 6:28 PM (in response to pavan jhawar)

Hi Pavan,
This issue comes up when the URL is wrong. Open the same in SM59 and see. You will not
be able to launch that URL in any browser.
PS: In case of SSO/SSL - you may get another error ICM_HTTP_SSL_ERROR.
BR.
Save web pages as PDF manually or automatically with PDFmyURL

Like (0)

Krishnakant Joshi Aug 30, 2014 11:01 AM

Great blog chandra,


Just wanted to know that, can we pass table param ( entity set ) to function import ?
Regards,
Kk
Like (0)

Ashwin Dutt R Sep 1, 2014 3:20 AM (in response to Krishnakant Joshi)

Hello Krishna,
You meant to say u have table of inputs and u want all those entries to be sent as inputs to
ur function import ? If yes, u cannot send at one shot like how we give to FM generally. U
need to operate in BATCH mode.
Example for GET: Search is happening based on different Name's and u get the
corresponding output as per the logic written in ur Execute_Action Method.

Save web pages as PDF manually or automatically with PDFmyURL

Regards,
Ashwin
Like (0)

Lukasz Zemelka Sep 10, 2014 12:55 PM

Hello, How you get er_data ?


Like (0)

Ashwin Dutt R Sep 10, 2014 1:13 PM (in response to Lukasz Zemelka)

Hello Lukasz,
er_data is actually an exporting parameter.
The below method which is already an existing method and you need to just call this and
send back the response as below. Only thing which has to be done from your end is to just
map back the data as response as below.
Save web pages as PDF manually or automatically with PDFmyURL

copy_data_to_ref( EXPORTING is_data = <your result set>


CHANGING cr_data = er_data ).
Regards,
Aswhin
Like (0)

Lukasz Zemelka Sep 19, 2014 1:08 PM

Hello,
How to know for example if odata update request finished without errors ?
from http status ?
Like (0)

Ashwin Dutt R Sep 19, 2014 1:58 PM (in response to Lukasz Zemelka)

Hello Lukasz,
Yes. Its based on status code 204.
In my opinion Its always good to write an error handling to through an exception if update is
failed. I mean check for errors encountered if update is failed. If error are encountered raise
exception.
If no errors are encountered after update do nothing. Lets the flow continue.
If interested, U can also fire a read after an update to check if data is really updated.
U can accomplish via BATCH ( Batch Retrieval and Change Set ).
Regards,
Ashwin
Like (0)

Jordan Tchorbadjiyski Sep 30, 2014 4:37 PM

Hi Chandra, g reat post!


I have a question regarding the function import though:
Is it also possible to pass multiple values for a single parameter and what would be the correct
syntax?
That is something like: /sap/opu/odata/sap/ZUSERINFO_SRV/UsersByCountry?
Country='US'&Country='UK'
I've been trying different formats but couldn't get it right.
Thanks,
Jordan
Like (0)

Save web pages as PDF manually or automatically with PDFmyURL

Ashwin Dutt R Oct 1, 2014 1:10 AM (in response to Jordan Tchorbadjiyski)

Hello Jordan,
U can send as below but values sent will be comma separated .
/sap/opu/odata/sap/ZUSERINFO_SRV/UsersByCountry?Country='US',Country='UK'
But if u put a break-point in ur Execute_Action method and check the entry of
'IT_PARAMETER' at the runtime, the different set of data u sent by repeating the same
properties as mentioned in above URL will be comma separated and extraction of those
values would be tedious and may turn into messy..
Once u debug u will get to know how the data will be captured in IT_PARAMETER which u
have sent as part of ur action parameters in the above URL.
According to me Execute action is not a correct operation if u want to send inputs in a
fashion u are trying to send.
Regards,
Ashwin
Like (0)

Jordan Tchorbadjiyski Oct 1, 2014 9:25 AM (in response to Ashwin Dutt R)

Hi Ashwin,
Thanks for the answer, unfortunately that's one of the ways I already tried but was
reluctant to parse on the server side
(sap/opu/odata/sap/ZUSERINFO_SRV/UsersByCountry?Country='US|UK'')
Since it_parameter is a table with no size restrictions I was hoping there should be
a way to fill it with more than one entry per parameter and pass the information in a
cleaner manner...
My use case is that I want to trigger a function in the back end; that function accepts
either a table or a single value for a parameter (selection of multiple values in the
UI should be possible, even preferred). That's why I thought it doesn't fit into any
CRUD operation and wanted to use a function import.
What would you advise? Perhaps an update operation on an entity set is
semantically closest but the requirement to pass multiple values can be satisfied
only for get entitiy set?
Thanks and best regards,
Jordan
Like (0)

Save web pages as PDF manually or automatically with PDFmyURL

Ashwin Dutt R Oct 1, 2014 11:32 AM (in response to Jordan Tchorbadjiyski)

Hello Jordan,
The function which u would like to trigger at the back end by sending
table entries/ Single value is a GET operation is it ?
Regards,
Ashwin
Like (0)

Jordan Tchorbadjiyski Oct 1, 2014 12:38 PM (in response to Ashwin


Dutt R)

Hi Ashwin,
No, the function starts a job (a background process) with no
direct output related to the service...
Best regards,
Jordan
Like (0)

Ashwin Dutt R Oct 1, 2014 1:30 PM (in response to Jordan


Tchorbadjiyski)

Hello Jordan,
Like u said its not falling under any standard CRUD
operation and cant be accomplished through function
import.
Then i think u can call an update.
But since u may have multiple entries, then how will u
send those to ur update operation ?
Only flat structure update is possible. I mean one entry
at a time.
Then u need to operate on BATCH mode so that inside
a payload u can load all ur entries and fire update.
But this update will call ur Job for very entry.
Say 10 entries are there inside the table, then 10 times
ur job will be called when u operate in BATCH.
So u need to think about this as well.
We can do this via Create_Deep_Entity but its not a
standard approach i feel and would be just an
workaround.
Regards,
Save web pages as PDF manually or automatically with PDFmyURL

Ashwin
Like (0)

Rajesh Dadwal Sep 30, 2014 7:29 PM

Thanks Chandra, Well documented blog for CRUD & function import..
Regards,
Rajesh
Like (1)

Vishnu Pankajakshan Oct 7, 2014 11:10 AM

I tried all the above steps and its working fine.I tried another method by redefining DPC_EXT and
MPC_EXT and i used a custom functional module with TABLE's as input and output.I passed my input
through XML payload in gateway client.I am not sure whether the method i used is proper or not.And i
also would like to know a method to do the same thing using GPA.
regards,
Vishnu
Like (0)

Vishnu Pankajakshan Oct 8, 2014 6:59 AM

Thanks chandra for such a large documentation for CRUD Operation.


Like (0)

Arindam Samanta Oct 8, 2014 7:24 AM

Hi Chandrshekhar,
Recently based on my requirement, I have used ?$filter option in my odata service url for query
operation. My URL is http://yyy.yyy.yyy.com:0000/sap/opu/odata/sap/ZAS_SODEXO_SRV/SODEXO_DISBURSE_SET?
$filter=Action eq 'COUNT' and Fdate eq '12.12.2014' and Tdate eq '12.12.2014' and Bukrs eq
'1001' and Pernr eq '123456'
This URL is being used in SAPUI5 application. While executing my application, /$count is
automatically added at the end my URL. As a result, ODATA not able to fetch data. How to get the
records through this kind of ODATA URL?
Kindly suggest!
Thanks & Regards,
Save web pages as PDF manually or automatically with PDFmyURL

Arindam Samanta
Like (0)

Vishnu Pankajakshan Oct 8, 2014 2:13 PM

Hi Chandra,
Which and how we can pass a entity_Set through the payload.I tried implementing it but i got stuck
with error '"The server is refusing to process the request because the entity has a unsupported format"
Regards,
Vishnu
Like (0)

Vishnu Pankajakshan Oct 8, 2014 2:18 PM (in response to Vishnu Pankajakshan)

I am trying to retrieve an internal table of data (Expecting to pass multiple entities using Http
POST method) so that i can modify and return through the response XML.
Regards,
Vishnu
Like (0)

Ankit Maskara Oct 14, 2014 11:06 AM

Good Work Chandra.


Like (1)

vivek gaurav Oct 14, 2014 2:59 PM (in response to Ankit Maskara)

Very nice and helpfull blog


Like (0)

Pham Chinh Thi Oct 29, 2014 6:24 AM

Hi Chandra,
How can we put parameter from action of BO, when I redefined a BOPF, I see the case that the
parameter name of function import after I redefined from action of BO is different from the method that
I implement in class?
Thanks
Chinh Pham
Like (0)

Save web pages as PDF manually or automatically with PDFmyURL

Yueqiang Zhu Nov 11, 2014 9:04 AM

Great work, really like this!


Like (1)

Harinder Singh Nov 11, 2014 9:57 PM

Hi Chandra,
Nice Document. I have question. I have implemented UserCollection?search='test '. But I am getting
thousands records from database based on condition. I want to implement SEARCH with PAGINING.
Is it possible?
Thanks
Harinder
Like (0)

Ashwin Dutt R Nov 12, 2014 5:37 AM (in response to Harinder Singh)

Hello Harry,
Yes u can as below:
UserCollection?search='test '&$skip=1&$top=1
Regards,
Ashwin
Like (0)

Zhengzhang Lu Nov 25, 2014 4:01 AM

Hi Mahajan,
It is a great helpful for us! We are facing a question that when we tried to create data to a new table
by 'Post' function and as the table has no data so we cannot use 'Get' function to get the format, could
you please give us some advice how to use 'Post' function for a new table?
Regards,
Zhengzhang
Like (0)

Ashwin Dutt R Nov 25, 2014 6:16 AM (in response to Zhengzhang Lu)

Hello Lu,
Save web pages as PDF manually or automatically with PDFmyURL

May be you can quickly insert a sample/test data into your table and perform a GET and
then use response of that GET operation as the payload for your POST operation.
However you can manually Create your XML or JSON payload as well.
You need not to always depend on response of your GET operation to get the payload
format.
Use your Property Names in the places of highlighted section which are defined in your
Gateway Model.
Property Names are Case Sensitive.
Sample JSON payload ->
{
"ManuCompany":"0100",
"RequestNo":"TEST_1",
"RequestItmno":"0001",
"FromPackage":"XXX",
"ToPackage":"XXX",
"Quantity":"1",
"BaseUnit":"TON"
}
In Header you can pass Content-Type -> application/json while performing POST
operation.
Sample XML payload ->
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<atom:content type="application/xml">
<m:properties>
<d:ManuCompany>0100</d:ManuCompany>
<d:RequestNo>TEST_1</d:RequestNo>
<d:RequestItmno>0001</d:RequestItmno>
<d:FromPackage>XXX</d:FromPackage>
<d:ToPackage>XXX</d:ToPackage>
<d:Quantity>1</d:Quantity>
<d:BaseUnit>TON</d:BaseUnit>
</m:properties>
</atom:content>
</atom:entry>
In Header pass you can pass Content-Type -> application/xml while performing POST
operation.
You can also Create XML or JSON payload manually for performing Deep Entity Creations
as well.
You can find Sample XML Payload in the below blog. Please have a look ->
Save web pages as PDF manually or automatically with PDFmyURL

Step by Step development for CREATE_DEEP_ENTITY operation


You can also Create payload in JSON format for the XML payload shown in the above blog.
Regards,
Ashwin
Like (1)

Zhengzhang Lu Nov 25, 2014 6:51 AM (in response to Ashwin Dutt R)

Hi Ashwin,
Thanks a lot for your help! It is working now.
Regards,
Zhengzhang
Like (0)

Dimitrios Papadopoulos Mar 17, 2015 4:14 PM

Hi Chandra,

very helpful post indeed !

I have a question regarding the update Response.


Although you have er_entity = ls_request_input_data, you get a blank Response with no content.
Did you manage to get the updated Entity in the Response Body ?
Thanks,
Dimitris
Like (0)

Chandrashekhar Mahajan Mar 18, 2015 4:14 PM (in response to Dimitrios Papadopoulos)

You will not get response in update operation. only status code as 204 for successful update
operation.
Regards,
Chandra
Like (1)

Dimitrios Papadopoulos Mar 18, 2015 4:21 PM (in response to Chandrashekhar Mahajan)

Save web pages as PDF manually or automatically with PDFmyURL

Hi Chandra,
thanks for the answer.
I looked at the definitions of the various HTTP Status codes and as it seems the
caller has to make a GET request again if he needs to view the updated entity.
Regards,
Dimitris
Like (0)

Chandrashekhar Mahajan Mar 18, 2015 4:27 PM (in response to Dimitrios


Papadopoulos)

yes that's correct. one need to execute GET request (READ operation) to
read the updated entity.
Like (1)

Kalyan Chakravarthi Mar 18, 2015 3:13 PM

Hi Chandra Nice Post,


I have a query hope you could help me.
I have searched over SDN to find about how do we pass multiple value ranges from Query to SAP
ODATA?
But I have not found suitable answers so I am posting it here.
If we need to pass a date parameter in Query which has a multiple range like sales orders created
date between 03/02/2014 to 05/07/2014.
How do we phrase it in Query ?
I tried as below but the IT_FILTER_SELECT_OPTIONS of
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET does not get filled up with the
parameters
How do we pass multiple values in Query?
http://ctnhsapapp16.corp.ken.com:8000/sap/opu/odata/sap/ZCHAKRABK_MAINT_ORDERS_SRV/Maint_Orders?
$filter=Maint_Plant eq 'US19' and B_st_dt gt datetime'2015-02-01T00:00:00' and B_st_dt lt

datetime'2015-02-28T00:00:00'
Thanks in Advance.
KC.
Like (0)

Save web pages as PDF manually or automatically with PDFmyURL

Abdulkadir AKIN Apr 3, 2015 8:23 PM

Hi,

Chandrashekhar it's a very helpful post, thanks alot.

I have a problem with calling "custom function" by ui5 odata.callFunction(..., "POST",...), please check
the following discussion.
Sap ui5 ODataModel callfunction post method?
Like (0)

Johan Fernandes Apr 29, 2015 6:35 AM

Hi Chandra,
Nice blog, very helpful.
I have an issue while implementing Function Import .

Would you be kind enough to explain this error ?


Like (0)

Ashwin Dutt R Apr 29, 2015 7:04 AM (in response to Johan Fernandes)

Hello John,
I think you need to check the Return Cardinality defined under Function Import.
You would have returned an Entity Set with Cardinality 0...1 or 1.
If cardinality is 0...1 or 1 then from DPC you need to map the structure as response to GW.
For other Cardinality map back an internal table as response to GW from DPC.
Save web pages as PDF manually or automatically with PDFmyURL

Please check this once.


Regards,
Ashwin
Like (0)

Johan Fernandes Apr 29, 2015 7:13 AM (in response to Ashwin Dutt R)

Hi Ashwin,
Thanks . I changed the cardinality of the Return type and was succsessfully able to
return a table.
Originally the cardinality was 0..1 and I was trying to pass a table hence I got the
error "Structure required". Once I changed the cardinality from 0..n my requirement
was successful.
Thanks you.
Like (0)

Arun Jadhav May 6, 2015 8:02 PM

Nice blog. Helps every time for quick reference. Thank You.
Like (0)

Kaan Ozdogan May 27, 2015 8:09 AM

Hi,
I pass import parameter and I get entityset a table.
But I want to get two or more table from import function.
How can I do?
Thank you
Like (0)

Ankit Maskara May 27, 2015 8:16 AM (in response to Kaan Ozdogan)

Hi,
What's your business requirement?
For multiple tables you can either nest them in a single structure(if they are related like
header-item) or have different entities all together(in case they are not related). As far as I
know its not possible ( and does not make sense) to output multiple unrelated tables data
from single entity.
BR.
Like (0)

Save web pages as PDF manually or automatically with PDFmyURL

Kaan Ozdogan May 27, 2015 8:29 AM (in response to Ankit Maskara)

I have rfc function to send import parameter from sapui5than I want to get two or
more table from function.
Like (0)

Ankit Maskara May 27, 2015 8:34 AM (in response to Kaan Ozdogan)

Hi Kaan,
So are the tables related to each other like Sales Order header and Sales
Order Item? If yes, then create a structure with a table nested in it and it
should work.
If not so, then its better to model two RFC calls and get data in two tables.
I assume, nested approach should solve your problem because you are
passing some import parameters which govern data in both tables so
implicitly both tables would be associated in some way.
BR.
Like (1)

Abdulkadir AKIN May 27, 2015 1:19 PM (in response to Kaan Ozdogan)

Hi Kaan,
You can use "batch operation" for independent table results (Entities without associations).
Batch operation allows multi calls from server with a request.
For ex: https://scn.sap.com/community/developer-center/front-end/blog/2012/11/18/gatewaybatch-calls-from-sapui5
Also You can use "expand" parameter if you want return a deep structure from function
import or from EntitySet. For Example I used the following deep structure with expand.

rnek http get call


/sap/opu/odata/SAP/ZTEST2_SRV/ResultSet(1)?
$format=json&$expand=OnaySet/SaticiSet/Address,Status,ReturnSet
stenilen rnek structure yaps
<result>
<status>
<type/>
<message/>
</status>
<onayset>
<onay>
Save web pages as PDF manually or automatically with PDFmyURL

<onay>
<id />
<title />
<saticiset>
<satici>
<id />
<name />
<address>
<id />
<city />
<desc />
</address>
</satici>
</saticiset>
</onay>
<onay>
.....
</onay>
<onay>
.....
</onay>
</onayset>
<returnset>
<return>
<id/>
<message/>
</return>
<return>
<id/>
<message/>
</return>
</returnset>
</result>

Save web pages as PDF manually or automatically with PDFmyURL

Like (0)

Kaan Ozdogan May 27, 2015 2:31 PM (in response to Abdulkadir AKIN)

Selam Abdulkadir,
Gateway tarafnda entity nasl tanmlyorum su anda sadece diset diye bi tablo
var.Fonksiyon import parameter verirken sadece bir tane set entity'ye izin veriyor,

Save web pages as PDF manually or automatically with PDFmyURL

Like (0)

Abdulkadir AKIN May 27, 2015 2:39 PM (in response to Kaan Ozdogan)

Function import isn't flexible and can return just a entity/entityset. You can
create a fake entity type and put other entitysets under this enetity with 1n assocation. I didnt try your scenario with function import. You can try
the following structre in function import.
(Kaan function import cok esnek bir yapya sahip deil. Odata nn kendisi
zaten ok esnek bir yapya sahip deil. (Aslnda .net iyim, yeniyim bu

ite ) Ui5 ile Netwaver odata ile ortak bir yap kurmak adna sk
kurallar koyulmu vs. Bir ay nce bende bir function import ile birden
fazla entityset dndrme ihtiyac duydum. Aratrdm ve anladm
kadaryla sadece bir tip veya set dnmek mmknm. En sonunda
yukarda resmini koyduum ekilde bir zm buldum. Sende ayn yolu
izleyebilirsin. Result adnda bir entity oluurup bu entity ye assocation ile
dier entityleri 1-n iliki ile balayabilir ardndan
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY.
methodunda deep structure eklinde dnebilirsin. Dediim gibi expand
olay function importta alyor mu bilmiyorum ama denenebilir.
Aadaki bilgileri incelersin. Kolay gelsin)

example http get call


/sap/opu/odata/SAP/ZTEST2_SRV/ResultSet(1)?
$format=json&$expand=OnaySet/SaticiSet/Address,Status,ReturnSet
stenilen rnek structure yaps
<result>
<status>
<type/>
<message/>
</status>

Save web pages as PDF manually or automatically with PDFmyURL

</status>
<onayset>
<onay>
<id />
<title />
<saticiset>
<satici>
<id />
<name />
<address>
<id />
<city />
<desc />
</address>
</satici>
</saticiset>
</onay>
<onay>
.....
</onay>
<onay>
.....
</onay>
</onayset>
<returnset>
<return>
<id/>
<message/>
</return>
<return>
<id/>
<message/>
</return>
</returnset>
</result>

Save web pages as PDF manually or automatically with PDFmyURL

method
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY.
**TRY.
*CALL METHOD SUPER>/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY
** EXPORTING
** IV_ENTITY_NAME
=
** IV_ENTITY_SET_NAME
=
** IV_SOURCE_NAME
=
** IT_KEY_TAB
=
** IT_NAVIGATION_PATH
=
** IO_EXPAND
=
** IO_TECH_REQUEST_CONTEXT =
** IMPORTING
** ER_ENTITY
=
** ES_RESPONSE_CONTEXT
=
** ET_EXPANDED_CLAUSES
=
** ET_EXPANDED_TECH_CLAUSES =
* .
** CATCH /IWBEP/CX_MGW_BUSI_EXCEPTION .
** CATCH /IWBEP/CX_MGW_TECH_EXCEPTION .
**ENDTRY.

Save web pages as PDF manually or automatically with PDFmyURL

types: begin of ty_satici.


include type zcl_ztest2_mpc=>TS_SATICI.
types:Address type zcl_ztest2_mpc=>TS_ADDRESS,
end of ty_satici.
types: ty_ttsatici type standard table of ty_satici with default
key.
types: begin of ty_onay.
include type zcl_ztest2_mpc=>TS_ONAY.
types:SaticiSet type ty_ttsatici,
end of ty_onay.
types: ty_ttonay type standard table of ty_onay with default
key.
types: ty_ttreturn type standard table of
zcl_ztest2_mpc=>TS_RETURN with default key.

types: begin of ty_result.


include type zcl_ztest2_mpc=>ts_result.
types:OnaySet type ty_ttonay,
ReturnSet type ty_ttreturn,
Status type zcl_ztest2_mpc=>ts_status,
end of ty_result.
data: result type ty_result,
gs_onay type ty_onay,
gs_satici type ty_satici,
gs_status type zcl_ztest2_mpc=>ts_status,
gs_return type zcl_ztest2_mpc=>TS_RETURN,
gs_address type zcl_ztest2_mpc=>TS_ADDRESS
.

// if IV_ENTITY_NAME =

'Result'

result-ID = 1.
gs_satici-NAME1 = 'Arelik'.
gs_satici-TOPLAM = 30.
gs_satici-ADDRESS-Id = 1.
gs_satici-ADDRESS-City = 'stanbul'.
gs_satici-ADDRESS-Desc = 'Ulu camii kars'.
append gs_satici to gs_onay-SATICISET.
gs_satici-NAME1 = 'Beko'.
gs_satici-TOPLAM = 22.
Save web pages as PDF manually or automatically with PDFmyURL

gs_satici-TOPLAM = 22.
gs_satici-ADDRESS-Id = 3.
gs_satici-ADDRESS-City = 'stanbul'.
gs_satici-ADDRESS-Desc = 'erenky istanbul'.
append gs_satici to gs_onay-SATICISET.
gs_onay-BUKRS = '123'.
gs_onay-SUBMI = '254'.
gs_onay-id = 1.
append gs_onay to result-ONAYSET.
gs_satici-NAME1 = 'Samsung'.
gs_satici-TOPLAM = 12.
gs_satici-ADDRESS-Id = 4.
gs_satici-ADDRESS-City = 'Bursa'.
gs_satici-ADDRESS-Desc = 'Nilfer'.
append gs_satici to gs_onay-SATICISET.
gs_satici-NAME1 = 'Beko'.
gs_satici-TOPLAM = 25.
gs_satici-ADDRESS-Id = 5.
gs_satici-ADDRESS-City = 'stanbul'.
gs_satici-ADDRESS-Desc = 'Ulu camii kars'.
append gs_satici to gs_onay-SATICISET.
gs_onay-BUKRS = '222'.
gs_onay-SUBMI = '354'.
gs_onay-id = 1.
append gs_onay to result-ONAYSET.
gs_return-ID = '1'.
gs_return-MESSAGE = 'Mesaj 1 dir'.
gs_return-NUMBER = 123.
gs_return-ROW = 1.
gs_return-TYPE = 11.
append gs_return to result-RETURNSET.
gs_return-ID = '2'.
gs_return-MESSAGE = 'Mesaj 2 dir'.
gs_return-NUMBER = 123.
gs_return-ROW = 2.
gs_return-TYPE = 21.
append gs_return to result-RETURNSET.
gs_return-ID = '3'.
gs_return-MESSAGE = 'Mesaj 3 bla bla dir'.
gs_return-NUMBER = 123.
gs_return-ROW = 3.
gs_return-TYPE = 21.
append gs_return to result-RETURNSET.
Save web pages as PDF manually or automatically with PDFmyURL

RESULT-STATUS-Message = 'Bu bir deneme mesajdr'.


result-status-type = 23.
copy_data_to_ref(
exporting
is_data = result
changing
cr_data = ER_ENTITY ).
constants: lc_expand_tech_clause4 type string value
'RETURNSET'.
constants: lc_expand_tech_clause2 type string value
'ONAYSET/SATICISET/ADDRESS'.
constants: lc_expand_tech_clause3 type string value
'STATUS'.

insert lc_expand_tech_clause2 into table


ET_EXPANDED_TECH_CLAUSES.
insert lc_expand_tech_clause3 into table
ET_EXPANDED_TECH_CLAUSES.
insert lc_expand_tech_clause4 into table
ET_EXPANDED_TECH_CLAUSES.

endmethod.
Like (0)

Vishnu Pankajakshan May 27, 2015 2:53 PM (in response to Kaan Ozdogan)

Hi Kaan,
Try to create a Deep Entity Service.That can push u any number of tables as u need
Regards,
Vishnu
Like (0)

Save web pages as PDF manually or automatically with PDFmyURL

Krishna Kallakuri Jul 8, 2015 2:14 AM

Hi Chandrashekhar,
Nice Blog. Can we have exporting structure and Importing structure in the same entity.
PUT -> In this operation i am receiving the input structure and RFC FM will perform Updates using
Standard FM , If there are any error during update i want to capture these error and send it back.
Since i have Mapping with Input structure i am not able to add exporting table in Mapping .
Any suggestion.
Regards,
Krishna
Like (0)

Ashok Dhayalaraj Jul 8, 2015 9:01 AM

Hi Chandra,
Very nice blog. For the past two days, I have been struggling to get the update operation to be done.
As soon as I copied it as the response, it worked perfectly. I believe we can do the same operation,
when we run it through the SAPUI5 Get / Put operations. If you have any example, kindly let me know.
Thanks and Regards,
Ashok Dhayalaraj
Like (0)

Jean Carlo Len Aug 10, 2015 1:32 PM

Hi Chandrashekhar,
Nice blog I already made the same example and it works, but when I try a new one with the same
steps, it display the next error:

Save web pages as PDF manually or automatically with PDFmyURL

How can I resolve this?


Thanks andRegards
Like (0)

Ankit Maskara Aug 18, 2015 2:48 PM (in response to Jean Carlo Len)

Hello Jean,
Please register your service in /N/IWFND/MAINT_SERVICE transaction code.
Should work after that.
BR.
Like (0)

Nimish Kate Aug 19, 2015 6:22 AM (in response to Jean Carlo Len)

Hi Jean,
You haven't registered your service yet. In Service Maintenance, Rightclick on your gateway
client and say "Register". You will have to provide your package name and then save it.
Then execute your service in the gateway client.
Save web pages as PDF manually or automatically with PDFmyURL

Cheers,
-NK
Like (2)

Anselmo Del Arco Aug 21, 2015 2:57 PM

Hi Chandra!
It's an excellent Blog.... Congratulations and thank's...
Like (1)

Jean Carlo Len Aug 22, 2015 12:51 AM

Thank you very much. I tried to answer before but I had technical issues. Thank you again for your
time and nice blog!!!
Like (0)

Saravanan Raju Sep 1, 2015 3:24 AM

Hi Chandra,
This is an excellent Blog.
Being a Developer, this makes my life easy be giving me exactly what I want explained using code
snippets which is exactly what I need.
Thanks a Ton.
Like (0)

Site Index
Privacy

Contact Us
Terms of Use

SAP Help Portal


Legal Disclosure

Copyright

Save web pages as PDF manually or automatically with PDFmyURL

Follow SCN