Skip to Content

SDN Meets Labs: Integrated Web Content

I presented at the Walldorf SDN Meets Labs, what I presented was nothing new. In fact most web developers have been doing for years with multiple other languages. Myself coming from this background found the ability to due this in ABAP and BSP quite lacking. What I didn’t realize was that it was not lacking, only my understanding was lacking.

Thus the quest began.

Over the last year and half on SDN there has been quite a bit of work done on this topic but not nearly enough to point out the simple fact “It’s a lot easier than it looks”.

Now with those items in mind let’s take a look at the main code segment you will need to accomplish the task at hand. That task of course being the ability to integrate external content into your system in what appears to the user as a seamless manner. The idea is that the user has no idea the server has just gone out to another website and retrieved a piece of data.

HTTP Client

This one simple bit of code is your key to unlocking any external content retrievalable by a URL.

That’s it, you need that and nothing more.

Now that we have that, let’s take a look at a single example from the presentation I used, the rest will of course be available for download here on SDN, a link will follow containing the content of the presentation as well as hopefully a link to a video of the presentation.

Exchange Rates

Now personllay the value of the dollar to the Euro is a huge thing for me as I get paid in the US but I live in Germany. I loose quite a bit right now when I transfer money over.


Therefore let’s grab the exchange rate for the Euro. To do this here we will build just a simple little ABAP program. Again the presentation will show other possibilites. But again I want to show one main point, “It’s a lot easier than it looks”.


So as you can see quite easy. Now let’s take this apart, there are a few pieces you have to have in place for this to work:

  • The HTTP Client Code
  • The ability for your server to access to the internet
  • The target, perferably and what I love are the websites like who have a “developers” link
  • Starting point of your text
  • Ending point of your text

Once you have those pieces in place then you are ready to go. For this example we needed our first starting point follwed by an end point and then our final end point and those 3 points are what we use to manipulate our string.


Now once you have those starting points we use some simple but powerful ABAP string commands to get rid of the rest of what we don’t want.

> * Get your data
  data: tmp TYPE STRING,

* Find start point
  tmp = content.
  p = cur.

* New content
  content = tmp+off.

* Find end point
  tmp = content.
  p = ‘<‘.

* New content
  off = off + 1.
  content = tmp+off.

* Find final end point
  tmp = content.
  p = ”.

* New content
  content = tmp+0(off).

There you have it, nice short and easy. For more in depth info please refer to the uploaded content as well as the video presentation.

