Skip to Content
Author's profile photo Alvaro Tejada Galindo

Julia, data analysis’s little sister…meets SAP HANA

/wp-content/uploads/2015/10/d_shop_blog_logo_813553.jpg

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


Julia is not that young right now…as it first appeared on 2012 🙂 It is a high-level dynamic programming language designed to address the requirements of high-performance numerical and scientific computing while also being effective for general purpose programming.

Julia_Logo.png

Woaw! That was a big description…so why should we care? Well…maybe because Julia was designed to be the language to rule them all…a language that can be used in any given situation…and without stopping to say if that’s true or not…I must say…Julia is really cool 🙂


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 Julia part…

Go into your Julia environment and install the following packages

  • HTTPClient
  • Codecs
  • LightXML

You only need to do Pkg.add(“PackageName”) for each of them.


Then create a file called Julia_HANA_XML.jl on your favorite editor and copy the following code


Julia_HANA_XML.jl

using HTTPClient.HTTPC

using Codecs

using LightXML

credentials=encode(Base64,”SYSTEM:YourPassword”)

Auth = bytestring(credentials)

Auth = “Basic ” * Auth

flights=HTTPC.get(“http://yourserver:8000/Flights/flights.xsodata/FLIGHTS“,RequestOptions(headers=[(“Authorization”,Auth)]))

raw_text = takebuf_string(flights.body)

xdoc = parse_string(raw_text)

xroot = root(xdoc)

entry = get_elements_by_tagname(xroot,”entry”)

for flights in entry

  print(content(find_element(find_element(find_element(flights,”content”),”properties”),”CARRNAME”)),”: “,

   content(find_element(find_element(find_element(flights,”content”),”properties”),”PRICE”)),”\n”)

end


To run this application, simply go to your Julia environment and type


Include(“Julia_HANA_XML.jl”)

Julia_HANA.jpg

If you are wondering…why didn’t I use JSON instead of XML? Well…there’s an easy explanation for that 🙂 Somehow…the HTTPClient package have a problem using ?$format=json so I was forced to use XML instead…

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Stefan Schnell
      Stefan Schnell

      Hello Avaro,

      thanks for your interesting blog post. From my side here a post how to use Julia with SAP NetWeaver RFC Library.

      Cheers

      Stefan

      Author's profile photo Alvaro Tejada Galindo
      Alvaro Tejada Galindo
      Blog Post Author

      Hello Stefan! Thanks for the blog! I totally love it and just bookmarked 😉 Keep them coming! 😀

      Greetings,

      Blag.

      Development Culture.