Monday, March 14, 2011

Japan KML by prefecture

If you require KML by prefecture of Japan,

Thanks to the work done here at the themeatic mapping engine,

to get KML of Japan by prefecture you need google fusion table 420419.

http://www.google.com/fusiontables/DataSource?dsrcid=420419

Then add a filter



Embedded it looks like this.




There is also some earthquake data, here

http://earthquake.usgs.gov/earthquakes/catalogs/

Tuesday, February 15, 2011

SAP: How to get a Google Chart onto a Windows SAP GUI screen

A way to get a google chart onto a windows SAPGUI screen

Google chart api allows you to download charts for offline use. Using GuiXT, cURL and dos commands a chart can be shown on a windows SAPGUI screen.

Example below for SAP transaction db02, showing freespace of the database, plus freespace of the actual disk dedicated to the database. *in this example the unix system is checked for freespace of the */sapdata* filesystems. (Obviously all the white space is my attempt at hiding the real data)





The way to get the charts is with GuiXT and cURL

Again as with previous attempts to get google and yahoo static maps onto SAPGUI screen links here and here, then all the following is setup in a similar way.

All the following is found in c:\guixt check out the other links for more of the same.

To note the code below is cut and pasted into blogger and most of it is on one line and I have left a gap between each  line.

1) The GuiXT control script is called RSORA060.e0110.txt and relates to the DB02 transaction on our systems.


Set  V[db]   “&V[_database]"

Pushbutton (toolbar) "&V[_database] update charts"  "/0"

if V[_database=SID]

image (4,83)  "C:\guixt\img\chart&F[TD110-TSFRP].gif"  -NoBuffer  -Transparent  -Plain  exe="c:\guixt\ch_copy.bat &F[TD110-TSFRP]"  start="c:\guixt\ch_copy.bat &F[TD110-TSFRP]"

image (13,83)  "C:\guixt\img\chart&V[_database].gif"  -NoBuffer -Transparent  -Plain   exe="c:\guixt\chdisk_copy.bat ""&V[_database]"""  start="c:\guixt\chdisk_copy.bat ""&V[_database]"""

endif

*Note in the code above SID needs to be changed to the system to be monitored. Each SID may have different scripts to check and create the charts.
To update the charts then the second chart is configured to use the GuiXT command start this enables the DOS BAT files to run. After the scripts complete then the pushbutton should be used to refresh the charts. The date is used in the chart to enable detection of out of date data :)

2) DOS script c:\guixt\ch_copy.bat generates the DB freespace google "GOM" chart. The dos bat file is below.

@ECHO OFF

@del "C:\guixt\img\chart%1.gif"

cd "C:\guixt"

@del ".\img\chart%1.gif"

.\curlbin\curl -s -xPROXY:PORT  http://chart.apis.google.com/chart? -d chs=225x125 -d cht=gom -d chd=t:%1 -d chl=%1 -d chco=FF0000,00FF00 -d chtt=DB+FreeSpace -d chof=gif    -G > .\img\chart%1.gif

exit

In the script above PUTTY command PLINK is used to connect to the unix system with ssh keys exchanged.

3) The second DOS script c:\guixt\ch_copy.bat generates the google chart for the free space in the unix system's sapdata filesystems


@ECHO OFF

cd "C:\guixt"

del ".\img\chart%1.gif"

rem %% required for batch % ok for command line

for /f %%A in ('plink -l USERID HOST "df -k|grep sapdata |awk '{n=n+$2}{s=s+$4} END{print s*100/n}'"') DO ( SET DISK=%%A )

echo %DISK%

.\curlbin\curl -s -xPROXY:PORT  http://chart.apis.google.com/chart? -d chs=225x125 -d cht=gom -d chd=t:%

DISK% -d chl=%DISK% -d chco=FF0000,00FF00 -d chtt=%DATE%+Disk+FreeSpace -d chof=gif  -G >.\img\chart%1.gif

exit
*Note in both of the DOS BAT files then the PROXY:PORT settings need to be adapted to the correct settings.

Monday, February 14, 2011

MAC: Creating a basic barcode web service with php

A new part time project for me is to  learn and use Apache and PHP.

First project is to generate barcodes from supplied url parameters.


Here is version 0.1, with no error checking or user input validation - maybe in the next version.
My Mac = Imac running snow leopard 10.6.6

Get Barcode Writer in Pure Postscript here.


1) Install Xcode and MacPorts

Links to both can be found here http://www.macports.org/install.php

Then install both ghostscript and imagemagick with macports.

2) Install ghostscript
sudo port install ghostscript

check its installed with the command gs -h

3) Install imagemagick

sudo port install imagemagick

check its installed with the command convert -h

4) Apache activate PHP and start Apache

uncomment out the php5_module line.

cd /etc/apache2
sudo vi httpd.conf

LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule bonjour_module     libexec/apache2/mod_bonjour.so
LoadModule php5_module        libexec/apache2/libphp5.so
#LoadModule fastcgi_module     libexec/apache2/mod_fastcgi.so


Start Apache web server - system preferences - sharing - web sharing



5) php code (really simple :) run a bash script to generate the barcodes from the supplied url parameters.
I called the php c.php

<?php

//phpinfo()

$bc=$_GET["b"];

$bt=$_GET["text"];

//echo $bt;

system("/Users/robert/Sites/barc.bash $bc $bt");

$barcpath="www/barcode.jpg";

//echo $_GET["texto"];

echo "<img src=\"$barcpath\">";

?>



6) BASH script (really simple :) no error checking nor options for the barcodes at the moment so text etc will be checked in the future.
I called the bash script barc.bash

BC=$1

shift

#build postscript code

echo "gsave" >/Users/robert/Sites/www/hello1.ps

echo "50 50 translate" >>/Users/robert/Sites/www/hello1.ps

echo "2 2 scale" >>/Users/robert/Sites/www/hello1.ps



echo "50 50 moveto (${*}) () /${BC} /uk.co.terryburton.bwipp findresource exec" >> /Users/robert/Sites/www/hello1.ps

echo "grestore" >> /Users/robert/Sites/www/hello1.ps

echo "showpage" >> /Users/robert/Sites/www/hello1.ps

#run ghostscript to generate EPS

/opt/local/bin/gs -dBATCH -dNOPAUSE -q -sDEVICE=epswrite -sOutputFile=/Users/robert/Sites/www/$$.eps /Users/robert/Sites/www/barcode.ps /Users/robert/Sites/www/hello1.ps

#imagemagick to convert from EPS to jpg

/opt/local/bin/convert -density 72 /Users/robert/Sites/www/$$.eps /Users/robert/Sites/www/$$.jpg

#copy the file to barcode.jpg

cp /Users/robert/Sites/www/$$.jpg /Users/robert/Sites/www/barcode.jpg



7) Before running create www directory in the users home directory, here the home dir is ~robert

mkdir www
cd www

move/copy barcode.ps to the www directory.

change the owner and group of barcode.ps and www directory
sudo chown _www:_www barcode.ps
himbleton:Sites robert$ ls -ld www
drwxr-xr-x  49 _www  _www  1666 Feb 14 23:26 www

END RESULT


Sunday, February 13, 2011

SAP: generate images for Excel with BSPs

Following on from the post "More Barcodes with Barcode Writer in Pure Postscript"

This post covers a straight forward BSP and a simple Excel Macro to generate barcodes. By straight forward and simple I mean that I dont go into any error checking :) Also as I have covered Yahoo maps previously then its a case of changing the Excel Macro slightly to pick up the Yahoo static map images, however as Yahoo terms of use are involved then its only a demo. The barcodes covered first are free though :).

First the barcode related BSP.

Goto Se80 and create a BSP called ZBWIPP

Create a page bc.htm with the following

Attributes, barcodes, options and text as shown below.


The Event Handler "OnInitialization" code takes the url parameters and generates the barcodes. See the "More Barcodes with Barcode Writer in Pure Postscript" post for the requirements for ghostscript and imagemagick. The external commands line CALL FUNCTION 'SXPG_COMMAND_EXECUTE' uses the same code in the SDN blog for the script ZBWIPP. Also all the scripts and barcode.ps code are in the work directory of my SAP demo 702 server.


navigation->set_parameter( 'text' ).

navigation->set_parameter( 'barcode' ).

navigation->set_parameter( 'options' ).



*DATA bitmap TYPE REF TO zcl_abap_bitmap.

DATA okcode TYPE syucomm.

DATA filed type string.



DATA: t_result         TYPE STANDARD TABLE OF btcxpm.

DATA psX type string.

DATA psY type string.



data scaleX type i.

data scaleY type i.



data bit TYPE  XSTRING.

data display_url type string.

*the scale values could be placed in the excel call also, not done it yet

scaleX = 2.

scaleY = 2.

data  p_name type string.



if text is initial.

  text = 'no text detected'.

endif.



if barcode is initial.

barcode = 'datamatrix'.

endif.



psX = scaleX.

psY = scaleY.



DATA: psnm  TYPE string VALUE 'f:\usr\sap\NSP\DVEBMGS00\work\zsapbarcode.ps'.

DATA: barc  TYPE string VALUE 'f:\usr\sap\NSP\DVEBMGS00\work\rob.bmp'.

DATA: TEXT1(255),

      TEXT2(20),

      LENG TYPE I.



* 0 moveto (2310844"Japan") () /qrcode /uk.co.terryburton.bwipp findresource exec

*howpage

*concatenate '50 50 moveto (' text  ') (' options ') /' barcode ' /uk.co.terryburton.bwipp findresource exec' into TEXT1.

