Skip to Content

A couple of weeks we held a spotgroup (knowledge sharing session) in the company I work for. It was one of the most busy NetWeaver spotgroups handons sessions ever. We literally had to extend the room!

Handson

Together with a couple of colleagues we organised a handson session to get aquanted with NetWeaver Gateway and consuming those services. For you all to enjoy I decided to simplify and shorten the exercises a bit and share it here. In 2 blogs we will create a NetWeaver Gateway service and consume the service in a SAPUI5 app, using the just released appBuilder. It assumes no handson knowledge on NetWeaver Gateway and SAPUI5 at all, and it is a first step to get aquanted with the topics.

Still interested? sure you are, good! Let’s start;

NetWeaver Gateway

NetWeaver Gateway enables us to perform CRUD operations on data from our SAP system via OData.

The BAPI we will expose as a service is:

0_bapi_sflight.JPG

Note: To perform this steps a NetWeaver Gateway system is required, if you do not have it at your disposal, the ES workplace demo services can be used as service. In the 2nd blog you could then consume those services in a mobile app.


Create project

To start building our service, we need to create a project in the NetWeaver Gateway service builder.

Open the gateway service builder by starting the transaction ‘segw’ in your gateway system. Use the create button to create a new project (The package ‘ZSCN’ was created before).

1_segw create project.JPG

Create entity

After creation of the project we define our entity. There are various ways to create an entity, we choose to base it on an BAPI

Right click on data model and pick ‘import RFC/BOR interface’.

Define the entity name and the BAPI:

BAPI_FLIGHT_GETLIST

3_ create entity.JPG

Select the ‘FLIGHT_LIST’ as data source parameters

3_ create entity step2.JPG

Configure the AIRLINEID and CONNECTID as key.

3_ create entity step3.JPG

The following message should appear;

3_create entity_step succes.JPG

We could use the import parameters of the BAPI as filter option, so let’s setup the Airlineid as ‘filterable’. See below:

4 - set filterable.JPG

Since the entity name is taken from our BAPI parameters naming, we like to rename it to FLIGHT.

5_rename entity.JPG

Create entityset

Based on our entity we want to create an entitySet

6 create entitySet.JPG


Service implementation

Move down in your project to the entry ‘service implementation’. We would like to create a getEntitySet query which will give us a list of flights.

Use right mouse button and  ‘create mapping’ to start performing the mapping of our entityset to a BAPI.

7 move to getentityset implementation- right mouse button create mapping.JPG

Choose the BAPI you would like to map.

Note: the BAPI we selected in the beginning was just the definition of our entity, it did not call or expose any BAPI yet. We will do that now.

8. choose the bapi for mapping.JPG

Use propose mapping to perform a default export mapping for your BAPI.

9. propose mapping - should fill all fields.JPG

Click the ‘+’ to add another entity set property.

Pick Airlineid again, as property.

10.add field again to mapping with plus sign.JPG

Map it to the Airlineid input parameter of the BAPI.

11. airline id map to input parameter of bapi by selecting and okay.JPG

This will give us later on the possibility to filter the list of flights based on airlineid.

The end result of the mapping should be like this:

12 end result mapping.JPG

Generate

Since mapping is done, we basically ready to generate, yes generate our service implementation.

We need to the magic button on top to start this proces.

13. generate!.JPG

When generation is finished, classes should be generated.

14. messages log after generate - succes!.JPG


Register

Only thing left is to register our service;

Scroll fully down in your project in the left pane and go to service maintenance. In this menu you should see at least your own gateway service registered and probably others. Open up your own system to register the just created service on this gateway stack.

After opening your system go to the right pane and in top bar, use ‘register’ to register your service.

15. register service - via register service button in service maintenance menu in tree.JPG

During registration we select ‘LOCAL’ as our system, where we would like to register our service.

After registration our service registration list should show a succesfull registration;16. click on maintain service to see the service registry and to be able to test.JPG

Test results

Click on maintain to open ‘service maintenance’.

A new transaction (/IWFND/MAINT_SERVICE) opens, in here we can normally see all registered service, in this case we only see our service, since we navigated starting from our project.

See the bottom left pane, we can decide to test our service in the browser or in the system itself via the build-in gateway client.

Let’s open the gateway client.

17. start GW client.JPG

A similar URL will appear when you start gateway client. Click on execute to see what happens, and if your service can actually be reached;

18 gw client - start.JPG

To retrieve the list of flights, fill in a similar url as below;

19. change url to this and see result.JPG

The result will show the list with flights as follows in atom-xml format;

20. service all flights result.JPG

Since we also setup a filter in our service we can see the result of this call as well. We need to add the $filter to the url, in this case filter the list on field Airlineid, which must be equal to LH. (Lufthansa).

21. use filter url.JPG

See an example result below;

22 check filtered result.JPG

Closure

Congratulations! You’ve succesfully build a simple service using SAP NetWeaver Gateway, please continue to step 2, to build an app with SAPUI5 in the appbuilder  consuming the list with flights.

Hope you enjoyed part 1 of this blog series, see you at part 2.

To report this post you need to login first.

12 Comments

You must be Logged on to comment or reply to a post.

    1. W. Snoep Post author

      Thanks Twan.

      Haha, you just mentioned it ;-).

      It was for sure a great evening, can’t wait to have more next year!

      Hopefully also SCN members will benefit, by having shared handson exercices here to get aquanted with topics as SAPUI5 and SAP NetWeaver Gateway.

      (0) 
  1. Jeroen Custers

    Nice blog Wim! I didn’t use the mapping function before. Much easier and faster than implementing the BAPI call in the redefined method in the *DPC_EXT class. Thanks!

    (0) 
  2. Arindam Samanta

    Hi,

    Excellent blog. Today I saw this. Its a very helpful blog and I really got the idea about NW gateway service. I am new in this area so I need to explore more.

    Thanks once again for your very kind and helpful blog.

    Regards,

    Arindam Samanta.

    (0) 

Leave a Reply