martes, 30 de octubre de 2012

Happy SAP HANA Friends

This is a presentation that I did on the Community Theatre at SAP TechEd Las Vegas 2012.


In this presentation, Blagbert helps his friends Nerdbert to set up his first SAP HANA project using different technologies like:

Python to feed up SAP HANA with some random data.
R to consolidate the data
PowerBuilder to consume the data and present it on a graphical style.

If you didn't attend TechEd in Las Vegas, here's your chance to see my presentation.
If you attend TechEd in Las Vegas, but you didn't attend my presentation...well...shame on you! It was a nice presentation -:)

Feel free to comment -;)

Greetings,

Blag.

martes, 23 de octubre de 2012

Build a Mobile App with PowerBuilder (or at least try it...)


Disclaimer: This blog is just a test. An attempt to build something that doesn't represent SAP or Sybase in any way.

While I was on SAP TechEd Las Vegas, someone asked me if he could use PowerBuilder to build Mobile Applications...at that time I sincerely replied him that I didn't had idea, but I was going to work on it as soon as I had some time. This blog is a product of that...

I first start doing some research on the web, and I found that Pocket PowerBuilder was used for this purpose, but now it's discontinued. So I kept looking...

Then I found Appeon Mobile for PowerBuilder, but it's a not free product and I didn't really want to make any marketing pitch, so I choose to do something else...

PowerBuilder now provides .NET Web Forms Applications which basically turns our application on a ASP.NET webpage, that could be rendered on a mobile device, so that's the approach I chose for this blog.

Before we start, let's make clear that I'm not a Web Developer nor a PowerBuilder developer so my experience in both is kinda limited.

When I first start doing my testing, I really had a lot of troubles and headaches, so here's what I did so you don't need to suffer the same way I did...


If is not already activated, we need to activate some services, so let's go to Control Panel --> All Control Panel Items --> Programs and Features and then Turn Windows features on or off.


From the Application Development Features choose .NET Extensibility, ASP, ASP.NET, ISAPI Extensions and ISAPI Filters.

Then go to Run --> inetmgr and do the following.



Double click on ISAP and CGI Restrictions and allow everything.

Now, we're ready to move to PowerBuilder. For this, we will need a connection to an SAP HANA system. If you don't know how to do this, please refer to my blog PowerBuilder - The new kid on Developer Center's block.

Create a new application and choose .NET Web Forms Application. The application is going to be called web_pb_hana.



Choose Grid and then SQL Select.



On the screen, simply choose CARRID and then Design --> Disctinct.


Call this one dg_carrid.

Next, create a another one but this time choose External and call the parameter Carrid.


On the screen we need to tell that the DataWindows is going to be dg_carrid (so it knows from where to fetch the data) and also specify carrid as both Display and Data Columns. One important thing is to check the options Always Show Arrow, Vertical Scroll Bar and AutoRetrieve.



Call this one ff_params.

Next, create one last DataWindow, Grid again and SQL Select again.

Select MANDT, CARRID, CONNID, COUNTRYFR and COUNTRYTO.

Choose Design --> Retrieval Arguments (This is very important as it will allows us to pass the values of the Drop Down control to our report). Name it Carrid.



In the Where tab fill in the parameter and the argument. Call this one dg_report.

Now, we can go and create a Window.


On the Layout we might to simply drag and drop the dd_report and the ff_params.


Call this dg_window. The button will be called btnreport.

Now that we're ready with our Layout, we need to go back to our Database Painter and copy the Preview generated by the SAP HANA connection.



Double click on the application icon and copy the following code (the first part is done by pasting the Preview the copied before).


Now, double click on dg_window and then double click on btnreport.


Go back to the dg_window layout and right click to choose Script.


We now can run it and it will of course open a browser.



Next job, is to open it on an emulator, so let's grab the Android Emulator and instead of passing the localhost address, use 10.0.2.2/web_bp_hana.


For some reason...it will ask as to open a new window.