concatenate '50 50 moveto (' text ') (' options ') /' barcode ' /uk.co.terryburton.bwipp findresource exec' into TEXT1.

concatenate psX pSY  ' scale' into TEXT2.



OPEN DATASET psnm  FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

*RANSFER '50 50 moveto' to psnm.

TRANSFER 'gsave' to psnm.

TRANSFER '50 50 translate' to psnm.

TRANSFER TEXT2 to psnm.

TRANSFER TEXT1 TO psnm.

TRANSFER 'grestore' to psnm.

TRANSFER 'showpage' to psnm.

CLOSE DATASET psnm.



CALL FUNCTION 'SXPG_COMMAND_EXECUTE'

  EXPORTING

    commandname                   = 'ZBWIPP'

*   additional_parameters         = v_dir_input

*   operatingsystem               = c_oper

  TABLES

    exec_protocol                 = t_result

  EXCEPTIONS

    no_permission                 = 1

    command_not_found             = 2

    parameters_too_long           = 3

    security_risk                 = 4

    wrong_check_call_interface    = 5

    program_start_error           = 6

    program_termination_error     = 7

    x_error                       = 8

    parameter_expected            = 9

    too_many_parameters           = 10

    illegal_command               = 11

    wrong_asynchronous_parameters = 12

    cant_enq_tbtco_entry          = 13

    jobcount_generation_error     = 14

    OTHERS                        = 15.



OPEN DATASET barc FOR input IN BINARY MODE.



READ DATASET barc INTO bit.

CLOSE DATASET barc.



IF  XSTRLEN( bit ) > 0.



  DATA: cached_response TYPE REF TO if_http_response.

  CREATE OBJECT cached_response TYPE CL_HTTP_RESPONSE EXPORTING add_c_msg = 1.



cached_response->set_data( bit ).

  cached_response->set_header_field( name  = if_http_header_fields=>content_type

                                      value = 'image/bmp' ).



    cached_response->set_status( code = 200 reason = 'OK' ).

    cached_response->server_cache_expire_rel( expires_rel = 180  ).



    DATA: guid TYPE guid_32.

    CALL FUNCTION 'GUID_CREATE' IMPORTING ev_guid_32 = guid.

    CONCATENATE runtime->application_url '/' guid '.bmp' INTO display_url.



    cl_http_server=>server_cache_upload( url      = display_url

                                         response = cached_response ).

***response->redirect( display_url ).

response->redirect( display_url ).



else.

  response->redirect( 'http://himble.test.com:8000/sap/bc/bsp/sap/zbwipp/zbwipperror.bmp' ).
 


endif.

SIMPLE EXCEL MACRO
 
The excel macro is really simple in that it uses the current selection and uses offsets to pick up the required barcode, options and text. So for example the required barcode would be in column A, the options in column B and the text for the barcode would be in column C. The range to select would be in column E, my choice.



Sub zbwipp()

    Dim barcode As String

    Dim text As String

    Dim options As String



For Each Cell In Selection



    Cell.Select

    barcode = Cell.Offset(0, -4).Value

    options = Cell.Offset(0, -3).Value

    text = Cell.Offset(0, -2).Value

'    MsgBox barcode

    ActiveSheet.Pictures.Insert( _

        "http://himble.test.com:8000/sap/bc/bsp/sap/zbwipp/bc.htm?barcode=" + barcode + "&options=" + options + "&text=" + text).Select

Next Cell

End Sub


The result in a YouTube Video 




Yahoo Static Map Images


If the Excel command  ActiveSheet.Pictures.Insert is used to point to the Yahoo BSP in this post then static maps can be generated as shown below. The same location is used in my home town of Birmingham and the width of the image is changed and the static maps generated.


Wednesday, January 26, 2011

SAP: Barcodes for free in a background job with PDFcreator in server mode

Running the 26 barcodes on a page report in an SAP background job.

Created with the Barcode Writer in Pure Postscript

While I was setting up my SAP demo NW702 system and BWIPP, I was notified of a new version of PDFcreator (version 1.2). So I thought I would try PDFcreator in server mode (note I do run the demo SAP server on XP)

A prereq, you will need the device type and abap report found here

Import the device type ZBWIPP (file zbwipp.pri in the zip file) with transaction SPAD
Enter the device type name and SAP will prompt for a transport



Download PDFcreator

1) Choose server installation

2) note the advice in the next screen.

Let the install complete and I activated autosave and kept the default directory and settings.



3) Download the BWIPP in the "seperate file per named resource" in the download section.
 Install this into the lib directory of PDFcreator as shown. Installing in this way will allow the print after save option to work, but more on that later.

4) Setup the output device, I used the direct operating system call.
*Note the device Type must be ZBWIPP

