Tuesday 17 March 2015

HR Note Application Gotcha...

Okay, there's a misdirection with OSS note 2122145.

They tell you that you can edit the required WageType entries /357 etc using transaction PU30, which errors if you try...

You can crowbar these entries in using transaction SM30 and table V_512W_T.
It'll give you lots of warnings about namespaces, but enter through those, and you'll eventually be able to save...

Dayumn.

Wednesday 11 March 2015

GeoCoding a Postcode / ZipCode in ABAP

Here's a quick PoC (that's Proof of Concept, folks, not Piece of... never mind...) function module that takes a Postcode and turns it into LatLngs that can be used for dropping pins on your Google Maps mashup, or just used to work out what's nearby and what's not.

I also tested it with everyone's favourite American Zip Code (90210) and it returned Beverly Hills, so I'm guessing whatever your location, Google is clever enough to know where you are.

The HTTP class could be used for all sorts of cool "get something from the internet" applications. Again, I know there are better ways of doing this, but since what I'm bringing back is so simple (Lat field, Lng field...) I'm happy to have the minor overhead of the string operations in this case.



FUNCTION YPD_GOOGLE_GEO .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_PSTLZ) TYPE  PSTLZ DEFAULT 'NE1 5JB'
*"  EXPORTING
*"     REFERENCE(O_LAT) TYPE  CHAR20
*"     REFERENCE(O_LNG) TYPE  CHAR20
*"----------------------------------------------------------------------

"http://maps.googleapis.com/maps/api/geocode/xml?address=

dataurl_stem type string value 'http://maps.googleapis.com/maps/api/geocode/xml?address='.
dataurl type string.
dataclient type REF TO IF_HTTP_CLIENT.
datats_dados_temp type table of string.
datal_dados_temp type string.
DATAp_content TYPE string.
datal_counter type int4.

datal_trash type string.
datal_keep type string.

datal_pstlz type char10.



concatenate url_stem i_pstlz into url.

clear p_content.

CALL METHOD cl_http_client=>create_by_url       "Create a client object with which to play.
EXPORTING                                       "based on the URL.
url url
IMPORTING
client client
EXCEPTIONS
OTHERS 1.


client->request->set_header_fieldname '~request_method' value 'GET' ).    "Set the Request type to GET
client->send).          "Make the call

****Receive the Response Object
CALL METHOD client->receive
EXCEPTIONS
http_communication_failure 1
http_invalid_state 2
http_processing_failed 3
OTHERS 4.



p_content client->response->get_cdata).

SPLIT p_content AT  '<lat>' into l_trash l_keep.

split l_keep at '</lat>' into o_lat l_keep.

SPLIT l_keep AT  '<lng>' into l_trash l_keep.
SPLIT l_keep AT  '</lng>' into o_lng l_trash.


CALL METHOD client->close).  "  prevents 'No Memory for processing HTTP, HTTPS or SMTP queries'


ENDFUNCTION.