Skip to Content

Consuming Web Service from ABAP

There have been many requests to know how to consume webservice from ABAP. I wanted to share a rudimentary sample written in ABAP of how this can be done. I am not sure whether this is a right approach though it does the job. Inspiration for this approach was from DJ Adams weblog Forget SOAP – build real web services with the ICF

For this exercise I have used a free webservice for getting Airport details by country name located at   (please go to this URL to look at the SOAP message)


Points to note:

  • The output internal table (outtab)  is designed after looking at the SOAP response. This can also be done dynamically using ABAP XSLT and CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
  • SAP system Used: 4.7/6.2 WAS


wf_user = user .
wf_password = password .

  1. proxy server authentication

CALL METHOD http_client->authenticate
    proxy_authentication = ‘X’
    username             = wf_user
    password             = wf_password.
CALL METHOD http_client->request->set_header_field
    name  = ‘~request_method’
    value = ‘POST’.
CALL METHOD http_client->request->set_header_field
    name  = ‘~server_protocol’
    value = ‘HTTP/1.1’.
CALL METHOD http_client->request->set_header_field
    name  = ‘~request_uri’
    value = ‘/airport.asmx’.
CALL METHOD http_client->request->set_header_field
    name  = ‘Content-Type’
    value = ‘text/xml; charset=utf-8’.
CALL METHOD http_client->request->set_header_field
    name  = ‘Content-Length’
    value = txlen.
CALL METHOD http_client->request->set_header_field
    name  = ‘SOAPAction’
    value = ‘http://www.webserviceX.NET/GetAirportInformationByCountry‘.
CALL METHOD http_client->request->set_cdata
    data   = wf_string
    offset = 0
    length = rlength.
CALL METHOD http_client->send
    http_communication_failure = 1
    http_invalid_state         = 2.
CALL METHOD http_client->receive
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3.
CLEAR wf_string1 .
wf_string1 = http_client->response->get_cdata( ).
    ‘<‘ IN wf_string1 WITH ‘<‘ .
 ‘>’ IN wf_string1 WITH ‘>’ .
 ‘xmlns=’ IN wf_string1 WITH ‘xmlns:xsl=’ .
            SOURCE XML wf_string1
            RESULT     outtab = outtab.
  CATCH cx_xslt_exception INTO xslt_err.
    DATA: s TYPE string.
    s = xslt_err->get_text( ).
    WRITE: ‘: ‘, s.
Loop at outtab .
Write:/ outtab .
Endloop .



+Path =>   Txn SE80 – > Edit Object (shift F5) ->more->XSLT program</p><p class=”MsoNormal”> </p><p class=”MsoNormal”><textarea cols=”85″ name=”S1″ rows=”12″><xsl:stylesheet xmlns:xsl=”” version=”1.0″>
  <xsl:strip-space elements=”*”/>
  <xsl:output indent=”yes”/>
  <xsl:template match=”NewDataSet”>
    <asx:abap xmlns:asx=”” version=”1.0″>
          <xsl:for-each select=”Table”>
                <xsl:value-of select=”AirportCode”/>
                <xsl:value-of select=”CityOrAirportName”/>
                <xsl:value-of select=”Country”/>
                <xsl:value-of select=”CountryAbbrviation”/>
                <xsl:value-of select=”CountryCode”/>
                <xsl:value-of select=”GMTOffset”/>
                <xsl:value-of select=”RunwayLengthFeet”/>
                <xsl:value-of select=”RunwayElevationFeet”/>
                <xsl:value-of select=”LatitudeDegree”/>
                <xsl:value-of select=”LatitudeMinute”/>
                <xsl:value-of select=”LatitudeSecond”/>
                <xsl:value-of select=”LatitudeNpeerS”/>
                <xsl:value-of select=”LongitudeDegree”/>
                <xsl:value-of select=”LongitudeMinute”/>
                <xsl:value-of select=”LongitudeSeconds”/>
                <xsl:value-of select=”LongitudeEperW”/>
</textarea></p><p style=”margin-left: 0.25in” class=”MsoNormal”> </p>