5) create ABAP report ZBWIPP_PRINT (use the text file zbwipp_print.txt from the zip file) and you can ignore the warning message, it works and the new page print on command is required to use the printer controls for the barcodes.

activate the report and the following is only a warning message



6) define the background job in sm36 and point to the new printer, I had set the new printer as my default printer in SAP.

Run the report immediately or schedule and the resulting PDF print out should be in the auto-save directory setup earlier.



7) Print after save.

I am still checking this part out but the mswinpr2 device used by ghostscript is a completely separate and therefore no control over margins, so I scaled the printer to get some results, if you note the 98% scaling option in the screen shot.

I may return to this later........


 

Sunday, January 9, 2011

SAP: Thematic mapping with KML

I have blogged about visualising wikipedia data with Tableau before

Here I will keep the same source data but  process  it with SAP ABAP. The ABAP code will create a KML file for viewing in google earth or arcgis explorer or any other kml compatible program. Hopefully you can make the connection to presenting business data in the same way. e.g. its all in ABAP and therefore you could use the data in SAP, I am not in the position to show even the test data I used to demonstrate this at work.

So I will cover the thematic map with the population of Japan but this time in a choropleth map.  In later blogs I will cover how to produce a choropleth map based on first level admin breakdown of countries, basically later blogs will explain this more! (for now, you can see this 1st level admin in google earth by expanding borders and labels and 1st level admin is shown).

Wikipedia Data

Now to get the wikipedia data we will use sparql as before (in the Tableau blog mentioned at the start) but this time add  iso code related lines.


The ABAP code
I am not an ABAP developer but I have been scripting for long enough to try it out and get this demo working. So its not really about the ABAP code but the idea of presenting data on a map I want to cover.

The - not so - Simple Transformation

This is the key to the choropleth map its based on my kml breakdown of Japan by prefectures in KML ( the 1st level admin borders I mentioned earlier). Now in SAP regions for Japan match the ISO codes for Japan prefectures.

So the simple transformation for Japan is based on changing the colour of the polygon.

The ABAP code works out a range of colours based on the data and then runs the simple transformation changing the colours of the 47 prefectures. As per the snippet of code shown here.


<PolyStyle>

  <color><tt:value ref="cjp34"/></color>

  <outline>1</outline>

</PolyStyle>



The Video,
This is just a demo video at the moment and I will update this later. The video shows data being processed by SAP to generate the polygons and the colour based on a scale. In the video I change Kanagawa and Tokyo prefectures to change the colours of the polygons. This is a first blog in a series and I will cover more in later posts.

**Update 13th March, I have taken down the demo video due to the current situation in Japan.
**Update 19th May, new video with the scalable icons in KML, the polygon video will return later.
**A way to generate your own KML for any country based on the Natural Earth Dataset here


.


Background as to why I ended up doing the above.

What "themematic mapping in SAP with KML", I didnt think I was going to be at this point as I have always been in the SAP Basis side of things and never written an business based report before. During several meetings people were talking about reports based on postcodes, I took this idea of postcodes and started my Google Driven Development and trying to Keep It Simple Stupid at all times. However at the end there was no take up of the idea, we have a complete BI system about to arrive and a commercial mapping service. I am still working on the idea though as it is a great way to show data.

The original ideas for KML presentation came from the Thematic Mapping Engine.

Living in Japan was also the inspiration behind my idea, if you have ever been to Japan then you may know the streets have no names which is weird (or maybe different). So as per QR code adventures into SAP, you can thank Japan for inspiring me to write this blog :) I found myself interested in the whole mapping side of things as a way to try and understand more about Japan, I have not finished my mapping adventure, and there is more blogs to come.

I like this video as it covers the "weird or just different" aspect with Japan street names. (its a TED talk by Mr Sivers, youtube allows me to get the embed code so I am using it).

Wednesday, January 5, 2011

PDFCreator: configure pdfcreator to permanently include Barcode Writer in Pure Postscript

After a trip to Wikipedia and this page http://en.wikipedia.org/wiki/List_of_virtual_printer_software

I have a new favourite pdf virtual printer in PDFCreator. Its free and for commercial purposes and can be downloaded here

I had blogged about 26 barcodes on one page with scripts based around Redmon, Microsoft services for Unix and Ghostscript.

PDFCreator can also add the barcode.ps file required to allow SAP to use the Barcode Writer in Pure Postscript without further scripting and bypass Microsoft services for Unix. (it appears redmon is used by pdfcreator as a default install)

Here is the screenshot of the config required.




In the example above the barcode.ps file is in directory C:\Program Files\PDFCreator\GS9.00\gs9.00\Bin, but can be placed in any directory with the search path set correctly.

The PDFCreator has a few more config options that I like such as the auto save shown below.


CutePDF can do the same thing here which allows the ABAP report to produce the following output.


Google +