One of the most powerful cloud tools in the integrating technology from multiple suppliers together interconnecting the software in your company is SAP Business Technology Platform (SAP BTP). It is extremely flexible when connections are occurring, it can run live, running whenever data is required, it can be triggered daily or actively, gather and send data over in batches. It is also very flexible and can be very intelligent and actively implement decisions made by management about workflows. Because the connecting logic is compiled into binaries SAP BTP connectivity is extremely fast. Those compiled binaries can include code that was custom developed for making decisions about the data that is flowing through its connections and is getting translated from one software system to the next.
This post is aimed at people that want to know how the powerful basic set of building blocks in SAP Business Technology Platform can be extended to be capable of intelligent business decisions using Groovy in the script block, and for development consultants wanting to learn the basics of Groovy development in SAP BTP.
Before we begin it must be stressed that in most situations consultants can implement integrations and connect software systems without any written code, so-called SAP low-code no-code solutions.
What is Groovy
Groovy is a programming language that extends the Java programming language in the spirit of the Ruby programming language.
SAP BTP is running on Java Runtime Environment with the same type of binaries you would get from compiling Java code. Groovy is an extension to Java which is installed on SAP BTP clouds but can also be installed locally for developers to work with. It supports most Java development IDE’s. For example eclipse
Groovy is a language that makes it more natural to think of sets, collections, groups of structured data, and how they flow as a stream. Groovy has extra syntactic features that allow the programmer to find data more easily and regroup the data structures for the receiving systems.
Some first steps
Below here some example code
As you can see it looks a lot like Java but some unusual things like def, which works like duck typing variables, although you can also explicitly type the variables. For example the body is fetch as a String in this code example.
Data structure manipulation
One feature that is really nice is if there is an array of objects that all have a field named “price” that you would normally address like follows:
item.price = “3.45”
then it is easy to get an array of just the prices by addressing the array without the square brackets. Groovy will automatically fold the resulting values into an array that you can easily loop through.
In groovy every array object has a function called “sum” that adds the elements of the array together.
In the philosophy of streaming data, you can stream the data into the sum in a single line. The dots connect the dataflow.
These were just some first steps, A lot more can be learned about Groovy online from the official Apache Groovy website or more SAP specific from the SAP SCN and SAP blogs.