martes, 25 de septiembre de 2012

PowerBuilder and Gateway - The Sinatra style

The other day I was playing with the idea of consuming Gateway from PowerBuilder...so of course, I tried a few things like reading it as a WebService or a Rest Service...none work as Gateway generated OData.


A couple of days ago I read this awesome blog by Mark Bradley called Gateway over PowerBuilder where he was using an OData Service DataWindow...which I didn't found on my PowerBuilder IDE...I contact Mark and he told me he was using a "not released yet" version of PowerBuilder, so my new goal was to find a new way to connect PowerBuilder and Gateway using what I currently had...

I tried a lot of things more...including the WCF Data Services for OData which didn't work at all...

But as part of my job is break my head trying to achieve the most crazy and cool ways of doing things...I decided to took another approach...

I remembered that ruby_odata is capable of consuming Gateway, as I was one of the one that contributed to that project Ruby, Camping and...Gateway? (Sorry...will fix the code as soon as I can...old post)

Then I learned that Sinatra the classy Ruby WebFramework was capable of exposing data as a Rest Service (You need to install also the JSON gem)...so all pieces we falling together...

I wrote a small Ruby/Sinatra script to read from Gateway (For this example, I made the service anonymous...just to type it too often)...BTW...I call it Sinatra_JSON.rb


After launching it, I could check it on my browser...


With that ready...I could move to PowerBuilder...create a Solution --> Target (Specify that you want a window to start) --> And then a RESTFUL Client.





After that, we need to Generate the Proxy...


And create a Grid DataWindow...


We need to define the columns that we're going to retrieve and show in our window.


We create a DataWindow inside our Window (w_window) and a button. We're going to drag & drop the Grid DataWindow into our DataWindow.


Double click the button and paste the following code...


Go to the application and double click on it, paste this code...


We're ready to run our program, and press the "Call Flights" button...


It works! So as a little wrap up...we read the Gateway service using Ruby_OData and expose it as REST service using Sinatra. From PowerBuilder we create a REST client, consume the Sinatra REST service and render it on a Grid DataWindow...

Hope you like it...so far...I guess is the best way to make PowerBuilder and Gateway work until we can put our hands on the latest PowerBuilder release.
The only drawback of course, is that I need to pass the filters manually instead of passing them dynamically...well...next time maybe...

Greetings,

Blag.

miércoles, 12 de septiembre de 2012

And along came .NET

Disclaimer: This blog is based on my own personal experiences and it's not endorsed or supported by SAP. ODBC connection to SAP HANA is neither endorsed or supported by SAP, so it must be used under your own risk, no support will be provided.

This last weeks I have been blogging a lot about integration of 3rd party tools with SAP HANA. Like Python, R, PowerBuilder and Euphoria. So, the next natural step for me was make the same using .NET

This might sound repetitive, but it's been a long time since I used .NET, actually I have never use it too much, just for some small personal projects but nothing really big.

First I did was to download the Visual Studio 2012 Express for the web, meaning that I will present some ASP.NET code (VB.NET style).

We must create a new project and call it "HANA_NET"


And then create two Web Form's...call them WebForm1.aspx and WebForm2.aspx as it's the default.


At first, I thought about using a JDBC connection, but then realized that Microsoft wouldn't provide that, so next choice was ODBC...but...I discover something kind of weird...ODBC is not provided by default...


So...we're going to do everything by code...lovely isn't it?

Second thing I discovered is that the ISS Express Web Server is 32 bits by default, so working with Windows 7 and having 64 bits SAP HANA drivers wasn't really helpful...after some Internet browsing, I found out that ISS Express is provided in both 32 and 64 flavours but you get 32 bits by default and there's no easy way to override it...so...the solution is...launch it from it's source...


With this little trick, we're not going to have any problems at all...

Let's create an ODBC connection for SAP HANA, which must by the way exist on System DNS, otherwise it's not going to work. Again, more 64 bits problems.


Now...we can start coding...go to the Web.config file and double click on it to modify it code...


That would tell ASP.NET that we want to use that DSN.

On the WebForm1.aspx create this layout (Yep...my design skills are under water)...


Right click and select View Code...


Go to the WebForm2.aspx and write this code (No layout here as we need to add some thing by code)


Again, go to the View Code option...


With our IIS Express server up and running, we only need to the execute our webpage



That's all folks...a simple example showing that .NET can speak SAP HANA too...

Greetings,

Blag.