You are on page 1of 12

Pgina 1 de 12

(/)
SEARCH

()

Bluefin (/) Lindsay Stanger (/blogs/lindsay-stanger) Building your first simple Gateway service

Building your first simple Gateway service


Lindsay Stanger (/Blogs/Lindsay-Stanger/), Enterprise Mobility Consultant, Bluefin

Published in 7 Categories - Tuesday 04 March 2014

Related

Getting started with SAP Fiori, NetWeaver Gateway & SAPUI5 (/Blogs/John-Murray/April-2014/Getting-started-with-SAPFiori,-NetWeaver-Gateway)
Introducing SAP Fiori as part of an SAP S/4HANA project (/Blogs/Lindsay-Stanger/March-2016/Introducing-SAP-Fiori-aspart-of-a-SAP-S-4HANA-pro)

I imagine youre reading this because youve either just installedSAP NetWeaver Gateway, or are considering
installingit. Well Im here to tell you that, from where Im standing, it looks like the future of SAP will rely
heavily upon it, so youre making the right steps!
1. Purpose
SAP NetWeaver Gateway is an enabling component of SAP which allows you to expose data from one or many systems to the outside world.
The underlying systems are usually SAP ones (SAP ECC, SAP CRM, SAP ERP and so on. ) but it is important to note that you can use Gateway
with non-SAP systems too.

Now you all have a basic understanding of what Gateway is, youre ready to get on with the fun bit!

Pre-requisites for this exercise


SAP system (ERP / ECC / CRM)
SAP NetWeaver Gateway Release 2.0 Support Package 4 or above
Free Gateway trial download here (http://scn.sap.com/community/developer-center/netweaver-gateway)
Some basic understanding of ABAP and databases
In this document I will use SAP ERP with integrated Gateway, i.e. both on the same box. But I will explain as I go along how this would differ if
your Gateway instance is separate.
The data I will exposewill be SFlight data, both the Flights (SFLIGHT) and Carrier (SCARR) database tables. SFlight is a standard set of tables
and data which comes free with SAP systems. To find out more about SFlight please visit this post.

2. Create a new project using the Service Builder


Login to ERP and navigate to transaction SEGW

We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

27/10/2016

Pgina 2 de 12

Click on Create Project

Chose a project name, give your project a description and select Standard generation strategy.
In my example I will be creating the service as a local object.

2.1 Create an entity Carrier from table SCARR


Right click on Data Model, and select Import > DDIC Structure.

Enter the name of the ABAP Dictionary Structure you want to use, and hit enter. In our example we are using SCARR.

We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

27/10/2016

Pgina 3 de 12

Enter an Object Name, this will be the name of your entity. Select any fields to not include (ignore) and ensure the correct key is selected.

You can now change the names of any of the properties.

2.2 Create an entity set Carriers


Double click on Entity Sets on the left hand side, and chose Append Row. Enter an entity set name usually a pluralisation of the Entity
name, which in our example is Carriers.

Chose the appropriate entity on which to base this entity set

2.3 Generate the Service


In order to use the service with the changes you have made you will first need to generate it. This will create the underlying ABAP classes for
you, containing all the information youve specified thus far in the service builder. Anytime you make a change in the service builder you will
need to generate again, to ensure the ABAP classes are up-to date.
Select the project name that you wish to generate, and click the generate wheel.

Enter names which you want the underlying classes to have.


We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

27/10/2016

Pgina 4 de 12

It is best practice for the model provider class name to end in _MPC and the data provider class to end in _DPC. The extension classes of these
should be named the same as their corresponding base class, with the additional suffix of _EXT.
Generating can take a few moments, so dont worry if it isnt instant. Once it is complete you will see a detailed log of successes, warnings and
errors. If you have done everything right this should be all green.

3. Activate the new Service


In order to be able to use your service you will first have to activate it. This means adding it to a list of services which can be reached through
Gateway. Because I am using integrated Gateway this is done in the same system, however for those of you using a separate Gateway
instance, login to you Gateway server first.
Navigate to transaction /IWFND/MAINT_SERVICE

We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

Click Add Service

27/10/2016

Pgina 5 de 12

Because my Gateway instance is on the same box as my ERP, I enter LOCAL as the system alias. To learn more about setting up system
aliases you can read this document.
Enter the name of your service and hit enter.

Select your service from the list.

Hit save and navigate back to the Activate and Maintain Services screen. Scroll down the list of services to find your one.

4. Test the Service from a browser


We now want to see if our service is accessible from the web, to validate whether we have set it up correctly.
Click the Call Browser button in the bottom left section of the screen.
If your call was successful you will see something like this:

We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

27/10/2016

Pgina 6 de 12

Now we can modify the URL so the suffix is $metadata?sap-ds-debug=true

Here we can see our Carrier entity, with its properties, and the fact that there is an entity set associated with this entity.
If we change the URL again to end in /Carriers?sap-ds-debug=true we will see this error message:

This is because we havent yet told our service how to read Carrier information from the SCARR database table.

5. Add ABAP to populate the Carriers


Navigate back to the Gateway Service Builder, SEGW.
Expand Service Implementation > Carriers
Right click on Get EntitySet (Query) and select Go to ABAP Workbench

We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

27/10/2016

Pgina 7 de 12

Click the tick on the warning message

This then takes you into the ABAP Class where you will need to build your implementation.
Click on display object list

Find the CARRIERS_GET)ENTITYSET method of the left hand side, right click on it, and chose Redefine.

We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

27/10/2016

Pgina 8 de 12

Enter this code into the newly redefined method:


select * from scarr into corresponding fields of table et_entityset.
Then hit activate.

6. Test the Service from a browser


Return to your browser and refresh the page.

