Using SE80 to consume a Web Service in SAP, inlcuding ABAP code to then execute it

The below steps will take you step by step and show you how to first consume any webservice WSDL using an SAP enterprise service and then call it using an ABAP program.

For this example we will use the currency converter available via WSDL link http://www.webservicex.com/currencyconvertor.asmx?WSDL It is supposed to take 2 currency codes (i.e. GBP, AUD, USD) and returns the conversion value.

If you are on a very old version of SAP you might want to check out this guide to creating an ABAP proxy which was the original version of the enterprise service consumer.

Step 1 - Enterprise service consumer creation wizard via SE80

Execute transaction SE80 and within the 'edit object' popup screen select Enhance Options->Enterprise Services tab->Proxy object->Use internal key and then press create.


To create an enterprise service that "consumes" a web service choose Service Consumer. This seems obvious but this caused me a bit of a headache initially as for some reason I chose "Service provider". Quick tip: If you have a service which you think is a Service consumer but you don't have the option to create a logical port via SOAMANAGER check it's not a Service Provider.


Now choose External WSDL/Schema and click continue


Select URL and click continue


Highlight the soap entry(top) and click continue


Now enter the package details or just click the local object check box. Also enter a prefix of something like 'ZESC_', which I use to stand for Enterprise Service Consumer. When the auto generation occurs SAP only has a finite size for the name of the proxy, this prefix helps ensure it does not encounter any duplication problems. Now press Continue.


and on the final screen press complete


Step 2 - Activate the created enterprise service

You should then be returned to the SE80 main screen displaying the new class based service consumer object. You simply need to active it using the activate option.


You could also double click on the class within the ABAP Name field and ensure it is also active


Now return to the previous screen and test the service by pressing the test button


But you will soon realise the service is not ready to test yet as you haven't created a logical port yet. See for yourself and use the search help / F4 to confirm there aren't any available to select.


Step 3 - Create logical port for enterprise service consumer via SOAMANAGER

To create a logical port first execute transaction SOAMANAGER. This used to be done via t-code LPCONFIG but this is now obsolete.


SOAMANAGER will open up in a web browser window and ask for your login details. These are the same ones you log into the backend SAP system


Select the Web Service Configuration option


now search for your service consumer object by selecting "Consumer Proxy" and entering the ABAP name of your service (found on the earlier SE80 screen).


your created object should be returned in the search results, simply click on this


and on the next screen select Create->WSDL Based Configuration


Step 4 - Enter logical port details

Now it's time to enter the details for the logical port. On screen one, enter a name for your logical port i.e. LP_CURR_CONV followed by a description of your choice. Then press the next button


On screen two enter the WSDL link to your web service i.e. http://www.webservicex.com/currencyconvertor.asmx?WSDL and press the next button. Note if your web service required a user name and password you would enter it here.


leave screen three as default and press next


again leave screen four as default and press next


familiarize yourself with the auto entered settings on screen five but again you should be able to leave these as default and simply press next


on screen six simple press next


and again have a look at the options on screen 7 and press next


finally on screen 8 press finish


Step 5 - Test your enterprise service consumer again using the logical port

Now return to se80 and re-test the service consumer using the test button.


This time you should be able to select the logical port name that you have just selected


Press the execute button


You will now be presented with the XML to call the web service which you can modify. You can do this by uploading a file but we will simply use the XML editor. To do this click the XML editor icon.


You will now be able to edit the XML request code. So enter two currency code such as AUD and GBP. Then press the execute button


You will then see the result of the call to the webservice on the response tab. Please note i'm not sure the response value of the web service is correct at the moment but it has at least called the webservice and you have received the response sent back from the web service.


You can actually install SOAPUI on your PC if you want to test the webservice outside of SAP to confirm the response is the same. Also, check out http://www.soapclient.com/?topic=soaptestl which seems to let you check a web service WSDL from their web page.

Step 6 - Call this service consumer/web service from your ABAP code

The next step is to add some simple ABAP code to your SAP application to call this web service consumer.... but think it might be time for a rest so I will let you digest the information above and I will show you how to call it from your ABAP code in the next tutorial.

In the mean time try following the above steps using this new web service I found, which has one input and 2 operations. You enter a number 1 to 9 and one operation converts the number to a word(2 = two) and the other converts it to a dollar value (2 = 2 dollars).

this web service can be found here http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL so give it a try.

Step 7 - Heres the ABAP code to call this web service

For those that just want to see the code to call this web service here it is. I will add a bit more information about how this is constructed based on the web service consumer service.
data: LR_PROXY type ref to
               ZESC_CO_CURRENCY_CONVERTOR_SOA,
      LD_IMP type ZCONVERSION_RATE_SOAP_IN,
      LD_OUT type ZCONVERSION_RATE_SOAP_OUT.
LD_IMP-FROM_CURRENCY = 'AUD'.
LD_IMP-TO_CURRENCY   = 'GBP'.
create object LR_PROXY
  exporting
    LOGICAL_PORT_NAME = 'LP_CURR_CONV'.
try.
call method LR_PROXY->CONVERSION_RATE
  exporting
    INPUT  = LD_IMP
  importing
    OUTPUT = LD_OUT
    .
* catch CX_AI_SYSTEM_FAULT .
* catch CX_AI_APPLICATION_FAULT .
endtry.
write: LD_OUT-CONVERSION_RATE_RESULT.


Click here for Main Web Service Menu



Related Articles

ABAP and SE80 to consume a Web Service - Example to demonstrate simple creation process
ABAP and SE80 to provide a Web Service to the outside world
SAP Visual composer application - modeling tool for rapid application development
Visual composer example - Very simple to implement
Visual composer application with layers to allow each input/output form to be on a separate screen
Consuming a temperature conversion webserve with an SAP VC application
Consuming a webserve with an SAP VC application
SAP web services - Consuming a webservice and surfacing them in SAP for others to use
ABAP and SE80 to consume a Web Service - Example to demonstrate simple creation process