Está en la página 1de 17

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.
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 lets 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.

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


Target System
Data Source Type
Data Source Name

SalesOrder
Local
Remote Function Calls
BAPI_EPM_SO_GET_LIST

4. Expand the SOHEADERDATA node and select the


SO_ID, NOTE, BUYER_ID, BUYER_NAME, CURRENCY_CODE,
NET_AMOUNT,
TAX_AMOUNT
Note that SOHEADERDATA is not selected. Choose Next.

following fields:
GROSS_AMOUNT,

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

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

Entity Type Name


Target System
Data Source Type
Data Source Name

SalesOrderItem
Local
Remote Function Calls
BAPI_EPM_SO_GET_LIST

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:

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. Enter the following values:

Name
SalesOrderCollection
SalesOrderItemCollection

Entity Type Name


SalesOrder
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:

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:

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 wont 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:

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:

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).

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:

También podría gustarte