SAP Gateway is an ABAP framework part of SAP NetWeaver which allows you to create RESTful OData webservices on the SAP system. Data can be transmitted in either JSON or XML format. It’s a great solution to integrate SAP as a backend system into mobile or web applications (as opposed to the complexity and rigidity of PI and SOAP services).
To demonstrate how to use SAP Gateway to integrate SAP into an iOS 7 app, I have created a simple webservice for the well-known
SFLIGHT demo data (make sure to run the
SAPBC_DATA_GENERATOR program to generate some demo data first) in SAP, and an iOS 7 app which displays the data.
SAP Gateway uses so-called abstract ‘data provider’ and ‘model provider’ classes, inheriting from a bunch of other classes in the framework, which need to be implemented by you. The good news is a lot of this stuff will be generated once and implementing the custom parts is easy.
To create the model for this demo, start transaction
SEGW and create a new project named
ZSFLIGHTGW. Open the project and follow these steps:
1. Create an Entity Type named
Flights and enter
SFLIGHT as the ABAP structure name
2. Add the following properties:
1 2 3 4 5 6
3. Create an Entity Set named
4. Click the ‘Generate Runtime Objects’ button (the red-white circle) and accept the defaults
5. After generation, you should be able to see the generated service implementation and its operations
In this demo we will only read a list of SFLIGHT records, so the only operation which needs to be implemented is the
GetEntitySet (Query) operation. As you can see on the previous screenshot, the operation can be implemented with class
ZCL_ZSFLIGHTGW_DPC_EXT in the
6. Implement the
1 2 3
7. Create the webservice (with SAP customizing transaction
SPRO) as shown on these screenshots:
The webservice is now ready and you should be able to reach it at
https://yoursapserver.local:<port>/sap/opu/odata/sap/zsflightgw_srv?sap-client=<client> (replace <port> and <client> with proper numbers for your system). Performing a
GET request on that url (make sure you provide the correct credentials through HTTP basic authentication) should return something like this:
Adding the parameter
$format=json will have the server return a response in JSON format. So if you prefer to work with JSON instead of XML, you should always add this parameter to every request.
The app will show a list of flights and when tapping one of the flights it will display the details of that flight.
To perform the HTTP requests to SAP Gateway I use the AFNetworking framework. It makes performing HTTP requests a lot easier than the standard iOS SDK, and it powers some of the most popular and critically-acclaimed apps on the iPhone, iPad, and Mac.
SAPGatewayClient class provides the following method to retrieve all flights using SAP Gateway:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
And that is all you need to integrate SAP into your iOS app using SAP Gateway. Everything else is just common viewcontroller code and a storyboard. You can find the complete iOS project and source code on GitHub: SAP Gateway App Demo.