lunes, 23 de noviembre de 2015

Lua is a lightweight multi-paradigm programming language designed as a scripting language with extensible semantics as a primary goal. Lua is cross-platform since it is written in ANSI C, and has a relatively simple C API.

If you wonder about the title…well…Lua means Moon in Portuguese -;)

Lua is very powerful but easy to learn and use. If you already know Python or Ruby, you will be just fine…

Before we move on…I want to share a little joke…which is not specific to Lua only…but still funny -;)

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.xodata

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

Before we continue…I will recommend you to install a couple of things…if you’re on Linux…install this…

sudo apt-get install lua5.2

And then follow the instructions to install LuaRocks a package manager for Lua…

lunes, 16 de noviembre de 2015

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

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.xodata

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 -;)

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

martes, 10 de noviembre de 2015

Yep...I'm aware that there must be a lot of more efficient and short ways to do this...but then again...my purpose with this is to have the same base code for all the programming languages that I learn...

Usually I write this code after a couple of days of learning the language...so in no way I can be aware of all the crazy and optimized features...

This code is just for fun and for me...a really good way to introduce the syntax of a language in a very friendly way...

lunes, 9 de noviembre de 2015

Erlang is a general-purpose concurrent, garbage-collected programming language and runtime system. And it’s also Functional, with eager evaluation, single assignment and dynamic typing. Did I forget to mention that it’s also distributed, concurrent and fault-tolerant.

Big description, huh? Well…Erlang has been around for the almost past 30 years…

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.xodata

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

Erlang, as opposed to many other languages, doesn’t have a Package Manager, so we need to only download the package that we want and compile it -;)

To code for Erlang I use one of the most awesome editors I have ever found…Geany. It comes almost pre-configured to handle a lot of programming languages, so you will be ready to code for Erlang.

We need to download mochijson2.erl and save it on our project folder, then we can simply compile it by calling

erlc mochijson2.erl

From the terminal or press the “Compile the current file” button. First one on the image.

With that, we should be more than ready to start coding -:) Copy and paste the following code…

Of course...we're going to use some Regular Expressions as well...but that's already included in Python :)

So, the basic idea is that we need to log into SCN using our Username and Password and then read the first page of our "content" folder only for blog posts...then we can continue reading the following pages by using a parameter that will load the next 20 blogs...

Now...and before you say something -:P This works (at least for me) only for the first 10 pages...because after that the HTML seems to be automatically generated...so there's nothing to get more data from -:( or maybe my blogs come from a long time ago...my first blog ever on SCN was written on February 17, 2006 Tasting the mix of PHP and SAP...

To compile this application we need to create another file…called compile_ada_hana.gpr

compile_ada_hana.gpr

with "aws";
project Compile_Ada_HANA is
for Main use ("ada_hana.adb");
end Compile_Ada_HANA;

And run it like this…

sudo gprbuild compile_ada_hana.gpr

One the executable is done…we can run it like this…

./ada_hana

If you are wondering…why didn’t I use JSON instead of XML? Well…there’s an easy explanation for that -:) The JSON library is nice…but I had some troubles compiling it and there’s not much examples on how to retrieve the data from a complex JSON…so using XML looked like an easier and better choice -;)