Product Lifecycle Management Blogs by SAP
Dive into product lifecycle management news, learn about digitalizing PLM for the digital supply chain, and stay informed with product updates from SAP.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182779
Active Contributor
0 Kudos

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.


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

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.

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…


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 :wink:

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

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 :grin: