Consume an External Web Service in a Nutshell With Good Old ABAP
Short Description
Download Consume an External Web Service in a Nutshell With Good Old ABAP...
Description
Consume an External Web Service in a Nutshell with good old ABAP
Applies to: SAP_BASIS, Release 701, SP Level 8
Summary Have you ever tried to consume an external web service out of ABAP? This document provides a detailed description which steps have to be processed to call an external web service. It is easy to reproduce and can be a basis for more complex developments using external web services. Author:
Andreas Hettich
Company: SAP AG Created on: 15 April 2011
Author Bio Andreas is a principal architect at SAP Custom Development and mainly focused on developments in the area of Financials.
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
Consume an External Web Service in a Nutshell with good old ABAP
Table of Contents Consume an external web service in a nutshell .................................................................................................3 Assumption ..................................................................................................................................................... 3 Create Consumer Proxy.................................................................................................................................. 3 Next step is to create a logical port ................................................................................................................. 6 ABAP Coding .................................................................................................................................................. 8 Related Content ................................................................................................................................................ 10 Copyright........................................................................................................................................................... 11
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
Consume an External Web Service in a Nutshell with good old ABAP
Consume an external web service in a nutshell Goal of this instruction is to demonstrate how easy it is to consume an external web service with ABAP. This example is based on an external web service which provides quotes for stocks. Anyway, this is just an example and basically any web service which is described via WSDL (Web Service Description Language) can be used. This example will retrieve the actual quote for the SAP share. Step by step the necessary proceedings to use an external web service are described. Assumption Make sure, that the proxy configuration is ok. Otherwise, you won’t have a chance to connect to an external web service. The proxy settings can be found in SM59:
Create Consumer Proxy At first you have to generate a consumer proxy. A proxy class will be generated, which will be instantiated later on in the report. Generation can be triggered out of SE80:
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
Consume an External Web Service in a Nutshell with good old ABAP
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
Consume an External Web Service in a Nutshell with good old ABAP
In the following dialogue you have to input the WSDL, in order that the proxy settings can be retrieved automatically:
The following screenshot display the consumer proxy. For our example, the default settings are o.k.
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
Consume an External Web Service in a Nutshell with good old ABAP
Next step is to create a logical port The logical port is necessary to call the external web service. You create the logical port with transaction SOAMANAGER. Within SOAMANAGER you have to go for the Single Service Administration:
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
Consume an External Web Service in a Nutshell with good old ABAP
Within SOAMANAGER you have to select the respective web service:
After applying the selection, you just push the button for creation of logical port and use the default setting. Be sure to input the correct URL for the WSDL into the creation dialogue and write down the logical port name. This will be used in your ABAP coding. Also make sure, that the proxy settings are entered:
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
Consume an External Web Service in a Nutshell with good old ABAP
ABAP Coding The following sample coding consumes the external web service. It uses the created consumer proxy and the logical port to request the quote for the symbol SAP. After successful calling, the structure out keeps the actual values for the SAP stock. REPORT
ZZ_GET_QUOTE.
DATA: LV_QUOTE IN OUT oref text
TYPE TYPE TYPE TYPE TYPE
REF TO CO_TEST2_QUOTESTOCK_QUOTE_SOAP, TEST2_QUOTEGET_QUOTE_SOAP_IN, TEST2_QUOTEGET_QUOTE_SOAP_OUT, REF TO cx_root, string.
*http://www.webservicex.net/stockquote.asmx?WSDL TRY. CREATE OBJECT LV_QUOTE EXPORTING LOGICAL_PORT_NAME = 'TESTPORT'. CATCH CX_AI_SYSTEM_FAULT into oref. text = oref->get_text( ). ENDTRY. IF NOT text IS INITIAL. WRITE / text. ENDIF. *Fill request with to be retrieved stock symbol in-symbol = 'SAP'. *Get stock quote TRY. CALL METHOD LV_QUOTE->GET_QUOTE EXPORTING
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
Consume an External Web Service in a Nutshell with good old ABAP
INPUT = in IMPORTING OUTPUT = out. CATCH CX_AI_SYSTEM_FAULT into oref. text = oref->get_text( ). CATCH CX_AI_APPLICATION_FAULT into oref. text = oref->get_text( ). ENDTRY. IF NOT text IS INITIAL. WRITE / text. ELSE. WRITE out-get_quote_result. ENDIF.
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
Consume an External Web Service in a Nutshell with good old ABAP
Related Content ESR Demo Error in Webservice Call HTTP Error Note 1327511 - Limitations and common problems in ABAP WSDL processing How to consume enterprise services with Ruby on Rails
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
Consume an External Web Service in a Nutshell with good old ABAP
Copyright © Copyright 2011 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
SAP COMMUNITY NETWORK © 2011 SAP AG
SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
View more...
Comments