EDUCAÇÃO E TECNOLOGIA

ABAP in the cloud

I’ve been wondering for some time how running ABAP in the cloud could be turned into something more useful. Up until now I’ve had my trial account set up, and could create and run some classes and methods that created output in the console.

But outputting stuff to the console didn’t really make it useful.

So I started looking at how could I trigger my ABAP code running in the trial account from a browser. The solution turned out to be really simple. Create an HTTP-service in the trial account, attach a class, and voila – I could trigger my code and return output to the browser.

ABAP%20output%20in%20a%20browser

ABAP output in a browser

How to

  1. First you must have a trial account with a running ABAP environment. I will not go into details how to obtain and setup this. You can use the ABAP booster after creating your trial account. https://account.hanatrial.ondemand.com/trial/#/home/trial
  2. Then you need the latest version of Eclipse with ADT and login to your trial account.
  3. In Eclipse you create the HTTP service and service class.

Create HTTP service

Create a new object and use the wizard to start creation of the HTTP service:

HTTP%20service%20wizard%20in%20Eclipse

HTTP service wizard in Eclipse

Give your service a new and description. The name of the Handler Class with be derived from the name of your service, but can also be changed to your liking.

Name%20your%20HTTP%20service

Name your HTTP service

And create your service with clicking Next or Finish.

You can then access your handler class by clicking on it’s name, or searching it with CTRL+SHIFT+A.

Open%20your%20handler%20class

Open your Handler Class

The handler class will contain a single method “handle_request” inherited from the interface “if_http_service_extension”.

The method will be empty, but I have added some code to create an example.

CLASS zcl_abap_in_the_cloud IMPLEMENTATION. METHOD if_http_service_extension~handle_request. DATA(lv_parameter) = request->get_form_field( i_name = 'expression' ). DATA(lv_response) = |We have sent ABAP into the cloud for real!|. IF lv_parameter IS NOT INITIAL. lv_response = lv_response && | And it is { lv_parameter }!|. ENDIF. response->set_text( lv_response ). ENDMETHOD.
ENDCLASS.

To return a response/text to the browser the method set_text on the response instance can be used. This is a plain string, so it could contain both plain text as in my example, or formatted HTML.

Parameters can be read using the method “get_form_field” in the request instance. A single parameter can be read, but there are also a method to read all parameters.

To access the HTTP service from a browser, you just need to click on the URL:

Open%20URL%20in%20browser

Open URL in browser

In the browser, you could also add additional parameters: /sap/bc/http/sap/z_abap_in_the_cloud/?sap-client=100&expression=great

ABAP%20running%20in%20the%20cloud

ABAP running in the cloud

Where to go from here

Now from the HTTP service we could call more of our own Z-classes and methods, store data in Z-tables and retrieve them, but also connect to an on-premise system using RFC-calls. Or access the cloud system with whitelisted classes and functions.

Summary

I hope that you have enjoyed this short blog. I had fun getting this to work, and I’m happy that we can now take ABAP to the cloud for real.