Skip to Content
Today I got the request from our sales department to get a list of all Mayors in Germany for a Marketing Campaign. Unfortunately there is no attribute maintained to retrieve this information using the CRM Segment Builder. So I thought where to get this information from and found the Wikipedia (http://www.wikipedia.org/) “[Export pages | http://en.wikipedia.org/wiki/Special:Export]” feature. From my Blog: “[Geocode Business Partner with Google Maps | Geocode Business Partner with Google Maps]” I had already everything in place to use Wikipedia. I had to do just these steps: h3. Preparation h4. Create Database Table for Towns and their Mayors I’ve put all development objects together in the Package ZWIKIPEDIALOAD. Here I’ve created also the DB Table ZCITYMAYORS which will contain City and Mayor. The following picture shows you the table definition: h4. Transform Mediawiki to ABAP Like I did in: “[Geocode Business Partner with Google Maps | Geocode Business Partner with Google Maps]” the XML returned is transferred to an ABAP variable using Simple Transformations (Fifth ABAP Online Meet-up: Simple Transformations). To test the Transformation I first downloaded the result of this request to my local drive: h4. Implement ABAP Program to fill Table ZCITYMAYORS with Cities My list of Cities is available in an Excel file. So I had to find a way to import it to my Database table. In the ABAP Forum I’ve found a link to Upload Excel document into internal table (http://www.sapdevelopment.co.uk/file/file_upexcel.htm). With a few modifications this was a perfect solution.

h3. Implement ABAP Program to fill Table ZCITYMAYORS with Mayors Finally we can now fill the Table ZCITYMAYORS also with Mayors. Together with the Transformation this little piece of ABAP does all the work: REPORT zget_mayors_for_cities. DATA: it_citymayors TYPE TABLE OF zcitymayors, wa_citymayors LIKE LINE OF it_citymayors, mayor TYPE full_name, trash TYPE string.   PARAMETERS: s_city TYPE s_city LOWER CASE.   SELECT * FROM zcitymayors INTO TABLE it_citymayors WHERE city LIKE s_city.   * HTTP Client according to * BSP: Create a weather magnet using xml feed from weather.com   DATA: client TYPE REF TO if_http_client, url TYPE string, xml TYPE xstring, c_xml TYPE string, city TYPE string.   * Converter DATA: l_convin TYPE REF TO cl_abap_conv_in_ce.   LOOP AT it_citymayors INTO wa_citymayors. * Use the Progress Indicator to show the user which City is processed CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR’ EXPORTING percentage = sy-index text = wa_citymayors-city.   city = wa_citymayors-city. * Spaces have to be replaced by _ in the URL REPLACE FIRST OCCURRENCE OF space IN city WITH ‘_’.   CONCATENATE ‘http://de.wikipedia.org/wiki/Spezial:Export/‘ city INTO url.   ****Create the HTTP client
TRY.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = url
IMPORTING
client = client
EXCEPTIONS
OTHERS = 1.
 
client->send( ).
client->receive( ).
 
xml = client->response->get_data( ).
client->close( ).
CATCH cx_root.
WRITE: / ‘HTTP Connection error: ‘, city.
ENDTRY.
* Wikipedia does not provide a encoding with the returned XML * so we have to do the conversion manually TRY. CALL METHOD cl_abap_conv_in_ce=>create EXPORTING encoding = ‘UTF-8’ input = xml endian = ‘L’ RECEIVING conv = l_convin.   CALL METHOD l_convin->read IMPORTING data = c_xml. CATCH cx_root. WRITE: / ‘Problem during Character conversion: ‘, city. ENDTRY. ****Transform XML to ABAP Values
TRY.
CALL TRANSFORMATION zwikipedia_mayor_to_abap
SOURCE XML c_xml
RESULT mayor = mayor.
CATCH cx_root.
WRITE: / ‘Data loss during transformation: ‘, city.
ENDTRY.
* Some Mayors already have pecial Pages REPLACE FIRST OCCURRENCE OF ‘[[‘ IN mayor WITH ”. REPLACE FIRST OCCURRENCE OF ‘]]’ IN mayor WITH ”. * Some Mayors are members of a Party SPLIT mayor AT ‘(‘ INTO mayor trash. wa_citymayors-mayor = mayor.   WRITE: / wa_citymayors-city. * Update Database IF NOT wa_citymayors-mayor IS INITIAL. UPDATE zcitymayors FROM wa_citymayors. WRITE: wa_citymayors-mayor. ENDIF. ENDLOOP. The result running this Program with the Parameter ‘Tr%’ the result in table zcitymayors is:

To report this post you need to login first.

5 Comments

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

  1. Anonymous
    Hi Gregor,

    great blog – as usual!
    Have you ever implemented some kind of route planning triggered from SAP, i.e. passes the address of a customer to an URL and receive the homepage of a FREE route planning service showing the route?

    Thanks & regards
    Wolfgang

    (0) 
        1. Anonymous
          Hi Gregor,

          I’ve extracted the URL web.de uses for calling map24 with an example route:
          http://link2.map24.com/?newroute=1&sstreet=Steinbeisweg%2020&szip=74523&scity=Schw%E4bisch-Hall&scountry=DE&dstreet=Guglgasse%206&dzip=1090&dcity=Wien&dcountry=AU&mid=LINK2&lid=a36ca77b

          I don’t know how long this link works since I don’t know the meaning of parameters “mid” and “lid”. I’ve build a prototype with web.de since they provide the HTML coding for insertion on your own homepage. It won’t be a problem to pass the address data of a customer to a BSP application and then auto-submit the form. However, web.de is only a “dispatcher”, i.e. provides the link to other route planners (e.g. map24).

          I do have to use BSP instead of WDA since most of my customers will not upgrade to NW2004s before 2007.

          Regards
          Wolfgang

          (0) 

Leave a Reply