14
3/13/2017 Stepbystep guide to build an OData Service based on RFCs – Part 1 | SAP Blogs https://blogs.sap.com/2012/10/26/stepbystepguidetobuildanodataservicebasedonrfcspart1/ 1/23 Community / Blogs Get Started Solutions Support Training Community Developer Partner About Volker Drees more by this author Follow Stepbystep guide to build an OData Service based on RFCs – Part 1 October 26, 2012 | 29,670 Views | Retagging required Mobile | SAP Gateway | gateway | Mobile | netweaver gateway | odata | sap netweaver gateway | service builder | volker drees share 0 share 0 tweet share 4 Hello fellow OData Service developers out there. When it comes to OData Service development with SAP NetWeaver Gateway a very typical use case is to build a service that is based on an RFC module (or a set of RFC modules) – e.g. for a List / Detail application. For such a scenario there are dozens of RFC modules

Step by-step guide to build an o data service based on rfcs – part 1 - sap blogs

Embed Size (px)

Citation preview

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 1/23

Community  /  Blogs

Get Started

Solutions Support Training Community Developer Partner

About

Volker Drees more by this author

Follow

Step­by­step guide to build anOData Service based on RFCs –Part 1October 26, 2012  |  29,670 Views  |

Retagging required

Mobile | SAP Gateway |  gateway | Mobile | netweaver gateway | odata | sap netweaver

gateway | service builder | volker drees

share  0 share

  0 tweet

 share

  4

Hello fellow OData Service developers out there.

When  it  comes  to  OData  Service  development  with  SAP  NetWeaver

Gateway a very typical use case is to build a service that is based on an

RFC  module  (or  a  set  of  RFC  modules)  –  e.g.  for  a  List  /  Detail

application.  For  such  a  scenario  there  are  dozens  of  RFC  modules

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 2/23

(BAPIs) available  in  the SAP standard that can be used. And of course

you  can  also  build  and  consume  your  own  (Z­)RFC  modules  if  the

existing modules don’t satisfy your needs…

For additional information regarding the Service Builder please also see

Thomas  Meigens  Blog:  The  new  SAP  NetWeaver  Gateway  Service

Builder: Build new OData Services in 3 Quick Steps

In  this  Step­by­step  Guide  we  will  build  an  OData  Service  that

consumes  two  RFC  modules  from  the  EPM  (Enterprise  Procurement

Model) demo content. From this EPM demo content we pick two BAPIs

that  retrieve  the  list  and  detail  of  Sales Orders  /  Line  Items.  The  data

model  is pretty simple. We have one entity  for  the Sales Order header

data, and one entity for the Sales Order Line Item.

The  two  BAPIs  that  we  will  use  in  our  service  are:

BAPI_EPM_SO_GET_LIST and BAPI_EPM_SO_GET_DETAIL

This guide  is based on SAP NetWeaver Gateway 2.0 SP5. We will  be

mainly  using  the  SAP  NetWeaver  Gateway  Service  Builder  for  the

service  creation.  The  Service  Builder  allows  us  to  build  our  service

without writing a single line of code (although you still can do coding – if

you want…).

In  this  first  part  (1)  we  will  build  a  Meta  Model  of  the  service.  In  the

second part (2) we will perform the service implementation.

So let’s get started.

1. Create a new project ZGW100_XX_SO  (SO stands for Sales Order).

XX  is  just a placeholder  for a group number and GW100  indicates  the

course  number  –  as  the  screen  shots  were  taken  from  the  GW100

training course material that I have created.

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 3/23

2. Create  the  first  entity  by  importing  an RFC  interface.  For  this  right­

click on Data Model and choose Import ­> RFC/BOR Interface

3. Enter the following values in the wizard and then choose Next:

Entity Type Name SalesOrder

Target System Local

Data Source Type Remote Function Calls

Data Source Name BAPI_EPM_SO_GET_LIST

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 4/23

 

4. Expand the SOHEADERDATA node and select the following fields: 

SO_ID,    NOTE,    BUYER_ID,  BUYER_NAME,    CURRENCY_CODE, 

GROSS_AMOUNT, NET_AMOUNT,  TAX_AMOUNT    

Note that SOHEADERDATA is not selected. Choose Next.

5. In the first line, SO_ID, select the field Is Key and choose Finish:

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 5/23

6. Create the second entity again by importing an RFC interface. Right­

click Data Model and choose Import ­> RFC/BOR Interface

7. Enter the following values in the wizard and choose Next:

Entity Type Name SalesOrderItem

Target System Local

Data Source Type Remote Function Calls