We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

As you can see we now get a stream of information back, detailing all the Carriers stored in the SCARR table in ERP.

27/10/2016

Pgina 9 de 12

7. Add another entity and link the two together


In this section we will create another entity set for Flights, and create a link between carriers and flights.

One airline carrier has many flights, but each flight has only one airline carrier.

7.1 Create an entity Flight with corresponding entity set from table SFLIGHT
Repeat the steps above to create a new entity Flight, and corresponding entity set Flights. This time, instead of basing it on the structure
SCARR we will use the structure SFLIGHT.

Dont forget to hit Generate when youre done!

7.2 Add ABAP to populate the Flights


Navigate to the ABAP workbench for the Flight entity.
Find the method FLIGHTS_GET_ENTITYSET, and redefine it.
Enter ABAP to select everything from the flights table.

Activate the code.


7.3 Test the Service from a Browser, to ensure the Flights entity has been added
Use the suffix Flights?sap-ds-debug=true on your URL to get back all the flights
We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

27/10/2016

Pgina 10 de 12

8. Create a navigation from Carrier to Flights


We want to be able to go from a specific carrier, to all the flights that carrier has. To do this we need to create a navigation in the service builder.
First we create a new Association:

Then we create the navigation:

Generate.
Now we need to modify the ABAP so that when we ask for a list of flights for a specific carrier we dont get back all the flights, we just get back
those relevant to us.
Navigate to the ABAP method FLIGHTS_GET_ENTITYSET.
Change the code to read:
data: ls_key like line of it_key_tab.
read table it_key_tab into ls_key with key name = 'Carrid'.
* If there is a carrier ID specified, use it to select only those for the specific carrier
if sy-subrc eq 0.
select * from sflight into corresponding fields of table et_entityset
where carrid = ls_key-value.
* If there is no carrier specified, read all the flights
else.
select * from sflight into corresponding fields of table et_entityset.
endif.

We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

27/10/2016

Pgina 11 de 12

IT_KEY_TAB is importing parameter of the method which will hold all keys which have been passed in. In our example it will contain a carrier ID f
the navigation is from Carrier, because Carrid if the key of the Carrier entity.

9. Test the Service from a browser


Use the URL suffix Carriers('AA')/Flights?sap-ds-debug=true to test whether your implementation has worked. If it has the list of results will
only show flights where the carrier ID is AA.

10. Wrap up
Congratulations, youve just built your first, easy Gateway service. Obviously this post does not go into the complexities of building a Gateway
service, but I hope it has given you an idea about where to begin.
For some interesting insights around, and beyond this topic its worth checking out the following:
Project Gateway - A call to arms, or at least to data (/Blogs/DJ-Adams/February-2011/Project-Gateway-A-call-to-arms-Or-at-leastto-da/) by DJ Adams
SAP Kapsel - what it is...and should we be excited? (/Blogs/DJ-Adams/February-2011/)by Brenton O'Callaghan
6 weeks, 3 apps and a sprinkle of SAPUI5 and Fiori customisation thrown into the mix. Challenge accepted! (/Blogs/LindsayStanger/February-2014/6-weeks,-3-apps-and-a-sprinkle-of-SAPUI5-and-Fiori/) by me!
SAP NetWeaver Gateway (/Technologies/SAP-Enterprise-Mobility/SAP-NetWeaver-Gateway/)
SAP NetWeaver Gateway (http://scn.sap.com/community/netweaver-gateway#) (on the SCN)

Published in:

Insight (/Insights/cat_Insight)

SAP Enterprise Mobility (/Insights/cat_SAPEnterpriseMobility)

Development (/Insights/cat_Development)

Gateway (/Insights/cat_Gateway)

How to (/Insights/cat_HowTo)

Mobile (/Insights/cat_Mobile)
We use cookies on bluefinsolutions.com
to ensure that weSAP
can (/Insights/cat_SAP)
give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

27/10/2016

Pgina 12 de 12

Read more from Lindsay


Introducing SAP Fiori as part of an SAP S/4HANA project (/blogs/lindsay-stanger/march-2016/introducing-sap-fiori-as-part-of-a-sap-s-4hanapro)
Using SAP Solution Manager for test management: how to support your Test Manager (/blogs/lindsay-stanger/january-2015/using-sapsolution-manager-for-test-management-how)
Building your first simple Gateway service (/blogs/lindsay-stanger/march-2014-(1)/building-your-first-simple-gateway-service)
View Lindsay's Profile ( /Blogs/Lindsay-Stanger/)

Want to know more?

Subscribe today

Sign up to our newsletters and receive leading industry insights from Bluefin.

Twitter (https://twitter.com/BluefinSolution)

Who we are (/About-us/)


What we do (/What-we-do/)
Clients (/Clients/)
Insights (/Insights/?tab=0)
Careers (/Careers/)
Events (/Events/Upcoming-Events/)
Contact (/Contact-Us/)

LinkedIn
(http://www.linkedin.com/company/24887)
RSS (/rss)

Bluefin: A Mindtree Company

Cookie policy (/privacy/cookie-policy)


2016 Bluefin Solutions

Legal information (/privacy/legal-information)


Privacy Policy (/privacy/privacy-policy)
Terms and conditions (/privacy/terms-and-conditions)

Mindtree delivers digital


transformation and technology
services to more than 2000
clients globally.
Find out more

Accessibility (/privacy/accessibility)
Site map (/privacy/site-map)

We use cookies on bluefinsolutions.com to ensure that we can give you the very best experience. To find out more about how we use cookies, please visit the cookie
policy (/privacy/privacy-policy) page.
Close (building-your-first-simple-gateway-service?cookiesViewed=true)

27/10/2016

You might also like