One important aspect and target of a good Customer Relationship Management system is to manage acurate customer address and contact information. SAP integrates a framework in SAP CRM to gather and store geolocation information about a customer’s location, i. e. the latitude and longitude of an address. This is especially critical in scenarios where the exact customer location is required (i. e. for weather information services).
You as a customer can enhance the framework and hook your own geocoding service into it. By standard the geocoding service in SAP CRM determines the geocoordinates based on country and region when an address is saved. Of course for most of the use cases, this is much too unprecise.
In this blog I describe how to use Google Maps as geocoding service in SAP CRM.
The Geocoding API in Google Maps is an HTTP based API where you can pass in an address and get geographical coordinates in return:
Check out the API documentation for more details.
To integrate the Google Maps API in SAP CRM, start by creating a Geocoder class. That is a generic ABAP class implementing interface IF_GEOCODING_TOOL. Activate the class only now, it will be implemented later.
This class must be registered in customizing (SPRO: SAP NetWeaver -> General settings -> Set Geocoding) as geocoder source.
Next step is to assign the relevant address field to the new geocoder source.
As the quality of geocoding solutions might vary between countries, you can define a geocoder per country. Here I defined the Google API for German addresses only.
Now let’s implement the geocoder class and method GEOCODE of interface IF_GEOCODING_TOOL. It is called everytime an address is updated in CRM.
The methods gets a table with addresses and some other information. It should geocode each of the addresses and put the results (latitude and longitude) in the CONTAINERS parameter.
The custom submethod GEOCODE_ADDRESS invokes another custom class that calls the Google Maps Geocoding API.
The Geocoding API is an HTTP-based web service API where this class sends GET requests to and consums the result.
The request URL is created by simply concatenating the base URL and the current address. Please note that a response in XML is requested.
SAP offers an XML library called iXML to read and parse XML content (see SAP help here). I haven’t found a similar version for JSON with the same capabilities.
Now if you’re create an account and maintain a German address, our Google Maps geocoder is called and the Geocoding API is asked for the coordinates.
The geograhical coordinates are stored in table GEOLOC.
Please share your comments and thoughts. I would really appreciate your feedback.