Actually...this doesn't work...when you choose the Carrid and press the Show Report button, you will see some loading, but then nothing...I guess it has to do with the rendering as we're passing an ASP.NET page.


Anyway...I tried with the BlackBerry emulator and it was even worse...it didn't even wanted to connect to the main page...so...I think to myself...ASP.NET? Windows Phone should work fine...

For the Windows Phone, you can keep passing localhost, which is a good thing.



As you can see...it really looks small...but at least it works...



As I already said...I'm not a Web Developer...so I don't know if this can be fixed on the generated ASP.NET page or not...so I simply went back to PowerBuilder and make everything bigger...Font 24 was my key....


So...at least it looks a little bit more descent...

Anyway...here you have an application build on PowerBuilder that run on a Windows Phone and read data from SAP HANA -;)

Greetings,

Blag.

domingo, 7 de octubre de 2012

Keeping track of my calories the R way

So...I'm back with Your Shape: Fitness Evolved 2012 for XBox Kinect. Why? Because I want to loose some weight and get back in shape of course -;)

The reason I stop playing the game is simple...I'm lazy...but this time, I have come back with a goal...burn calories!

While I'm using the Your Shape IPhone Application which is really good...I wanted to do something with R and more precisely with Rook...

What I wanted, was a way to keep track of the days and calories burned and generate a nice graphic, but allowing me to choose a range of dates...

This is the code I came up with yesterday night...

Blag_Fitness.R
require("Rook")
library("lubridate")
setwd("C:/Blag/R_Scripts")

Blag_Fitness = read.csv(file="Blag_Fitness.csv",header=TRUE)
Blag_Fitness$Date<-strptime(Blag_Fitness$Date,"%d/%m/%Y")
Rows<-nrow(Blag_Fitness)
Rows
Default_Day<-day(Blag_Fitness$Date[1])
Default_Month<-month(Blag_Fitness$Date[1])
Default_Last_Day<-day(Blag_Fitness$Date[Rows])
Default_Last_Day
Default_Last_Month<-month(Blag_Fitness$Date[Rows])

fill_zeros<-function(param,mode=0){
    count<-nchar(param)
    zeros<-rep(0,1)
    if(mode==0){
      if(count==1){
        r_param<-c(zeros,param)
      }else{
        r_param<-c(param)
      }
    }else{
      if(count==7){
        r_param<-c(zeros,param)
      }else{
        r_param<-c(param)
      }      
    }
    r_param<-paste(r_param,collapse="")
    return(r_param)      
}

