Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
Showing results for 
Search instead for 
Did you mean: 
Active Contributor
Ever heard of SAP Leonardo? If not, you can learn more in this openSAP course. The course includes a unit about machine learning (ML). The term is currently used widely by researchers, companies and the press. For a better understanding here is the definition from Wikipedia:

"Machine learning (ML) is the scientific study of algorithms and statistical models that computer systems use to perform a specific task without using explicit instructions, relying on patterns and inference instead. It is seen as a subset of artificial intelligence. Machine learning algorithms build a mathematical model based on sample data, known as "training data", in order to make predictions or decisions without being explicitly programmed to perform the task."

As a developer, it is not easy to believe that a system can do something right without precise instructions. But it works. For example, a computer can learn to play the Atari VCS (2600) classic game Pitfall. Everyone who has played Pitfall knows the challenges of the game. See this blog for details.

Of course, in addition to solving computer games, there are other use cases of machine learning. These include, for example, the translation of text, the recognition of text in images or the recognition of faces. Such use cases make a lot of sense in business. Just think about unlocking your smartphone with your face. This is a complex task for a small device like a Smartphone.

Where is the connection to SAP Leonardo? Well, with the Functional Services of the SAP Leonardo Machine Learning Foundation, there are such possibilities as translating and recognizing text based on machine learning. That can also be done easily, quickly and for free. Without having to install a special software. As an ABAP developer you can even use these services quite comfortably ...

Access and overview

The services overview page is here. To get an overview, no login is required. If you would like to test the services online in a sandbox, you must log in. For me, my credentials from the SAP Community Network were sufficient.

At the moment 27 APIs are listed. Among them are services like

  • Inference Service for Customizable Image Classification

  • Inference Service for Human Detection

  • Inference Service Google Speech-To-Text

  • Inference Service for Face Detection

For each service there is a description, so that you can first inform yourself what the task of the service is.

Example with OCR

Of course, a developer is interested in what possibilities the services offer. As an example, I chose the "Inference Service for Optical Character Recognition (OCR)". The description is "returns extracted characters of any given file". The page looks like this.

If you click on the text "Try out" next to the button "Post", the parameters open. Basically, of course, a file with image information must be specified in which text should be recognized. Here is my example. I used a png file I made from a Word document.

Then there are information about options. The "pageSegMode" and "modelType" parameters seem important, but I was unable to classify the intended values. It probably needs more experience and expertise 😉

Anyway, you can specify your own settings in the input field at the end of the options.

For my first test, I used the following JSON string:
{"lang": "en,de", "outputType": "txt", "pageSegMode": "1", "modelType": "lstmPrecise"}

Click on the "Execute" button and see what happens. Here is the answer from the service.
"id": "[..]",
"predictions": [
"Text 1: | <heart> ABAP\nText 2: | <heart> ABAP\n\n \n\nText 3: | <heart> ABAP\n\nrn\nText 7: I <heart> ABAP\nText 8: | <heart> ABAP\n\nText 9: | <heart> ABAP\nText 10: | <heart> ABAP\n\f"
"processedTime": "[..]",
"status": "DONE"

As you can see, the texts with the number 4, 5 and 6 were not recognized. There is also a problem with the letter "I".

For another test, I changed the options as follows (pay attention to the modelType value).
{"lang": "en,de", "outputType": "txt", "pageSegMode": "1", "modelType": "all"}

Here is the answer from the service.
"id": "[..]",
"predictions": [
"Text 1: | <heart> ABAP\nText 2: | <heart> ABAP\n\n \n\nText 3: | <heart> ABAP\n\n'ext 4: | <heart> ABAP|\nText 7: I <heart> ABAP\nText 8: | <heart> ABAP\n\nText 9: | <heart> ABAP\nText 10: | <heart> ABAP\n\f"
"processedTime": "[..]",
"status": "DONE"

Ok, parts of text 4 are now recognized. I also tested with different font sizes. That had a big impact on the recognition of the characters.

Now one could be disappointed by the result. But for me, the result and the performance were already impressive. In addition, one can argue that OCR has been possible for years. Products like ABBYY FineReader have been around for quite some time. It should not be forgotten that this is just one of many services. The quality of recognition can certainly be increased with enough experience and practice. And, as I will explain in the next chapter, the services can also be used from ABAP.

Integration in ABAP

There is a possibility to generate a code snippet to use a service in ABAP. Just click on the text "Code Snippet" and select ABAP as the programming language. The class CL_HTTP_CLIENT is used for integration.

In 2018, there was also a blog by ajay.rawat on how to use a service in ABAP. This time, the class CL_REST_HTTP_CLIENT was used for integration. His solution looks "cleaner" at first glance than the "Code Snippet".

Due to lack of time, I couldn't try them in own programming examples.

Legal situation

After my little test I was quite euphoric. With the services you can implement many interesting ideas in ABAP. However, there is a legal notice. According to the notice, the data processed by the services can be used by SAP AG, for example to improve their own algorithms of the services. In my opinion this makes it really hard to implement a business case with critical/customer data. But there is certainly a solution for that. For first tests as ABAP developer, it's still a great offer.

Some thoughts at the end

I think the services will get better and better in the future. At some point, as ABAP developers, we might access these services as naturally as we do today with classes/methods and function modules. Maybe comparable to calling a BAPI in another system? Let's see what the future brings 🙂


Best regards and thanks for reading


Labels in this area