Monday, June 7, 2010

SAP: How to get a Google Static Map onto a Standard SAP screen

A short and simple guide to get a Google Static Map image onto a standard Windows SAPGUI screen.





Normal GuiXT will not allow image files to be viewed via HTTP. The basic Guixt is free with standard Windows SAPGUI. Paying Synactive some cash will allow all the good things found here

*1 As its a static map the location of the customer is based on post code only
*2 As its a Google API, then you should read the terms of use, to ensure you comply

What you need is
1) Windows SAPGUI
2) GuiXT activated and knowledge of the default script directory. (normal example GuiXT directory is C:/GuiXT/, and these examples will use this directory)
3) Follow this link to get cURL


Step ONE
Setup the Windows directories.
create
C:/GuiXT/img
C:/GuiXT/curlbin


Step TWO
Extract cURL into C:/GuiXT/curlbin

Step THREE
Create GuiXT script named "SAPLBUS_LOCATOR.e3000.txt" in C:/GuiXT/ for transaction BP (business partner)

The contents of SAPLBUS_LOCATOR.e3000.txt


if Q[Page=Address]

Pushbutton (toolbar) "Refresh Google Map Image" image (14,95) "c:\GuiXT\img\&F[ADDR2_DATA-POST_CODE1].jpg" "-NoBuffer" "-Transparent" "-Plain"


image (14,95) "c:\GuiXT\img\&F[ADDR2_DATA-POST_CODE1].jpg" "-NoBuffer" "-Transparent" "-Plain" exe="C:\GuiXT\startstatic.bat &F[ADDR2_DATA-POST_CODE1] ""&F[T005T-LANDX]"""

endif


*Note the image (14,95) is ONE line and requires all those quotes. This script passes the post code and country to a BAT file.

Step FOUR
Create BAT file C:\GuiXT\startstatic.bat

The contents of C:\GuiXT\startstatic.bat

@ECHO OFF

cd c:\guixt

IF EXIST c:\guixt\img\%1.jpg GOTO EXfile

set LAND=%2
set LAND=%LAND: =+%

start /min c:\GuiXT\staticnew.bat %1 %LAND%

:EXfile

exit


This script checks if the post code exists and simple exits if it does. If the image does not exist then it does a simple string replace, in replacing " " (space) for a plus. This is for URL encoding in the next script. The script is split so the START command can be used to minimise the next cURL script.

Step FIVE
Create BAT file c:\GuiXT\staticnew.bat

The contents of c:\GuiXT\staticnew.bat

c:\guixt\curlbin\curl http://maps.google.com/maps/api/staticmap? -d "center=%1,%2" -d size=200x200 -d zoom=12 -d format=jpg -d sensor=false -d "markers=color:blue|label:H|%1,%2" -G >c:\GuiXT\img\%1.jpg


exit



This script uses cURL to download the static map image in jpg format. The curl command is one line. It uses the post code and country to geo code the location via the google api.

The END Result





Final Note
As its google its not free, but cURL can be used to download static images of which I will attempt to cover with later blogs.
*The post code is used to save the downloaded image. If the countries used share the same postcode format then the country name is needed in the filename to make it unique.

1 comment:

john bo said...

Thank you ..I used your programs to pull bing image to SAP screen.

Post a Comment

Google +