Skip to Content

One of the challenges I have faced recently for one of our customers is implementing a piece of code within some Web Dynpro ABAP that would work with their installed geo-coding solution which would, based on a user’s home location and office location, give an accurate driving distance between the two addresses. Now this doesn’t sound too difficult and in fact, like everything else, it is not (once you know how!).

 

SAP already has in place, a set of function modules with which you can get the distance between two geo-coordinates as the crow flies, which is fine as long as you are not relying on the output to give an accurate representation of how long it will take you to get from A to B. However in most cases more is required. So how do we achieve geo-routing?

 

Firstly, without going into too much detail, make sure that you have installed and configured your geo-coder. Next we will need to know the RFC destination. This can be found easily by going to the transaction SPRO.

image

 

A geocoding program is first registered in the system and then assigned to a country. Assuming this has been done, we only need to know at this stage which geo-coder we are going to use and what the name of the RFC destination for that geo-coder is. This can be found here using the nodes shown above. In this example our geo-coder is IGS1 and our RFC destination is IGS_RFC_DEST1. We can see this in the “Register Geocoding Program in the System” node.

 

image

 

For the purposes of this blog we are going to assume that the country GB has been configured to use the geo-coder IGS1. Now that we have the location of our geo-coder we can now start to code our solution.

 

Firstly we need to turn our two addresses into longitude and latitude. This is done using the function ‘FITP_WEB_GEOCODING_GET_SINGLE’ which accepts a structure of the type FTPS_WEB_ADDRESS containing the following attributes:

 

image

 

This will then return a structure of the type FTPS_WEB_GEOCODING which is simply the longitude and latitude of the address you provided.

 

Once you have completed this for both addresses you are ready to compute the distance. You will first need to declare an object of type ref to class CL_GIS_ROUTE_IGS which can be used for this task. When you create this object you will need to give it a name and you will need to set the RFC destination to the one we identified earlier. This is shown below:

 

  DATA: LO_GEOROUTE TYPE REF TO CL_GIS_ROUTE_IGS.
CREATE OBJECT LO_GEOROUTE
  EXPORTING
    name = ‘IGS1’.
LO_GEOROUTE->M_RFC_DESTINATION = ‘IGS_RFC_DEST1’.

 

Now we need to add the address structures to the route as stops. This is done by using the ADD_STOP method which requires a structure of the type GEOPOSITION containing the Longitude and Latitude of the address and a unique ID of type C to uniquely identify the location. See example below:

 

CALL METHOD LO_GEOROUTE->IF_GIS_ROUTE~ADD_STOP
  EXPORTING
    ID = ‘Office’
    POSITION = ls_addr1.

 

Repeat this step for both addresses. Following this we need to execute the geo-routing for this segment.

 

CALL METHOD LO_GEOROUTE->IF_GIS_ROUTE~EXECUTE.

 

Finally we can retrieve the distance computed by the geo-coder. We are only dealing with two addresses so we are going to be retrieving the distance for part 0 of the journey (A to B).

 

CALL METHOD LO_GEOROUTE->IF_GIS_ROUTE~GET_PART_INFO
EXPORTING
PART = ‘0’
IMPORTING
DISTANCE = lv_distance .

 

The distance returned here is of the type GEODIST. This solution will need to be fleshed out with error checking and any other requirements but assuming that your addresses exist and your system is configured correctly, you will now have a fully functioning, distance calculating geo-router.

To report this post you need to login first.

4 Comments

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

  1. Gregor Wolf

    Hi Brenton,

    inspired by your Blog I’ve extended the ZGEOCODE Project to support distance calculation. I’ve created a new class ZCL_GIS_ROUTE_YOURS which implements the interface IF_GIS_ROUTE. The class provides a free distance calculation using the OpenStreetMap YOURS API. Please check out the Projects SVN repository for the new class and the demo report ZTEST_GIS_ROUTE_YOURS. So now distance calculation is possible without investing into a commercial solution.

    Best regards
    Gregor

    (0) 
    1. Nilesh Kumar

      Hi Gregor,

      I am getting error “Access to this place or content is restricted. If you think this is a mistake, please contact your administrator or the person who directed you here.”

      when I access the ZGEOCODE project. Can you please help me.

      Thanks,

      Nilesh.

      (0) 
  2. P. Javadian

    Hi Brenton,

    I have created a test program, but during running, I got a short-dump.

    A RAISE statement in program “CL_GIS_ROUTE_IGS==============CP” has raised

    exception condition “INTERNAL_ERROR”.

    Could you please give a advice how solve this issue?

    Thanks and regards,

    P.

    (0) 

Leave a Reply