Top Banner

of 24

Step by Step Guide to Build an Odata Service Based on Rfcs Part 1

Mar 05, 2016

Download

Documents

chaithanya
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • Generated by Jive on 2015-11-14+01:001

    volker.drees: Step-by-step guide to buildan OData Service based on RFCs Part1

    Posted by Volker Drees Oct 26, 2012Hello fellow OData Service developers out there.

    When it comes to OData Service development with SAP NetWeaver Gateway a very typical usecase is to build a service that is based on an RFC module (or a set of RFC modules) e.g. for aList / Detail application. For such a scenario there are dozens of RFC modules (BAPIs) availablein 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 dont satisfy your needs...

    For additional information regarding the Service Builder please also see Thomas Meigens Blog: The new SAPNetWeaver 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 retrievethe list and detail of Sales Orders / Line Items. The data model is pretty simple. We have one entity for theSales 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 andBAPI_EPM_SO_GET_DETAILThis guide is based on SAP NetWeaver Gateway 2.0 SP5. We will be mainly using the SAPNetWeaver Gateway Service Builder for the service creation. The Service Builder allows us to buildour 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 serviceimplementation.

    So lets get started.

    1. Create a new project ZGW100_XX_SO (SO stands for Sales Order). XX is just a placeholder fora group number and GW100 indicates the course number as the screen shots were taken fromthe GW100 training course material that I have created.

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:002

    2. Create the first entity by importing an RFC interface. For this right-click on Data Model and choose Import ->RFC/BOR Interface

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:003

    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

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:004

    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.

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:005

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

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:006

    6. Create the second entity again by importing an RFC interface. Right-click Data Model and choose Import ->RFC/BOR Interface

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:007

    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

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:008

    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.

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:009

    9. In the first and second line, SO_ID, SO_ITEM_POS, select the field Is Key and choose Finish:

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0010

    Now our project has 2 entities one for the Sales Order and one for the Sales Order Line Item. Asa next step we create entity-sets out of these entities.

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

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0011

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

    3. Enter the following values:

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0012

    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 necessaryruntime artifacts.

    1. Choose the Generate pushbutton:

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0013

    2. Leave the default values and choose Enter:

    Please note the Technical Service Name ZGW100_XX_SO_SRV is equal to the External Service Namerequired to consume this service later on.

    3. Choose Local Object:

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0014

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

    Now we can Register and Activate the Service.

    1. Double-click Service Maintenance:

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0015

    2. Select system ZME and choose the Register button. Please note that the entries listed heredepend on the System Alias configuration you have done in the SAP NetWeaver GatewayImplementation Guide (IMG). In a local deployed environment (Backend and Hub componentsdeployed on the same box) you might also find LOCAL with the RFC destination NONE here.

    3. Confirm the warning message displayed in the popup:

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0016

    4. Press F4 to select the system alias. Select ERP_EMEA from the input help. Please note that youwont get any popup if there is only 1 System Alias maintained. As mentioned above, dependingon the deployment method and IMG configuration you possibly see an alias LOCAL instead ofthe ones shown in the screen shot:

    5. Confirm the Select System Alias popup:

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0017

    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:

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0018

    Now we can run our service the first time. Please note that weve only maintained the basicmodel data so far. As a consequence we can access the metadata of the service, but not yet anybusiness 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:

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0019

    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 andtwo entity-sets. We have generated the runtime artifacts and registered and activated our ODataservice. In part 2 we will map the data provider to bring life into our OData service.72307 Views Tags: mobile, sap_netweaver_gateway, gateway, odata, netweaver_gateway, service_builder

    Nishant KumarSep 23, 2015 6:20 AMGreat Note on OData Services. Thank you so much.

    Kavitha Fredrick in response to Volker Drees on page 19Jul 15, 2015 8:00 AMDone..

    Thanks

    Volker Drees in response to Kavitha Fredrick on page 19Jul 14, 2015 3:33 PMHi Kavitha,the mentioned buttons are typically greyed out if the project has not been generated. In that case no runtimeartifacts exist which can be used for e.g. registration.

    Can you please try to generate the project and check if the buttons are still disabled?

    Best Regards, Volker

    Kavitha FredrickJul 14, 2015 7:22 AMHi Volker,

    This is an excellent document. Thank You.

    During "Service Maintenance", after I select the system, I see all buttons like "Register,Maintain, Error Log andGateway Client" are disabled(greyed out). What cloud be the reason?

    Please help. Is that role assignment issue?

    Regards,Kavitha

    Archana BellamkondaJun 2, 2015 12:23 AMThank you for the blog. It was really helpful to get started.

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0020

    -Archana

    Volker Drees in response to Arshad Ansary on page 20Jan 23, 2015 5:22 PMHi Arshad,I assume you are on 7.40? Have you tried to use "Add Service" to add the GWSAMPLE_BASIC service if it isnot yet present in the list of registered services?

    As per the pagination in a SELECT statement, you can only use the "up to x rows" statement to reduce thenumber of items to be read. As a consequence the efficiency is higher if you are browsing the first pages ofyour entityset.

    In my example I first prepare some helper varaibles (all of type i):

    lv_top = io_tech_request_context->get_top( ). lv_skip = io_tech_request_context->get_skip( ). IF ( lv_top > 0 ). lv_maxrows = lv_top + lv_skip. ENDIF.

    And in the SELECT statement I use the lv_maxrows variable to limit the number of records to be read. sy-dbcnt helps me to skip the records at the beginning (though they still need to be read from the DB). Sorting andfiltering takes place along with the SELECT statement.

    SELECT INTO () FROM ( ) UP TO lv_maxrows ROWS WHERE (lv_where_clause) ORDER BY (lv_orderby_clause).

    IF ( sy-dbcnt > lv_skip ). APPEND ls_entity TO et_entityset. ENDIF. ENDSELECT.

    hthBest Regards, Volker

    Arshad Ansary in response to Volker Drees on page 21Jan 23, 2015 5:07 AMHi Volker,

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0021

    I am in SP10 and I am not able to find your sample service GWSAMPLE_BASIC in /IWFND/MAINT_SERVICE.Can you post the code of pagination handling in select

    if we can limit the records at the select itself(instead of at the DPC classes),we can hugely improve theperformance.

    Moreover how the pagination should work along with sort is also a question. Because ideally sort shouldhappen first and then top skip pagination should happen next.

    In our project we are currently getting all records from DB and then doing sorting and pagination after thatwhich is affecting perfomance

    RegardsArshad

    Martin Maruskin in response to Volker Drees on page 21Jan 14, 2015 7:52 PMThanks for clarifying this, much appreciated!

    Volker Drees in response to Martin Maruskin on page 21Jan 14, 2015 4:04 PMHello Martin,the BAPI BAPI_EPM_SO_GET_LIST unfortunately does not expose the parameter IS_PAGING_OPTIONS.Therefore it is not possbile to use it when calling the BAPI.

    In the generated DPC method (...GET_ENTITYSET) the paging is handled out of the box. But this is donein a generic way - after the BAPI has provided the full list. You can adjust the generated coding to fill theMAX_ROWS parameter based on the paging request. That can improve the performance when calling theBAPI.

    I'm not aware of any standard BAPI that supports full paging. If you have access to a NW 7.40 system withSAP_GWFND SP8 installed you can check my sample service (/sap/opu/odata/IWBEP/GWSAMPLE_BASIC) which implements the paging by performing a direct databaseaccess (SELECT).

    Best Regards, Volker

    Martin MaruskinJan 14, 2015 2:42 PMHi Volker,

    interesting blog! I have a question whether pagination can be done within your example - BAPIBAPI_EPM_SO_GET_LIST. I see that within the code of the BAPI the pagination related parameter

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0022

    (IS_PAGING_OPTIONS) of method QUERY_BY_HEADER are not passed. So I not think it is supported butmaybe you found a way for this...

    In case you agree with me that no pagination supported by the above mentioned BAPI... Are you aware of anyother standard SAP BAPI which supports pagination functionality within the result set?

    thanksm./

    Volker Drees in response to Arshad Ansary on page 22Jun 13, 2014 3:49 PMHi Arshad,the reason for not marking SOHEADERDATA was to keep the Entity Type name that you defined on the firstpage of the wizard. The blog was created based on GW 2.0 SP5. Now with SP8 (and SP9 coming soon) thebehavior of SEGW has changed a bit. So it's not a problem if the SOITEMDATA or SOHEADERDATA nodesare marked. You just need to make sure that you get the expected Entity Type name in the end.Also the Entity-Sets you do not need to add manually anymore. This is done using the "Create Default EntitySet" check-box automatically.

    As per the 2nd error it's more tricky to say what is wrong. I learned that you e.g. need to have the certificatesgenerated in STRUSTSSO2. But there might be more steps necessary.

    Best Regards,Volker

    Arshad AnsaryJun 11, 2014 10:23 AMHi Volker,

    Thanks for the blog. This is very helpful for beginners in Gateway.I followed your steps and I registered the service using /iwfnd/maint_service in LOCAL server.

    1 While creating data model for Gateway servcice , I am not able to select the individaul fields w/o selecting theSOITEMDATA and SOHEADERDATA nodes.

    2 I am not able to test the service in /IWFND/GW_CLIENT it syas some HTTP error. But I copied the URL andpaste it in chrome browser . I am able to get the result but the individual fields in Entity is not shown

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0023

    RegardsArshad

    Matteo Somensi in response to Volker Drees on page 24May 12, 2014 9:21 AMhi, someone can help me?I followed step by step your guide, but it does not work, the service when I call SalesOrderCollection orSalesOrderItemCollection gives me an error like this:

    Akhila MDec 4, 2013 6:14 AMThanks so much Volker, It is really helpful

    Phillip Parkinson

  • volker.drees: Step-by-step guide to build an OData Service based on RFCs Part 1

    Generated by Jive on 2015-11-14+01:0024

    Jul 24, 2013 4:36 PMExcellent blog, thanks Volker.Maybe worth mentioning the EPM Data Generator transaction is sepm_dg for those that are using a freshsystem without data yet.

    CheersPhillip

    Nick ArchontisJul 11, 2013 8:35 PMThanks! Very clear and precise.

    Nick.

    Syam Babu in response to Volker Drees on page 24Nov 15, 2012 1:31 PMHi Drees,

    Thanks for the information.

    Volker Drees in response to Syam Babu on page 24Nov 15, 2012 1:11 PMHi Syam,that is correct. The mentioned features are available as of GW2.0 SP5.

    Best Regards,Volker

    Syam BabuNov 15, 2012 10:56 AMHi Drees,

    Nice Blog.

    When i am trying to create project through SEGW project is created success but in import menu option i am notgetting BAPI/RFC Interface tab.

    Ref: Using SP04

    Thanks,Syam.