newapp<-function(env){
  req<-Rook::Request$new(env)
  res<-Rook::Response$new()
  
  res$write('<form method="POST">\n')
  res$write('<div align="center"><table><tr>') 
  res$write('<td><select name=DAYFROM>')
  for(i in 1:31) {
    if(i==Default_Day){
      res$write(sprintf('<OPTION VALUE=%s SELECTED=%s>%s</OPTION>',
                        i,Default_Day,i))
    }else{
      res$write(sprintf('<OPTION VALUE=%s>%s</OPTION>',i,i))
    }
  }
  res$write('</select></td><td>')
  res$write('<select name=MONTHFROM>')
  for(i in 1:12) {
    if(i==Default_Month){
      res$write(sprintf('<OPTION VALUE=%s SELECTED=%s>%s</OPTION>',
                        i,Default_Month,i))
    }else{
      res$write(sprintf('<OPTION VALUE=%s>%s</OPTION>',i,i))
    }
  }
  res$write('</select></td>')
  res$write('</select></td><td>')
  res$write('<select name=YEARFROM>')
  for(i in 2012:2020) {
    res$write(sprintf('<OPTION VALUE=%s>%s</OPTION>',i,i))
  }
  
  res$write('</select></td>')
  res$write('<td>To</td>')

  res$write('<td><select name=DAYTO>')
  for(i in 1:31) {
    if(i==Default_Last_Day){
      res$write(sprintf('<OPTION VALUE=%s SELECTED=%s>%s</OPTION>',
                        i,Default_Last_Day,i))
    }else{
      res$write(sprintf('<OPTION VALUE=%s>%s</OPTION>',i,i))
    }
  }
  res$write('</select></td><td>')
  res$write('<select name=MONTHTO>')
  for(i in 1:12) {
    if(i==Default_Last_Month){
      res$write(sprintf('<OPTION VALUE=%s SELECTED=%s>%s</OPTION>',
                        i,Default_Last_Month,i))
    }else{
      res$write(sprintf('<OPTION VALUE=%s>%s</OPTION>',i,i))
    }
  }
  res$write('</select></td>')
  res$write('</select></td><td>')
  res$write('<select name=YEARTO>')
  for(i in 2012:2020) {
    res$write(sprintf('<OPTION VALUE=%s>%s</OPTION>',i,i))
  }
  res$write('</select></td>')  
  
  res$write('<td><input type="submit" value="Get Stats"></td>')
  res$write('</tr></table></div>')
  res$write('</form>')
  
  if (!is.null(req$POST())) {
    p_dayfrom = req$POST()[["DAYFROM"]]
    p_monthfrom = req$POST()[["MONTHFROM"]]
    p_yearfrom = req$POST()[["YEARFROM"]]
    p_dayto = req$POST()[["DAYTO"]]
    p_monthto = req$POST()[["MONTHTO"]]
    p_yearto = req$POST()[["YEARTO"]]
    p_dayfrom<-fill_zeros(p_dayfrom)
    p_monthfrom<-fill_zeros(p_monthfrom)
    date_from<-c(p_dayfrom,'/',p_monthfrom,'/',p_yearfrom)
    date_from<-paste(date_from,collapse="")
    date_from_n<-strptime(date_from,"%d/%m/%Y")
    date_from_n<-as.numeric(format(date_from_n,"%d%m%Y"))
    p_dayto<-fill_zeros(p_dayto)
    p_monthto<-fill_zeros(p_monthto)
    date_to<-c(p_dayto,'/',p_monthto,'/',p_yearto)
    date_to<-paste(date_to,collapse="")
    date_to_n<-strptime(date_to,"%d/%m/%Y")
    date_to_n<-as.numeric(format(date_to_n,"%d%m%Y"))
    
    Blag_Fitness$Date<-as.numeric(format(Blag_Fitness$Date,"%d%m%Y"))
    
    Selected_Data<-subset(Blag_Fitness, Date >= date_from_n & Date <= date_to_n)
    Selected_Data$Date<-as.character(Selected_Data$Date)
    fixer<-fill_zeros
    Selected_Data$Date<-sapply(Selected_Data$Date,fixer,mode=1)
    Selected_Data$Date<-strptime(Selected_Data$Date,"%d%m%Y")

    res$write(sprintf('<div align="center"><h3>From %s to %s</h3></div>',
                      date_from,date_to))
    
    png("Blag_Fitness.png",width=800,height=500)
    plot(Selected_Data,type="n")
    lines(Selected_Data,col="blue",ann=FALSE)
    points(Selected_Data, pch=21, bg="lightcyan", cex=1.25)
    dev.off()
    res$write("<div align='center'>")
    res$write(paste("<img src='", server$full_url("pic"), "/", 
                    "Blag_Fitness.png'", "/>", sep = ""))
    
    res$write("</div>")    
  }else{
    res$write("<p>No data to select...</p>")
  }
  res$finish()
}

server = Rhttpd$new()
server$add(app = newapp, name = "Blag_Fitness")
server$add(app = File$new("C:/Blag/R_Scripts"), name = "pic")
server$start()
server$browse("Blag_Fitness")

When we executed, the application is going to read the first and the last line of our .CSV file and set the default values for the comboboxes...making it easy to select the date range...

Here comes the screenshot -;)


So...you can see that I'm making big progress...I started 3 days ago and burning more calories each day...

Greetings,

Blag.