Providing Enterprise Data Simply via SAP BSP - First Steps


Overview

Today, I want to share a very handy approach with you about building simple web services in SAP. It's a lightweight alternative to the SOAP web services. I mostly try to avoid building SOAP web services, since they provide very thick interfaces, always need to regenerate the proxies and so on, so it can be a nightmare in complex cases (at least for me). I usually prefer building RESTful web services using the SAP Netweaver Gateway, but what if I don't have it?

To demonstrate the approach, we are going to build a simple web service that uses JSON format and deals with flight schedules.

Today lesson

How to build a simple one-page BSP Application in SAP


Create a BSP Application

The first task is to create an empty BSP application in the transaction SE80 that we name as ZFLIGHTS.


Create a Page with Flow Logic

The next task is to create a simple page that we name as schedules, with the page type Page with Flow Logic. We mostly use the page type,

  • View for larger applications that follows the MVC design pattern (the program flow is driven by the controller)
  • Page with Flow Logic for small and simple applications (executable on its own, using a simple URL)
  • Page Fragment for modularizing complex pages


Mock JSON Response

The requirement is providing Flight Schedules in JSON format that now we are going to simply mock out as placing simple hard-coded JSON string in the layout (so if we call our service URL, then it will simply return this JSON back):

{
  "FLIGHTSCHEDULES":
  [
    {
      "MANDT": "800",
      "CARRID": "AA",
      "CONNID": "0017",
      "COUNTRYFR": "US",
      "CITYFROM": "NEW YORK",
      "AIRPFROM": "JFK",
      "COUNTRYTO": "US",
      "CITYTO": "SAN FRANCISCO",
      "AIRPTO": "SFO",
      "FLTIME": 361,
      "DEPTIME": "11:00:00",
      "ARRTIME": "14:01:00",
      "DISTANCE": 2572,
      "DISTID": "MI",
      "FLTYPE": "",
      "PERIOD": 0
    },
    {
      "MANDT": "800",
      "CARRID": "AA",
      "CONNID": "0064",
      "COUNTRYFR": "US",
      "CITYFROM": "SAN FRANCISCO",
      "AIRPFROM": "SFO",
      "COUNTRYTO": "US",
      "CITYTO": "NEW YORK",
      "AIRPTO": "JFK",
      "FLTIME": 321,
      "DEPTIME": "09:00:00",
      "ARRTIME": "17:21:00",
      "DISTANCE": 2572,
      "DISTID": "MI",
      "FLTYPE": "",
      "PERIOD": 0
    }
  ]
}

Of course, later on we are going to replace this hard-coded JSON to real data extraction, formatting and messaging.


Set MIME Type

As a last step, we have to set the MIME type of the page to simple application/json, since as a result we want JSON.


Test Your BSP Application

Now comes the best part of building something from scratch, namely running the app. For this, simply let's right-click on your BSP application and choose the option, Test! The URL is made of the followings:

<Prot>://<Host>.<domain>.<extension>:<Port>/sap/bc/bsp/<namespace>/<application name>

My URL looks like this:

http://xxxx.xxxx.com:xxxx/sap/bc/bsp/sap/zflights/schedules


Summary

Have you got the JSON message after running your BSP app? I hope, you could follow me, and everything went fine. If not, then don't hesitate to leave me a comment below!

Now, you have a simple service in SAP that you can consume, let's say from a Xamarin mobile app for example. :)


blog comments powered by Disqus