Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
athavanraja
Active Contributor

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 http://www.webservicex.net/airport.asmx?op=GetAirportInformationByCountry   (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

 

ABAP Report  Y_CONSUME_WEBSERVICEco_disabled.
 
wf_user = user .
wf_password = password .
 
  1. proxy server authentication


CALL METHOD http_client->authenticate
  EXPORTING
    proxy_authentication = 'X'
    username             = wf_user
    password             = wf_password.
 
 
CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = '~request_method'
    value = 'POST'.
 
CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = '~server_protocol'
    value = 'HTTP/1.1'.
 
CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = '~request_uri'
    value = '/airport.asmx'.
 
CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = 'Content-Type'
    value = 'text/xml; charset=utf-8'.
 
CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = 'Content-Length'
    value = txlen.
 
CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = 'SOAPAction'
    value = 'http://www.webserviceX.NET/GetAirportInformationByCountry'.
 
CALL METHOD http_client->request->set_cdata
  EXPORTING
    data   = wf_string
    offset = 0
    length = rlength.
 
CALL METHOD http_client->send
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2.
 
CALL METHOD http_client->receive
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3.
 
CLEAR wf_string1 .
wf_string1 = http_client->response->get_cdata( ).
 
REPLACE ALL OCCURRENCES OF
    '<' IN wf_string1 WITH '<' .
 
REPLACE ALL OCCURRENCES OF
 '>' IN wf_string1 WITH '>' .
 
REPLACE ALL OCCURRENCES OF
 'xmlns=' IN wf_string1 WITH 'xmlns:xsl=' .
 
TRY .
    CALL TRANSFORMATION (`Y_AIRPORT_XML2ABAP`)
            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.
    STOP.
 
ENDTRY .
 
Loop at outtab .
Write:/ outtab .
Endloop .


XSLT program  Y_AIRPORT_XML2ABAP.

 

+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="http://www.w3.org/1999/XSL/Transform" version="1.0">
 
  <xsl:strip-space elements="*"/>
 
  <xsl:output indent="yes"/>
 
 
  <xsl:template match="NewDataSet">
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
        <OUTTAB>
          <xsl:for-each select="Table">
 
            <OUTTAB1>
              <AIRPORTCODE>
                <xsl:value-of select="AirportCode"/>
              </AIRPORTCODE>
              <CITYOFAIRPORTNAME>
                <xsl:value-of select="CityOrAirportName"/>
              </CITYOFAIRPORTNAME>
              <COUNTRY>
                <xsl:value-of select="Country"/>
              </COUNTRY>
              <COUNTRYABBRIVATION>
                <xsl:value-of select="CountryAbbrviation"/>
              </COUNTRYABBRIVATION>
              <COUNTRYCODE>
                <xsl:value-of select="CountryCode"/>
              </COUNTRYCODE>
              <GMTOFFSET>
                <xsl:value-of select="GMTOffset"/>
              </GMTOFFSET>
              <RUNWAYLENGTHFEET>
                <xsl:value-of select="RunwayLengthFeet"/>
              </RUNWAYLENGTHFEET>
              <RUNWAYELEVATIONFEET>
                <xsl:value-of select="RunwayElevationFeet"/>
              </RUNWAYELEVATIONFEET>
              <LATITUDEDEGREE>
                <xsl:value-of select="LatitudeDegree"/>
              </LATITUDEDEGREE>
              <LATITUDEMINUTE>
                <xsl:value-of select="LatitudeMinute"/>
              </LATITUDEMINUTE>
              <LATITUDESECOND>
                <xsl:value-of select="LatitudeSecond"/>
              </LATITUDESECOND>
              <LATITUDENPEERS>
                <xsl:value-of select="LatitudeNpeerS"/>
              </LATITUDENPEERS>
              <LONGITUDEDEGREE>
                <xsl:value-of select="LongitudeDegree"/>
              </LONGITUDEDEGREE>
              <LONGITUDEMINUTE>
                <xsl:value-of select="LongitudeMinute"/>
              </LONGITUDEMINUTE>
              <LONGITUDESECONDS>
                <xsl:value-of select="LongitudeSeconds"/>
              </LONGITUDESECONDS>
              <LONGITUDEEPERW>
                <xsl:value-of select="LongitudeEperW"/>
              </LONGITUDEEPERW>
            </OUTTAB1>
          </xsl:for-each>
        </OUTTAB>
 
      </asx:values>
    </asx:abap>
 
 
 
  </xsl:template>
 
</xsl:stylesheet>
</textarea></p><p style="margin-left: 0.25in" class="MsoNormal"> </p>
41 Comments