Professional Documents
Culture Documents
Editor's Note: To be honest, I didn't really understand the Web Application Server as well as I
wanted to—until I read Axel's SAPtips white paper on the subject. Axel has a knack for making
sense of SAP®'s solutions and helping others to understand their value. He believes that SAP's
technological evolution is part of the overall trend towards open platforms and universal
standards. What some SAP users may not realize is that the “future is now”—SAP has already
reached the point where it can provide support for basic, integrated Web services initiatives. But
stepping into SAP Web services does require mastery of new buzzwords like SOAP and WDSL.
And, some key decisions about development environments must also be made. These choices
may depend on which version of SAP is in use, which messaging systems are running, and many
other factors. In this excellent how-to article, Axel digs right into all these issues. Building on his
last piece, Axel starts with a basic introduction to Web services technologies, and then he takes a
closer look at how basic Web services can be designed using WebAS, either with Business
Server Pages or with HTTP extensions. Because this technology is still emerging, there are some
judgment calls that must be made, such as whether to use traditional RFC/SAP HTTP Protocol,
or WebAS's new ABAP Objects/HTTP classes. If this kind of techie talk peaks your interest,
you're going to love Axel's opinionated, bird's eye view of SAP's Web services technologies.
Chock full of actual coding examples, this article gives the real scoop on the technical capabilities
SAP has to offer—capabilities that anyone who is looking to upgrade to the latest versions of SAP
will want (and need) to know about.
Technical Overview: The first part of this white paper1 uncovered the technical landscape of
SAP’s WebAS and outlined how to develop classical server pages through the Business Server
Pages (BSP). Web services are the recognized technology that provides automated services via
the Internet. Given that fact, and given that a majority of international companies have SAP as
their ERP system, it is a natural approach to make use of SAP itself to provide Web services. In
this article, we’ll start by guiding you through an introduction to Web services and emerging
protocols like SOAP and WDSL. Then, we'll discuss how Web services can be implemented
using WebAS, either by means of Business Server Pages, or through SAP’s adaptation of the
Java Servlet technology by means of the HTTP extensions super class.
A note on public XML services: The examples for Web services in this document make use
of the public services provided by Amazon.com. The developer key in the examples has
been invalidated. The examples will still work, but we kindly ask you to register for your
own developer token at http://amazon.com/xml, in order to comply with their code of
conduct and as a gesture to proper “netiquette.”
1
Part one of this series is available for SAPtips subscribers in the SAPtips document library. The
article is titled "How to Develop Web Services in WebAS – Part 1," by Axel Angeli.
RFC
Web services are designed to be accessed from another program, although they can generally be
consulted from a Web browser as well. The calling program can be any program that understands
HTTP, including SAP R/3 starting with release 3.0E. Before we go into details, let’s first learn
more about Web services by example.
To make the request string a little better readable, we insert some line breaks after each part of
the URL (Figure 3). However, the URL above must be entered as one string without any spaces
as shown in Figure 2.
http://xml.amazon.com/onca/xml2
?t=webservices-20
&tag=logosworldcom
&dev-t=D2H30000000000
&AsinSearch=3528057297
&type=lite&f=xml.
Figure 3: The Amazon.com Web Service Request URL Formatted for Better Readability
This request (which asks Amazon.com to list the books authored by someone in my company,
logosworld.com), returns a plain XML document with the requested information included. See
Figure 4 below.
• The public name of the server and the domain; alternately, it can specify the server’s unique
IP address.
• The name of the resource in a format that it is understood by the listening port on the server
• Optionally, parameters to pass further details about the request are provided.
The assembly of these three information items is called a URI – Uniform Resource Indicator. In
cases of Web pages, they are also known as URL – Uniform Resource Locator, where a URL is
generally recognized as a subset or special variant of a URI. So we can say that a reference to a
general point of content within the Internet is called a URI, a Uniform Resource Identifier, while
URL is reserved to address a Web page. Figure 5 shows how a URI is constructed.
Traditionally, a URL references a file on a specific server. Nowadays a URL may point to any kind
of electronic resource that can be reached via HTTP. In these cases, the Web server captures
the URL, and instead of returning a simple file, it calls a program to return a computed result.
Parts of a URI
Resource type
Resource address Resource parameters
r
me ame mete
a n
ol rN in file ara
rotoc erve oma ath& GI-P
P S D p C
http: //www. logosworld.de /asp/testdrive.htm ?user=micky&pass=mausi
Resource address
This is an identifying name of the requested ressource. Usually, this is simply the
filename of the requested document, but it can be any string that is understood
by the server. Usually the server tells from the suffix (e.g., .htm, .txt, .asp, .php,
.cgi).
Ressource type
Tells the server which protocol to use. There are a wide variety of protocols. The
most important protocols are the following ones:
http: HyperText Transfer Protocol
Tells the server that the requester (i.e., the browser) wants to receive
general Unicode-coded documents (e.g., HTML).
ftp: File Transfer Protocol
Protocol specially for file transfers.
smtp: Simple Mail Transfer Protocol
Most important protocol for eMail distribution.
2
If readers are looking for more explanation of the technical terms involved in Web services, we
recommend taking a look at http://whatis.com, delivered by Techtarget.com
One great feature of the “human readable XML format” is that it usually allows an easy discovery
of its contents and the document structure without the need for external documentation. As a
point of comparison, many EDI projects failed primarily because the chosen formats were
proprietary and had been disclosed only to a pre-selected, exclusive audience (E.G. EDIFACT
documentation is only accessible by paying dues to the organization).
2. Web services should be easily adaptable to a range of clients and operating systems.
The “Alpha and Omega” of Web services is “compatibility through convention”. No matter the
content, Web services look largely the same. With the use of XML, it is possible to parse
documents for necessary information, instead of mapping to a strict, inflexible format. Given this
flexibility, a handler program can react smoothly on changes and additions in the sent documents.
then called an “HTTP Post request”. There are many uses of HTTP Post requests, e.g., an HTTP
Post request is sent to a server if you fill out an online HTML form in your browser and submit the
form data. Amazon.com accepts requests from an HTTP Post as well and, in this case, it uses
the SOAP protocol standard.
SOAP is the acronym for the Simple Object Access Protocol and is itself an XML document. In
addition to having the same features as a plain XML document, SOAP defines restrictions on
how the document must be structured and how the XML tags have to be named. SOAP was
designed out of the simple need to provide a standard format for the multiple ways you could
structure a response with respect to naming your tags and laying out your response tree. SOAP
has been designed to be used out of programs; therefore it is not that easy to test this variant in
your browser, but in Figure 6, we show what a SOAP request might look like.
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<AsinSearchRequest>
<AsinSearchRequest>
<asin>3528057297</asin>
<tag>logosworldcom</tag>
<type>lite</type>
<dev-tag>12345678901234</dev-tag>
</AsinSearchRequest>
</typens:AsinSearchRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
must be defined with transaction SM59 in SAP (Figure 8), pointing to SAPHTTP either on the
server or on the PC that has SAPGUI on. In the latter case, SAPHTTP will be called via the
SAPGUI on the workstation.
Using SAPHTTP, you call the following function modules:
• function HTTP_GET, and
• function HTTP_POST
with the destination of SAPHTTP. See Figure 7 for an example of accessing Web services in
SAP, using our Amazon.com book query example.
DATA: ABSOLUTE_URI(128) type c.
data: response_headers(80) occurs 0 with header line.
data: RESPONSE_ENTITY_BODY(120) occurs 0 with header line.
ABSOLUTE_URI =
'http://xml.amazon.com/onca/xml2?t=webservices-20' &
'&tag=logosworldcom&dev-t=D2H30000000000' &
'&AsinSearch=3528057297&type=lite&f=xml'.
CALL FUNCTION 'HTTP_GET'
EXPORTING
ABSOLUTE_URI = ABSOLUTE_URI
RFC_DESTINATION = 'SAPHTTPA'
PROXY = '192.168.69.64:8080'
TABLES
* REQUEST_ENTITY_BODY =
RESPONSE_ENTITY_BODY = RESPONSE_ENTITY_BODY
RESPONSE_HEADERS = RESPONSE_HEADERS
* REQUEST_HEADERS =
EXCEPTIONS
OTHERS = 8.
LOOP AT response_entity_body.
WRITE: / response_entity_body.
ENDLOOP.
Figure 7: SAP as Web Service Client with ABAP via SAPHTTP Utility
Calling a Web Services with the SAP WebAS HTTP Extension Class
WebAS, with its generic HTTP interface, proposes to use the IF_HTTP_CLIENT interface class
instead. Standard SAP WebAS distribution includes the report SXSLT_TEST, whose form
LOAD_HTTP gives an example of how to request an HTTP page. In Figure 9 we constructed
another example to demonstrate the essential.
Intermezzo (and key SAP RFC tip):
I recommend continuing to use the traditional method via the RFC destination to SAPHTTP
whenever possible. Not only will it keep your development backward-compatible with older SAP
releases, but the new access method, via the ABAP Object syntax, is still in a state of evolution,
and cannot currently satisfy the needs of a modern developer. Unfortunately, ABAP Workbench,
the traditional SAP development environment, only has very basic support for ABAP/Objects. The
core tool of every modern development workbench, the debugger, does not allow the display of
essential information about ABAP/Objects and the current setting of attributes. The ABAP editor
does also not support ABAP/Objects in a convenient way. Editing aids, like Intellisense, which
displays methods and attributes for an object while you type, are either completely missing or
awkward to use. With respect to the HTTP classes that ship with WebAS, it must be said that a
large part of the coding is realized on the kernel level, which makes it nearly impossible to debug
there. I am aware that a large community of developers, who dedicate their time, ambition, and
professional obsession to object oriented development will heavily object, but from an
experienced software architect’s and software auditor’s point of view, this way in which HTTP
services are currently implemented in WebAS cannot be endorsed at this time.
The only advantage of the HTTP classes over the traditional SAPHTTP is the direct
implementation of all HTTP features, as opposed to SAPHTTP, which basically does HTTP
forwarding to your proxy. But when you take into account that real life implementations of Web
clients from SAP will forcibly access the Internet via a proxy anyway, this is not much of an
advantage. Therefore, I decidedly state that, as of this writing, the best practice is to ignore
the HTTP classes of WebAS, while continuing to use SAPHTTP for outbound Internet
access and BSP for inbound HTTP calls. I will keep an eye on the evolving ABAP/Objects
and HTTP classes of WebAS, and at the point where these new technologies surpass the
traditional SAP HTTP protocols, I will author an update to SAPtips readers. For a detailed
look at the WebAS HTTP client classes, see Figure 9 below, which submits a query to
Amazon.com.
REPORT ZAXXTEST_CLHTTP. .
CLASS cl_ixml DEFINITION LOAD.
DATA: response TYPE string.
DATA: g_ixml TYPE REF TO if_ixml.
DATA: g_stream_factory TYPE REF TO if_ixml_stream_factory.
DATA: headfields TYPE tihttpnvp.
DATA: client TYPE REF TO if_http_client,
host TYPE string, port TYPE string,
proxy_host TYPE string, proxy_port TYPE string,
path TYPE string, scheme TYPE i.
During program load we create factory (helper) classes for XML handling
LOAD-OF-PROGRAM.
g_ixml = cl_ixml=>create( ).
g_stream_factory = g_ixml->create_stream_factory( ).
START-OF-SELECTION.
Setting the parameters needed by the object
host = 'http://xml.amazon.com'.
port = '80'.
path =
'/onca/xml2?t=webservices-20' &
'&tag=logosworldcom&dev-t=D2H30000000000' &
'&AsinSearch=3528057297&type=lite&f=xml'.
proxy_host = '192.168.69.64'.
proxy_port = '8080'.
scheme = 1. "1=HTTP 2=HTTPS
<definitions targetNamespace=
"urn:PI/DevCentral/SoapService" name="AmazonSearch">
<types>
<xsd:schema>
<xsd:complexType name="AsinRequest">
<xsd:all>
<xsd:element name="asin" />
<xsd:element name="tag" />
<xsd:element name="type" />
<xsd:element name="devtag" />
<xsd:element name="offer" />
<xsd:element name="offerpage" minOccurs="0"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<message name="AsinSearchRequest">
<part name="AsinSearchRequest"
type="typens:AsinRequest"/>
</message>
<message name="AsinSearchResponse">
<part name="return" type="typens:ProductInfo"/>
</message>
</definitions>
Figure 10: WSDL-Definition of an Amazon Search by Article Number (ASIN)
We’ll now vary this example by inserting some useful XML tags to represent a proper request
response (see Figure 11). The format of the resulting XML document is taken from the template
defined in the interface repository http://ifr.sap.com. As another variation, we could also enhance
the template from the IFR and easily construct a SOAP document, which differs only in some
named tags. We'll do this later in this paper.
<%@page language="abap"%>
<%
DATA: exch_rate_list type bapi1093_0.
<%@page language="abap"%>
<html>
<head>
<link rel="stylesheet"
href="../../sap/public/bc/bsp/styles/sapbsp.css">
<title>Simulation of AMAZON Web Services through BSP</title>
<%
DATA: BEGIN OF parm,
name TYPE string, value TYPE string, rc TYPE i,
END OF parm.
DATA: querystring TYPE string.
DATA: request_uri TYPE string.
DATA: query TYPE REF TO cl_swlwp_uri.
DATA: xml TYPE string.
DATA: tfields TYPE tihttpnvp, field TYPE LINE OF tihttpnvp.
**** Here we read all information pairs of the HTTP request ********
CALL METHOD request->get_header_fields
CHANGING fields = tfields.
**** This one reads the query_string explicitely ********
CALL METHOD request->get_header_field
EXPORTING name = '~query_string'
RECEIVING value = querystring.
*********** URI Helper Class **************************************
* Initialize the helper class to better deal with query strings URI
* need a dummy prefix to make the class work properly
CONCATENATE 'dummy?' querystring INTO querystring.
CALL METHOD cl_swlwp_uri=>create_from_string
EXPORTING im_string = querystring
IMPORTING ex_uri = query.
*********** Extract a single parameter ****************
parm-name = 'ASIN'.
CALL METHOD query->get_query_parameter
EXPORTING im_name = parm-name
IMPORTING ex_value = parm-value.
**** Here we better call a function module to do our service.
* CALL FUNCTION 'Z_AXX_XML_BOOKSTORE'
* EXPORTING querystring = querystring
* IMPORTING XML = XML.
*******************************************************
%>
</head>
<body class="bspBody1">
<H1>Simulation of AMAZON Web Services through BSP</H1>
<HR>QueryString: <% = querystring %>
<br>PARAM: Name=<% = parm-name %> Value=<% = parm-value %> RC= <% =
parm-rc %>
<HR><table>
<% LOOP AT tfields INTO field. %>
In Figure 13 we show the way to simulate the Amazon.com article number search. The example
returns an XML data stream in the way it is done by Amazon.com. Since there is no bookstore
available in the WebAS basic version, we simply echo the received parameters in the result
string, assuming that this is sufficient guidance to add the necessary code to return the desired
result data in the resulting XML stream.
<%@page language="abap"%>
<%
%>
3
Extending a class is also known as inheriting a class, depending on which terminology of object
oriented programming is used
When the HTTP service request is received by the WebAS, it calls the method
HANDLE_REQUEST() of the named class. In our example, pingservice is the public name
that has been assigned to the implementing class in transaction SICF. The implementing class
should be an extension of the default handler class IF_HTTP_EXTENSION, and it should
implement a method with the fixed name HANDLE_REQUEST().
The IF_HTTP_EXTENSION class implements all important methods and attributes that are
needed for handling the response and request parts of an HTTP communication. See Figure 15.
method IF_HTTP_EXTENSION~HANDLE_REQUEST.
data: result type string.
server->response->set_header_field(
name = 'Content-Type'
value = 'text/html' ).
Within the HANDLE_REQUEST method, an arbitrary ABAP Object code can be executed.
Finally, the response object must be furnished with the response data, according to the
requirements of the requesting HTTP client. In the pingservice example, we assume that the
request expects a simple standard HTML response. So the response header is set with the
method
server->response->set_header_field
accordingly to text/html and the result data block is set to the response data with method
server->response->set_cdata( data = ) .
In addition to returning the data, we need to set the HTTP header information, which is
sometimes mandatory and sometimes only useful. Typically, the header would at least provide
information about the content of the document data that is sent in the document body. In our
case, we tell the receiver of the document that the body contains HTML data. The valid content
descriptors are defined by the W3C MIME recommendation.
server->response->set_header_field(
name = 'Content-Type'
value = 'text/html' ).
As a next step, we build the result string, which actually can be an arbitrary text. As a best
practice rule, you would insert a call to a function module that returns the final result data string.
This is “best practice” because it reduces the amount of code within an interface handler to a
minimum. Doing so, the request handler is used as a wrapper for the application and as a
jumping board to call the actual processing only:
result = '<html><body>'(001) &
'Connection to server successful'(101) &
'SystemID: &SYSID&'(102) &
'</body></html'(999).
Every method will be called exclusively from the matching context, and the response of each
method is a string that is returned in the body of HTTP response. Before we can use the servlet,
the servlet class must be deployed in the Web server’s servlet container. When this is
successfully done, it can be called via an HTTP Get or HTTP Post request by specifying nothing
more than the class name in the URL. If the class requires parameter information, it can be
appended to the URL separated by a question mark (?) to build a canonical URI, which we are
already familiar with. See Figure 16.
method if_http_extension~handle_request.
* parameters:
* [in] if_http_server& server
* Call through browser: http://linux:8080/sap/public/info
clear xdata.
create object soapdoc.
if not soapdoc is initial.
try.
call method soapdoc->set_method
exporting name = 'RFC_SYSTEM_INFO.Response'
nsprefix = 'rfc'
nsvalue = CSoapConstants=>sc_rfc_function_ns.
get reference of l_rfcsi into dref.
call method soapdoc->add_parameter
exporting name = 'RFCSI'
value = dref
direction = CSoapConstants=>ic_param_in.
isoapdoc = soapdoc.
call method isoapdoc->serialize
changing document = xdata.
* -- set header field
call method server->response->set_header_field(
name = 'Content-Type' "#EC NOTEXT
value = 'text/xml' ).
catch CSoapExceptionUsage into exUsage.
"-- don't care
clear xdata.
catch CSoapExceptionResource into exResrc.
clear xdata.
catch CSoapExceptionInternal into exIntrn.
clear xdata.
endtry.
endif.
if xdata is initial.
call method server->response->set_header_field(
In my system, the resulting SOAP document looks as follows in Figure 18. If you look closer, you
will find that the SOAP document is nearly identical with the template provided by the SAP
interface repository, but with one small enhancement: the template is embraced by the SOAP-
ENV envelope tags.
Figure 18: SOAP Document Produced with Aid of the SoapdocÆadd_parameter Method
However, there are other arguments for upgrading your SAP ERP system to SAP Enterprise 4.7:
• SAP Enterprise will allow you to easily design browser access to SAP for Intranet solutions.
These solutions are becoming more and more popular, because they don't involve deploying
SAPGUI on every workstation.
• Secondly, having SAP function like any HTTP server, as it does in SAP Enterprise, allows a
smoother communication with other internal TCP/IP applications, including your own Internet
Web server.
Smooth HTTP interaction can provoke a nominal return of investment when you have a complex
heterogeneous server landscape. Whereas having RFC access means deploying the necessary
drivers on the client computer, calling dedicated libraries, and being dependent on SAP-provided
utilities and documentation during development, the use of WebAS allows you to access your
SAP ERP system in the same manner and use the same utilities as you would to access any
other online location or Web server.
Although programming RFC access is relatively easy, and it's available for most common
operating platforms (including Windows, Java on Windows, Linux, and UNIX), deploying an RFC
application requires that the client computer has the necessary RFC drivers installed.
Installing drivers on a productive machine is always critical. You have to consider:
• deployment and registering of the drivers
• rebooting the box after installation
• allowing for the proper security mechanisms
• hat testing your application may interfere with existing applications and even bring them
down.
When you decide to activate HTTP communication with SAP, you will benefit from the already-
installed TCP/IP tools that are universally installed on every modern computer from mainframes
down to pervasive palm-top clients. This allows access to SAP from every computer within reach
of your network, without any special preparation of the client.
Another benefit of SAP HTTP: your development and deployment team will also avoid endless
discussions with the Basis and security administration team. Every proprietary standard used in
your server landscape will likely explode your training and planning costs. What may look like an
easy five-minute task to your development team suddenly turns out to become an elaborate
ceremony requiring weeks of planning. Once your SAP talks HTTP, it is only up to whoever is
handling the firewall to open or deny the access to your SAP ERP system. This takes the
discussion away from technical complexities and allows for a more strategic focus.
So, based on the strengths of the WebAS and Enterprise 4.7, what is my final assessment in
terms of the best approach to Web services? My current recommendation, as of this writing, is
that WebAS and Enterprise 4.7 is the ideal platform for SAP Web services, for all the reasons I've
outlined in this paper. But, keep in mind, that specifically when submitting a SOAP request to the
SAP system, I recommend continuing to use SAP HTTP and RFC, not the HTTP classes of
WebAS, until the HTTP classes and ABAP/Objects technologies mature. Even if you're running
on WebAS, you can still continue to use SAP HTTP and traditional RFC methods. And, best of
all, you do not need to be running WebAS or 4.7 to start using Web services in your application
environment.
Axel Angeli is a senior SAP and EAI advisor and principal of logosworld.com, a German-
based enterprise specializing in coaching SAP and EAI project teams and advising IT
management on implementation issues. Axel has been in the IT business since 1984, and
throughout his career, he has always worked with cutting edge technologies. Axel's SAP
experience stems back from the good old R/2 days and he is an expert on SAP’s NetWeaver
technology and any kind of ABAP development. A speaker of several languages, Axel
specializes in coaching and leading large multi-national teams on complex projects with
heterogeneous platforms and international rollouts. Known for his intensive and successful
trouble-shooting experience, Axel has been nicknamed by his colleagues as the “Red Adair”
of SAP projects. He is the author of the best-selling tutorial “The SAP R/3 Guide to EDI, IDocs,
ALE and Interfaces.”
The information in our publications and on our Website is the copyrighted work of Klee Associates, Inc. and is owned by
Klee Associates, Inc.
NO WARRANTY: This documentation is delivered as is, and Klee Associates, Inc. makes no warranty as to its accuracy
or use. Any use of this documentation is at the risk of the user. Although we make every good faith effort to ensure
accuracy, this document may include technical or other inaccuracies or typographical errors. Klee Associates, Inc.
reserves the right to make changes without prior notice.
NO AFFILIATION: Klee Associates, Inc. and this publication are not affiliated with or endorsed by SAP AG. SAP AG
software referenced on this site is furnished under license agreements between SAP AG and its customers and can be
used only within the terms of such agreements. SAP AG and mySAP are registered trademarks of SAP AG.
All other company and product names used herein may be trademarks or registered trademarks of their respective
owners.