Data Source Name BAPI_EPM_SO_GET_LIST

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 6/23

8. Expand the SOITEMDATA node and select the following fields: 

SO_ID,  SO_ITEM_POS,  PRODUCT_ID,  NOTE,  CURRENCY_CODE, 

GROSS_AMOUNT,    NET_AMOUNT,    TAX_AMOUNT,    QUANTITY, 

QUANTITY_UNIT

Note that SOITEMDATA is not selected. Choose Next.

9. In the first and second line, SO_ID,  SO_ITEM_POS, select the field Is

Key and choose Finish:

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 7/23

Now our project has 2 entities – one for the Sales Order and one for the

Sales Order Line Item. As a next step we create entity­sets out of these

entities.

1. Expand the node Data Model and double­click Entity Sets: 

2. Click the Create button twice to add two new lines to the table:

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 8/23

3. Enter the following values:

Name Entity Type Name

SalesOrderCollection SalesOrder

SalesOrderItemCollection SalesOrderItem

4. Choose Save:

Now  the  basic  definition  of  the Model  is  done.  As  a  next  step we  can

generate the necessary runtime artifacts.  

1. Choose the Generate pushbutton:

 

2. Leave the default values and choose Enter:

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 9/23

Please note the Technical Service Name ZGW100_XX_SO_SRV is equal

to the External Service Name required to consume this service later on.

3. Choose Local Object:

4. Verify that the runtime objects have been generated successfully:

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 10/23

Now we can Register and Activate the Service.

1. Double­click Service Maintenance:

2. Select system ZME and choose the Register button. Please note that

the  entries  listed  here  depend  on  the  System  Alias  configuration  you

have  done  in  the  SAP  NetWeaver  Gateway  Implementation  Guide

(IMG). In a local deployed environment (Backend and Hub components

deployed on  the same box) you might also  find  “LOCAL” with  the RFC

destination “NONE” here.

3. Confirm the warning message displayed in the popup:

4. Press F4 to select the system alias. Select ERP_EMEA from the input

help. Please note that you won’t get any popup if there is only 1 System

Alias  maintained.  As  mentioned  above,  depending  on  the  deployment

method  and  IMG  configuration  you  possibly  see  an  alias  “LOCAL”

instead of the ones shown in the screen shot:

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 11/23

5. Confirm the Select System Alias popup:

6. Leave the default values and enter $tmp as the package and choose

Enter:

The  External  Service  Name  is  defaulted  with  the  Technical  Service

Name from the Generation Step.

7. Verify that the service has been registered and activated successfully:

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 12/23

Alert Moderator

Now we can  run our service  the  first  time. Please note  that we’ve only

maintained  the  basic  model  data  so  far.  As  a  consequence  we  can

access the metadata of the service, but not yet any business data (that

will come in part 2).

1. Open a new window, start transaction /IWFND/GW_CLIENT.

2.  Enter  URI:    /sap/opu/odata/sap/ZGW100_XX_SO_SRV/$metadata

and choose Execute:

ZGW100_XX_SO_SRV is the External Service Name that was registered

before.

So we are done –  for  the moment. We have created a Service Builder

Project  with  two  entities  and  two  entity­sets.  We  have  generated  the

runtime artifacts and registered and activated our OData service. In part

2 we will map the data provider to bring life into our OData service.

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 13/23

25 CommentsYou must be Logged on to comment or reply to a post.

Hi Drees,

 Nice Blog.

 When i am trying to create project through SEGW project is created success but

in import menu option i am not getting BAPI/RFC Interface tab.

 Ref: Using SP04

 Thanks,

Syam.

Hi Syam,

that is correct. The mentioned features are available as of GW2.0

SP5.

 Best Regards,

Volker

Hi Drees,

 Thanks for the information.

Syam Babu

November 15, 2012 at 9:56 am

Volker Drees  Post author

November 15, 2012 at 12:11 pm

Syam Babu

November 15, 2012 at 12:31 pm

3/13/2017 Step­by­step guide to build an OData Service based on RFCs – Part 1 | SAP Blogs

https://blogs.sap.com/2012/10/26/step­by­step­guide­to­build­an­odata­service­based­on­rfcs­part­1/ 14/23

hi, someone can help me?

I followed step by step your guide, but it does not work,

the service when I call SalesOrderCollection or

SalesOrderItemCollection gives me an error like this:

Matteo Somensi

May 12, 2014 at 7:21 am

Thanks! Very clear and precise.

 Nick.

Nick Archontis

July 11, 2013 at 6:35 pm

Excellent blog, thanks Volker.

Phillip Parkinson

July 24, 2013 at 2:36 pm