Beruflich Dokumente
Kultur Dokumente
Tweet
With this blog we would like to introduce the new Service Builder in SAP NetWeaver Gateway
and its various options for building OData services for SAP NetWeaver and SAP Business Suite
data.
Consuming OData in any kind of app is fairly easy. OData SDKs are available for all relevant
client technology and for the most important ones there are already dedicated developer
tools, which help any kind of developer to jump-start his app development by consuming
available OData services. To get started with OData consumption for SAP NetWeaver
Gateway, SDN includes several toolkits for instance for iOS, Android, JSE, PHP or HTML5.
What easily gets overlooked is the fact, that nearly always the right OData service first has to
be built before it can be consumed. The number of out-of-the-box OData services is and may
remain limited. When you think about it, this quite logical, because OData services by nature
are fine granular and mostly tailored to the use case. In that sense they are quite different
from comprehensive Enterprise Services in A2A scenarios, where resources like bandwidth,
memory and CPU power are less critical. Learnings from app development projects show that
up to 50% of development time can go into building the right OData service.
The picture below shows the various options that are covered in SEGW:
For the definition of a new data model you will find different options inside SEGW. You can
define all elements of the OData service step by step using the various editors within the
transaction. If your data model is similar to an existing data structure (like an RFC or BAPI)
inside of the DDIC, you can also import that structure. Alternatively, if you already have an
existing OData model definition in appropriate EDMX format, you can import that from a file.
At any time, you can check the consistency of the data model and SEGW will show you
existing issues and guide you there. Also, as soon as you have a valid data model you can
already activate the service and display the service document and the metadata in a
browser.
Things become very interesting, when you have the right business framework in your SAP
Business Suite landscape. If there is any data object available which contains the data that
you are looking for, you actually can ask SEGW to generate an OData service from that
object. Guided by wizards you simply select the data (entity types and properties) that you
need and rename ("redefine") them to make them look OData style. Redefinition is already
supported for BW Easy Query, SPI, GenIL and BOL with thousands of well-defined business
objects. With the redefine option you will also get the implementation of the service
operations for free and can immediately execute the resulting OData service.
But perhaps already one of the many thousand RFCs or BAPIs in the SAP Business Suite
already does the right job. Then you can map the RFC or BOR operations to your data model.
In that case SEGW generates the entire ABAP runtime logic.
As soon as you have a valid data model you can already activate the service and check out
the service document and the metadata.
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 (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 dont 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.
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.
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.
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:
5. In the first line, SO_ID, select the field Is Key and choose Finish:
6. Create the second entity again by importing an RFC interface. Right-click Data Model and
choose Import -> RFC/BOR Interface
9. In the first and second line, SO_ID, SO_ITEM_POS, select the field Is Key and choose Finish:
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.
2. Click the Create button twice to add two new lines to the table:
3. Enter the following values:
4. Choose Save:
Now the basic definition of the Model is done. As a next step we can generate the necessary
runtime artifacts.
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.
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:
Now we can run our service the first time. Please note that weve 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).
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.
Step-by-step guide to build an OData Service
based on RFCs Part 2
Posted by Volker Drees in volker.drees on Oct 26, 2012 11:44:38 AM
Tweet
Hello again.
In the first part (1) we have created a service that consists of two entities (Sales Order and
Sales Order Line Item) and two related entity-sets. The runtime artifacts have been
generated and the OData service has been registered and activated.
In this part (2) we will map both entity-sets to the related data providers in our case the 2
EPM BAPIs.
When it comes to data provider mapping / implementation of OData services you usually
start with the Query method as this is a typical entry point when consuming a service. In our
case we will first enable the query: provide me all Sales Orders that exist. In a real business
case you would probably make some filtering mandatory to not overload the backend
system. But lets keep it simple for the time being
1. As mentioned we will start with the Query method for the SalesOrderCollection entity-set.
Expand the node Service Implementation -> SalesOrderCollection and right-
click GetEntitySet (Query) and select Map to Data Source:
2. In the map to data source window, enter the following values and choose Enter:
Target System Local
Data Source Type Remote Function Call
Data Source Name BAPI_EPM_SO_GET_LIST
3. The mapping has already done because the data model has been built based on the same
RFC interface. For each property, set the Mapping Direction to Output. Choose Enter:
Now we can move on and do the mapping for the Read operation (GetEntity) of the
SalesOrderCollection.
1. Right-click GetEntity (Read) and select Map to Data Source:
2. In the Map to Data Source dialog box, enter the following values and choose Enter:
Target System Local
Data Source Type Remote Function Call
Data Source Name BAPI_EPM_SO_GET_DETAIL
3. This time there are no default mapping settings because the data model has been defined
based on a different RFC module.
Expand the HEADERDATA node from the tree on the right-hand side:
4. Drag&drop the following fields from the right-hand tree to the Data Source
Parameter column of the grid in the middle of the screen:
RFC Field (right hand side) Entity Property
SO_ID SoId
NOTE Note
BUYER_ID BuyerId
BUYER_NAME BuyerName
CURRENCY_CODE CurrencyCode
GROSS_AMOUNT GrossAmount
NET_AMOUNT NetAmount
TAX_AMOUNT TaxAmount
In any Read Operation we also need to provide the primary key of the underlying entity as an
input parameter. For this we have to manually add a new line to the mapping screen.
3. Expand the SO_ID node from the tree on the right-hand side:
4. Drag&Drop the RFC field SO_ID (from node SO_ID) to the newly-created line:
5. This performs the mapping on the input parameter (Sales Order ID to fetch the Sales Order
details):
Now we can move on with mapping the Query operation for the Sales Order Item entity-set
2. In the Map to Data Source dialog box, enter the following values and choose Enter:
4. Drag&drop the following fields from the right-hand tree to the Data Source
Parameter column of the grid in the middle of the screen:
7. From the input help, select SoId for the new line:
Now we are done with the data provider mapping (at least for the Query and Read operations
we need). Now we can re-generate the runtime artifacts and run our OData service.
5. Get the related sales order line items via the following URL:
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/SalesOrderItemCollection/?$filter=SoId eq
'0500000001'
To navigate from the Sales Order entity to the related line items (Entity-Set), you need to
construct the URI yourself. In the next part (3) you will see how to define an association and a
navigation property between the two Entities.
Step-by-step guide to build an OData Service
based on RFCs Part 3
Posted by Volker Drees in volker.drees on Oct 26, 2012 11:45:07 AM
Tweet
Looking into this part (3) means that you have successfully completed the first part (1) and
the second part (2) and you are now curious to see how our EPM OData Service will be
extended with an Association and a Navigation Property. This will allow us to navigate from
the Sales Order to the related Sales Order Line Items by using a link instead of manually
putting a filter together. Furthermore this also allows us to use the $expand statement to
fetch the Sales Order together with all Sales Order Line Items in one http call.
We are still in the Service Builder and enhancing our project that we created in part 1 and
extended in part 2.
1. Double-click Associations:
3. Enter the following values for the Association and choose Enter:
Name SalesOrderSalesOrderItems
Principal Entity* SalesOrder
Principal Entity Cardinality* 1
Dependent Entity* SalesOrderItem
Dependent Entity Cardinality* M
*) This field has an input help
Name SalesOrderSalesOrderItems
Association* SalesOrderSalesOrderItems
*) This field has an input help
1. Expand Data Model -> Entity Types -> SalesOrder and double-click Navigation Properties:
2. Choose the Create pushbutton:
Name SalesOrderItems
Relationship Name* SalesOrderSalesOrderItems
*) This field has an input help
Now we need to re-generate the runtime objects and were then ready to test the service
I hope you enjoyed creating and consuming an OData Service that is based on RFC modules.