Vous êtes sur la page 1sur 9

Exception Handling in Web Services exposed from an R/3 System

Exception Handling in Web Services exposed from an R/3


System
Applies to:
SAP WAS 6.2 onwards

Summary
We expose an RFC enabled function module as web service in R/3.
While creating the function module, we specify the exceptions that should be raised under the exceptions
tab. When we execute this function module we get just the Exception Name not the Exception Text
maintained against that exception.
Here I will show how to change the exception name in the virtual interface of the web service as well as how
to specify the complete and meaningful exception text in the web service response.
Author(s): Pushkar Anand
Company: Deloitte
Created on: 29 May 2007

Author Bio
I have been working as an SAP ABAP & XI Consultant. Having worked on end to end SAP XI
implementations and the basis activities, now I am moving towards ESA and SOA. XI, ALE and
ESA are my key areas

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


1

Exception Handling in Web Services exposed from an R/3 System

Table of Contents
Exception Handling Description ....................................................................................................... 3
How to over write the exception name ............................................................................................ 5
How to add more meaningful Exception Text.................................................................................. 7
Related Content............................................................................................................................... 8

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


2

Exception Handling in Web Services exposed from an R/3 System

Exception Handling Description


Here I have created a function module ZPL which concatenates firstname and lastname into name and
returns name and date. I have exposed this function module as web service.
If the firstname is Pushkar, it raises an exception EXCEPT1 as shown below.

Source Code :

When I use Raise Exception in the ABAP code it returns just the exception name i.e.EXCEPT1 in the
fault message as shown in the payload attached below.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


3

Exception Handling in Web Services exposed from an R/3 System

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<soap-env:Fault>
<faultcode>soap-env:Client</faultcode>
<faultstring xml:lang="en">EXCEPT1</faultstring>
<detail>
<n0:Zpl.Exception xmlns:n0="urn:sapcom:document:sap:soap:functions:mc-style">
<Name>EXCEPT1</Name>
<Text/>
</n0:Zpl.Exception>
</detail>
</soap-env:Fault>
</soap-env:Body>
</soap-env:Envelope>

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


4

Exception Handling in Web Services exposed from an R/3 System

How to over write the exception name


To overwrite the exception name with more meaningful name, we can edit the virtual interface
created for this web service.
Go to Transaction SE80, select the Enterprise Service and click on the Service Definitions.
Click on the edit button and select Faults->EXCEPT1. Here we can overwrite the default exception
name with more meaningful name to be reflected in the web service.

Now we edit the Exception field in Service Interface as EXCEPTION_PUSHKAR as shown below.

And now on executing this web service the exception in the fault message is EXCEPTION_PUSHKAR
as shown in the payload attached below.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


5

Exception Handling in Web Services exposed from an R/3 System

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<soap-env:Fault>
<faultcode>soap-env:Client</faultcode>
<faultstring xml:lang="en">EXCEPTION_PUSHKAR</faultstring>
<detail>
<n0:Zpl.Exception xmlns:n0="urn:sapcom:document:sap:soap:functions:mc-style">
<Name>EXCEPTION_PUSHKAR</Name>
<Text/>
</n0:Zpl.Exception>
</detail>
</soap-env:Fault>
</soap-env:Body>
</soap-env:Envelope

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


6

Exception Handling in Web Services exposed from an R/3 System

How to add more meaningful Exception Text


To add a meaningful message we define a message class (ZPLATINO) and message text (001) and
use in the source code as shown below.

And now on testing the web service, the fault message contains Exception Name, Exception Text,
Message Id as well as Message No.

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<soap-env:Fault>
<faultcode>soap-env:Client</faultcode>
<faultstring xml:lang="en">EXCEPTION_PUSHKAR</faultstring>
<detail>
<n0:Zpl.Exception xmlns:n0="urn:sapcom:document:sap:soap:functions:mc-style">
<Name>EXCEPTION_PUSHKAR</Name>
<Text>EXCEPTION TEXT FOR PUSHKAR !!</Text>
<Message>
<ID>ZPLATINO</ID>
<Number>001</Number>
</Message>
</n0:Zpl.Exception>
</detail>
</soap-env:Fault>
</soap-env:Body>
</soap-env:Envelope>

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


7

Exception Handling in Web Services exposed from an R/3 System

Related Content
Please include at least three references to SDN documents or web pages.

https://weblogs.sdn.sap.com/pub/wlg/3982

https://www.sdn.sap.com/irj/sdn/enterprisesoa

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c019bf26-8bb8-2910-4f8fe9bd55eda650

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


8

Exception Handling in Web Services exposed from an R/3 System

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces
and therefore is not supported by SAP. Changes made based on this information are not supported and can
be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods
suggested in this document, and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of
this technical article or code sample, including any liability resulting from incompatibility between the content
within this document and the materials and services offered by SAP. You agree that you will not hold, or
seek to hold, SAP responsible or liable with respect to the content of this document.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


9

Vous aimerez peut-être aussi