Skip to Content

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:

https://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY

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.

Image_01.png

This class must be registered in customizing (SPRO: SAP NetWeaver -> General settings -> Set Geocoding) as geocoder source.

Image_02.png

Next step is to assign the relevant address field to the new geocoder source.

Image_03.png

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.

Image_04.png

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.

Image_05.png

The custom submethod GEOCODE_ADDRESS invokes another custom class that calls the Google Maps Geocoding API.

Image_06.png

The Geocoding API is an HTTP-based web service API where this class sends GET requests to and consums the result.

Image_07.png

The request URL is created by simply concatenating the base URL and the current address. Please note that a response in XML is requested.

Image_08.png

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.

Image_09.png

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.

Image_11.png

The geograhical coordinates are stored in table GEOLOC.

Image_12.png

Please share your comments and thoughts. I would really appreciate your feedback.

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. K Anandh

    Dear Robert,

    Thanks for writing this article.

    Please inform us with your experience about Google Geo-coding API license implications.

    Is it commercially free for Production environment?

    Regards,

    K.Anandh

    (0) 
    1. Robert Witt Post author

      Hi K Anandh,

      In my experience you need a business account in order to use the API commercially. The standard version works for non-commercial and development scenarios. However, in the usage limits I cannot see any restrictions on that, only the number of service requests per day is restricted.

      Please check Google’s Terms of Service.

      Regards,

      Robert

      (0) 

Leave a Reply