You must be Logged on to comment or reply to a post.
  • Hi, Craig!
    I attended your presentation on SDN Meets Labs and I believe that it was good. I was hoping to see it on SDN and here it is. Thanks!
    I tested your simple program and got stuck exactly where I expected to: The Internet connection.
    The method call client->receive returns SY-SUBRC = 1 (http_communication_failure), and client->response->get_status returns 404.
    How do I setup proxy settings and authentication? I tried with method client->authenticate before send and receive, but was unsuccessful. What's the trick?
    • Hi Igor!
      Thanks glad you enjoyed it! I didn't touch on the HTTP Proxy stuff as it is covered in my BoF session presentation. However it's actually quite easy, just jump over into SICF and Goto - Proxy Settings there you can set the proxy info for your server, however you will also need to talk to your network people to be sure that your server can get out to the internet to begin with 🙂

      Write back if you still have problems.


      • If you want handle the proxy within the program (instead of global setting suggested by Craig).
        here is the code
        call method cl_http_client=>create
            host          = ''
            service       = '80'
            scheme        = '1'
            proxy_host    =  wf_proxy "
            proxy_service =  wf_port  "8080
            client        = client.

        http_client->propertytype_logon_popup = http_client->co_disabled.

        wf_user = user .
        wf_password = password .

        call method http_client->authenticate
            proxy_authentication = 'X'
            username             = wf_user
            password             = wf_password.

        I have covered this in another weblog at
        Consuming Web Service from ABAP


        • This is true Raja thanks for the code sample 🙂

          For most production systems though it's better to have the server set because if your proxy settings change, like ours did the day before I held my presentation then you have to go through and change all of your coding which of course not so nice.

          In our production server we set it server wide and use authroization objects to control the use.

          For testing though the code sample is a nice one and easier then system wide 🙂

          Thanks again,


        • Raja!
          Thanks to you I am doing a progress. However, it's not over yet. The method call client->receive is fine now (sy-subrc = 0). However, the client->response->get_status returns 407, and the content is "The page cannot be displayed". What could be wrong now? It's a valid page that I'm sending - I have it opened in IE.
          (Sorry - this was supposed to be a blog - I am turning it into forum thread)
          • It must be your proxy / network settings, I just tried it with the code above,

            *& Report Z_WEBBROWSE *
            *& *
            *& *
            *& *

            REPORT Z_WEBBROWSE .

            * Parameters
            parameter: url type c length 255.

            * Data declaration
            data: client TYPE REF TO if_http_client,
            path TYPE STRING,
            scheme TYPE i,
            off TYPE i,
            RC type sy-subrc,
            host TYPE STRING,
            port TYPE STRING,
            content TYPE STRING,
            xcontent TYPE XSTRING,
            BINARY TYPE FLAG,
            timeout type i.

            * Given Path Name
            path = url.

            * Checking if Path is SSL or not
            if path(8) = 'https://' or path(8) = 'HTTPS://'.
            scheme = 2.
            path = path+8(*).
            elseif path(7) = 'http://' or path(7) = 'HTTP://'.
            scheme = 1.
            path = path+7(*).
            scheme = 1.

            if path ca ':'.
            off = sy-fdpos.
            host = path+0(off).
            add 1 to off.
            path = path+off(*).
            if path ca '/'.
            off = sy-fdpos.
            port = path+0(off).
            "add 1 to off.
            path = path+off(*).
            if path ca '/'.
            off = sy-fdpos.
            host = path+0(off).
            "add 1 to off.
            path = path+off(*).
            host = path.
            path = '/'.

            * Setting the port, 80 or 443 for SSL
            if port is initial.
            if scheme = 1.
            port = '80'.
            port = '443'.

            if path is initial.
            path = '/'.

            *create client object
            call method cl_http_client=>create
            host = host
            service = port
            scheme = scheme
            client = client.

            client->request->set_header_field( name = '~request_uri'
            value = path ).
            client->request->set_header_field( name = '~request_method'
            value = 'GET' ).

            * send and receive
            client->send( ).
            call method client->receive
            http_communication_failure = 1
            http_invalid_state = 2
            http_processing_failed = 3
            others = 4.

            * Did you get an error
            RC = sy-subrc.
            client->response->get_status( IMPORTING code = http_rc ).

            * display content
            if binary is initial.
            content = client->response->get_cdata( ).
            xcontent = client->response->get_data( ).

            * Close Client
            client->close( ).

            * Output result
            write: content.

   gives me a return of:


            302 Moved

            #The document has moved#
            Displaying of course in a BSP with a phtmlb:formattedText field would be nicer but the ABAP programs gives you the general idea.

            I would check out your network / proxy settings to ensure that the server is allowed out to the internet since the server is the one making the internet call and connection. Also double check your proxy settings.


  • Hi Craig,

    Nice examples! As you say yourself: it is easy. Once one understands the basics of HTTP programming, the world of harvesting really opens up. This is in my opinion a must learn step on the way to web services, etc.

    One small comment: often in programming, you hear comments about formatting of code to make it easier to read. All of this is important. But what I consider even more interesting is vertical formatting. How can I code a specific sequence with a few lines of elegant code.

    And your FIND sequences reminded me again of similar code I wrote many times before. And later I learned the trick to SPLIT the string. See example code:

    * Extract from HTTP stream ...EUR...>123...
    SPLIT tmp AT cur INTO dummy tmp.
    SPLIT tmp AT '>' INTO dummy tmp.
    SPLIT tmp AT '' INTO tmp dummy.

    Of course, debateable is the performance aspects. But for shortish strings I prefer code that is easy to read and understand. Never did like the offset/length calculations that are required to cut out something from a string. The above brute force is my current hammer for string parsing!

    bye, brian