You must be Logged on to comment or reply to a post.
  • this blog is a perfect example for anyone who wants to start using SOAP over HTTP in ABAP

    Thank you very much for making it so simple


      • Hi Raja,

        I need a help from you. I need to transfer XML data to another server. I want tranfer by using SAP WEB API through HTTP POST. Do you know how to do that.Please help me on this


        Thanks and Regards,



    • hi there,
      this blog was great for the time (and releases)written and it is still great today in demystifying webservices because of its illustrativ approach showing that a soap message isn’t much more than an ordinary HTPP message containing some special header fields and a specific kind of payload.

      Nevertheless, IMHO it’s not really state of the art today and for contemporary releases. Today we have wizards creating soap clients from the WSDL directly therefore being more accurate by taking into account soap errors, handling HTTP error conditions and considering data types (a little). Moreover XML bodies do not have to be parsed ‘manually’.

      I suggest to have a look at the webservices section here on SDN and find a number of actual examples.

      But again I want to state that it was a great blog at it’s time and it still is for didactical reasons today.


  • Hi,

    I tried to use the code to execute the program, however in the http_client->receive call i receive sy-subrc = 1,  I am not using any user id pwd when executing the program.

    Could you tell me the configuration steps required before program execution. I checked Proxy settings/port/transaction SICF etc but am not sure what exactly needs to be done.

    Thank you

  • Hi,

    I checked with our basis team and they mentioned that we did not need to use proxy authentication, however we kept getting this error “HTTPIO_PLG_NO_MPI_INIT” and I checked in OSS and found note 876932 which needs a patch to be applied.Hope the patch helps.Will keep SDN updated. 

  • Hi,
      I tried to test this example on a 4.6C system (no WAS).

    I am getting compilation errors :
    DATA: xslt_err TYPE REF TO cx_xslt_exception .
    Error is : type cx_xslt_exception is unknown.

    Can you suggest if we need to be on 4.7 & WAS 6.XX. Or do we need to install any add-ons.


    • it wont work in 4.6C.

      to make it work in 4.6C you need use http_get function module instead of cl_http_client class and also you cannot use CALL TRANFORMATION


    • Hi Raja,
        Thanks for your reply. We tried it in 4.7 & it works fine.

      Now we are planning to use this in our ECC 6.0 system. But it is not working, do you know if we need to make any chnages to make it work.


  • Hello ,
         In my WSDL I have a Hierarchy so that the repeating values in an table is not sent everytime in the input and output. I am able to consume the Webservice but when trying to send the request I am having issues with the data types etc.
    Input : Example: Order Number,sold to party
                          |—–Item number
                          | —–Product
                                 |—– Qty
               |——-Attributes of the product
    Is  there a place I can get a sample of the above scenario.


  • Hi Raja,
    Thanks for info. We tried it in 4.7 & it works fine.

    Now we are planning to use this in our ECC 6.0 system. But it is not working, do you know if we need to make any chnages to make it work.


      • Hi Raja,
          Thanks for the reply.

        I will review the other blog as well.

        Your example we tested in 4.7 & it worked fine. How ever in ECC 6.0 the following statement is not brining any response.

        CLEAR wf_string1 .
        wf_string1 = http_client->response->get_cdata( ).

        So there could be some issue in the earlier coding also some where.

        Is there any checks that we can do if this is a SAP system issue (Do we need to activate any services etc on the SAP system ) or the ABAP program issue.


        • Hi Raja,
            Although I am in SAP (ABAP – more than 8 yrs), I am not much into BSP’s etc.
          What is the basic difference between the solution given in your blog & the newer one you suggested to review.


          • in this example i am hardcoding soap message whereas in the other weblog i have linked, you created what is called client proxy from the wsdl (which is basically a ABAP class)

            and that abap class/method can be called to consume the webservice.


  • Hi Raja,

    I get the error in the subject line, I tried to check for the other dynamic options to perform transformation in 6.2 but could not get clear understanding from the documentation.

    If you have a good weblog in mind do mention the same.

    Thank you.

  • Hi,
    FIrst off, your weblog was a great source of information for calling webservices from ABAP.
    I really learned a lot.

    I copy pasted your code but ran into a small problem.
    I am getting the error ‘:  ABAP XML formatting error in XML node of type “element”, name: “{}abap”
    when i execute ‘Y_CONSUME_WEBSERVICE’.

    And in the debugger I can see after the statement
    wf_string1 = http_client->response->get_cdata( )
    all the right data in the string.

    But it fails at
                  SOURCE XML wf_string1
                  RESULT     outtab = outtab.

    and I get the output as I have pasted on the top.

    Can you tell what could be wrong here?

    Thanks a lot.

    • the error is to do with the XSLT. can you copy paste the code which wf_string1 has and the xslt code and mail it to me , will see whats going wrong. you can find my email id in my business card.


    • I’m getting the same error.  Raja, do you have a resolution to this problem?  wf_string1 has data.  I can see the results in xml format.  However, it won’t translate to ABAP.

      BTW, Great BLOG.  It helped me a lot.

      Thank you,

      • I ran into the same problem. When analysing the SOAP Response you will see, that the inner tags are html encoded < instead of < (> instead of >)

        The following lines in the code should replace that:

        ‘<‘ IN wf_string1 WITH ‘<‘ .

        ‘>’ IN wf_string1 WITH ‘>’ .

        Unfortunately, it does not show correctly on an HTML page, because the right version is:

        ‘<‘ IN wf_string1 WITH ‘<‘ .

        ‘>’ IN wf_string1 WITH ‘>’ .



  • Hi Raja, thanks for thes valuable blog.

    You write:
    In this example the SOAP message is hard coded, better way would be to get the WSDL and parse it using ABAP XSLT program and build the SOAP message at runtime.

    Would you please give some hints, how to do that. Unfortunately I have to call a service from a 4.7 system.

    • you would need a such a parser only if you are going to build a abap proxy generation system. if its one off (or few WS calls) then i would suggest to manually build the SOAP message. Moreover, from WAS 6.40 SAP provides mechanism to build the client proxy. Wo its going to be waste of time building one.


  • Hi Raja,

    Thanks for you example, I tested it and it works fine! However, in your example, you have SOAP message hard coded, however I will have to call WSDL service (one file).
    Do you have an example how to call WSDL service from ABAP?

    Thanks in advance!


    • This example was written for old version of R/3. if you are on WAS 6.40 or above, you should use the standard way of creating client proxy from WSDL for consuming the webservice. You can find quiet a few examples on this in the webblog area here.


  • Hi Raja
    Thank´s a lot for this weblog , I´ve learned a lot and it´s very clear and simple .
    I need to do something like this because of problems of compatibility between the version of SAP at work (640) and my Web service supplier ; problem is that client proxy generation wizard is not able to  generate the methods ,ending with errors .
    I´d like to adapt your example to my own proyect but I´m facing 3 problems :

    – 1) In variable wf_string you hardcode a SOAP message ¿how do i know the message that I have to hardcode in my own wf_string variable?
    – 2) You are using method CALL METHOD http_client->request->set_header_field ¿ how do i know what header fields should i SET for my own needs?
    – 3) Related to transformation , SE80 give us 2 possibilities:S , Simple transformation X , XSLT programm ; I´m using XSLT program , according to your blog ,question is ¿there´re some guidelines to write the code i´ve to include , for example , I guess , in the wsdl file?

    Thank you again

    • 1] I used a free tool called webservicestudio to analyze the wsdl and come up with request SOAP message format.

      2]Its purely dependent on the service definition of your WS

      3]I am not sure i understood the question in full, but you could use whatever you are comfortable with. i always use XSLT.

  • Hello,

    Thanks for this blog.
    I copy the program and transformation, but when i execute the program, a message is displayed : ‘No valid source context supplied’.

    Can you help me ?

  • Hi Raja, thanks a lot for posting all this. I’ve been browsing around and there’s almost no information on this subject.

    I need some assistance anyway, and maybe you can enlighten me about my problem.

    I’ve copied both program and transformatioin, but when running the report I constantly get this error about non valid source.

    This is the begining of what I have in wf_string1 before the transformation:

    Do you have any ideas of what could be wrong here?
    Is there any customizing needed before the code you posted works?

    Thanks once again,


  • The reply button didnt work, thus posting as a new message.

    Can you check whether the webservice works from browser? from the sample response, you had posted, looks like the ws is not returning proper xml.

    • Hi Raja, thanks for your answer.
      As you said, I checked the service and it was unavailable. Once it was restablished, the program worked ok.
      Now I’m having some dificulties with the transformation.
      I get a message saying that there’s an error in a field of type text, name ‘{}’. Any suggestions about this?
      By the way, would you have any information you could share about consuming web services running on secure http?

      Thank you once again.
      Best regards,