Skip to Content

/wp-content/uploads/2015/11/d_shop_blog_logo_831600.jpg

If you are an SAP Employee, please follow us on Jam.


Falcon is an Open Source, multi-paradigm programming language. It supports procedural, object-oriented, prototype-based, functional, tabular and message passing. It first appeared 12 years ago…so not a new and fresh language. It was the default scripting language for the now disappeared Auroraux operating system.


/wp-content/uploads/2015/11/falcon_logo_831593.png

Falcon is pretty awesome and has some features that other programming languages would kill to have 🙂

So…no example or demonstration would be complete if we didn’t hook it up with SAP HANA, right? So…let’s go and do it -;)

First, we need to create a Calculation View and call it “FLIGHTS_BY_CARRIER”. It will be composed of two tables, SCARR and SFLIGHT.

First, we need to create a Join object and link the table by MANDT and CARRID. From here select the following fields as output MANDT, CARRID, CARRNAME, PRICE and CURRENCY.

Then create an Aggregation object selecting the fields CARRNAME, PRICE (As Aggregated Column) and CURRENCY. Filter the CURRENCY field by ‘USD’.

Then create a Projection object and select only PRICE and CARRNAME.


On the Semantics object make sure to select “CROSS CLIENT” as the Default Client.

Calculation_View.jpg

Now, switch to the SAP HANA Development View and create a new repository. Call it “Flights”.

Create a new “XS Engine” project and call it “Flights” as well. Link it to the “Flights” repository.

Create an empty “.xsapp” file.

Create a file called “.xsaccess” with the following code.

.xsaccess

{

“exposed” : true,

“authentication” : [ { “method” : “Basic” } ]

}

Finally create a file called “flights.xsodata” with the following code

flights.xsodata

service {

          “Blag/FLIGHTS_BY_CARRIER.calculationview” as “FLIGHTS” keys generate local “Id”;

}


Activate your project and launch it on your browser, you should see something like this…


XSProject.jpg

The SAP HANA part is done…so we can move into the Falcon part…

Falcon should be bundled already in every Linux based system…and I’m sure you haven’t even noticed it 😉

Anyway…you can grab it from Falcon Releases

Now…as I’m still a Falcon newbie…I’m not sure if we really need this…but just in case…install it…

apt-get install falconpl-curl

It’s the curl binding for Falcon…

Grab your favorite editor and copy and paste the following code…

falcon_hana.fal

import from curl

import from json

h = curl.Handle(“http://YourServer:8000/Flights/flights.xsodata/FLIGHTS?$format=json“)

auth = “Authorization:Basic ” + Base64.encode(“SYSTEM:YourPassword”)

headers = [auth]

h.setOption(curl.OPT.HTTPHEADER,headers)

h.setOption(curl.OPT.SSL_VERIFYPEER,false)

data = h.setOutString().exec().getData()

try

   raw = json.JSONdecode( data )

catch

   printl( “Can’t decode the string” )

end

d = raw[“d”]

results = d[“results”]

for Index in [0:results.len()]

  print(results[Index][“CARRNAME”])

  print(” : “)

  printl(results[Index][“PRICE”])

end

To execute it…simply open a terminal session and go to source code folder and type

Falcon falcon_hana.fal

Falcon_SAPHANA.jpg

I have to admit that this wasn’t easy at first…the Falcon documentation doesn’t talk about curl…so I need to check the source code on GitHub…make a lot of testing…until I finally could get it to work…the json part on the other hand was extremely easy 😀

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply