Hi Everyone,
In this blog post, I will walk you through the process of creating a SOAP-based web service in SAP S/4HANA, and demonstrate how to configure and expose it using SOAMANAGER for consumption by external systems.
What is SOAP API ?
SOAP API stands for Simple Object Access Protocol.
It is a protocol-based method of communication that allows different systems to exchange data over a network — usually using XML messages over HTTP or HTTPS.
Difference Between SOAP API and Rest API
Feature / Aspect SOAP API (in SAP) REST API (in SAP)
TechnologyWeb Service (Enterprise Service, Function Module via SOAMANAGER)OData service via SAP Gateway (or RAP in S/4HANA)Tool UsedSPROXY,SOAMANAGER, SE37SAP Gateway, SEGW, CDS Views, RAP Model.Data FormatXML onlyMostly JSON (also supports XML)Typical Use CaseIntegration with legacy systems, middleware, PI/POFiori apps, mobile apps, third-party REST integrationsSecurityWS-Security, SAML, SSLHTTPS, OAuth 2.0, SAMLPerformanceHeavier (due to XML parsing and SOAP envelope)Faster and lighter (especially with JSON)Contract DescriptionWSDL file.$metadata (EDMX format) via OData.Preferred InECC or S/4 for BAPIs, ALE, PI/PO scenarios.S/4HANA, Fiori Elements, RESTful integrations.
Step 1:Create a Structure & Table Type for Request and Response.
Objects with the naming convention ZCH* are designed to be transported across all systems (DEV → QA → PROD).
In contrast, objects with the naming convention YCH* are typically created only for development purposes and are stored in the $TMP package, meaning they are local objects and will not be transported. These may be deleted later.
YCH_CUST_REQ is the request structure.
We need to save in $TMP.
YCH_CUST_REQ_TT is the table type which is consuming YCH_CUST_REQ structure
We are storing the request table type in $TMP
YCH_CUST_RES_S is the Response Payload and stored in the $tmp package
Table type YCH_CUST_RES_TT is the table type & it is consuming YCH_CUST_RES_S and stored in $TMP package.
Step2) Creating RFC FM and saved in $TMP Package
So here we are declaring IM_REQUEST as Import parameter with type of Table Type of Request (YCH_CUST_REQ_TT)
So here we are declaring EX_RESPONSE as Export parameter with type of Table Type of Request (YCH_CUST_RES_TT)
There will be no logic written inside the function module only Importing and exporting parameter will be defined
Step 3)Creation of Web service
We need to go for Utilities ->More Utilities->Create web service->From the function Module.
Provide the service definition name and Description
By Default it will take Function module name
By Default it will assign SOAP Appl & Profile
Click on local object check box so that by default it will be assigned to $TMP package
Click on finish to create web service
What is WSDL ?
It is an XML-based language used to describe web services and how to access them. Think of it as a contract between the service provider and the consumer, detailing what the service does, where it can be accessed, and how to interact with it.
Once after that go to WSDL tab and Click on export symbol and download the data in Notepad
So in the WSDL file change the filed type from “tns:char10” to “xsd: String” as below in the downloaded Notepad from WSDL tab.
Step 4) Go to Sproxy tcode
Click on New icon to create Service Consumer.
Select the service Consumer radio button
Select External/WSDL schema.
Chose local file
Choose the local file path for the WSDL.
Provide the package with workbench task request & provide the prefix so that we will taken as reference to create a SOAP class.
click on finish
Save the Service Consumer YSRV_SRV_DEF
Change the Release status from Not Released to Released state and Activate the Service Consumer.
So in the External View Tab we can see all Request and Response Fields.
Soap Class ZCH_CL_CO_YSRV_SRV_DEF will be generated automatically which is helpful in sending and receiving the data using the method YCUST_SOAP_API
Step 5) Execute SOAMANAGER Tcode.
An web page will be opened
Select Web service Configuration
Search our proxy(YSRV_SRV_DEF) in Object type as showed below
We will get the SOAP Class click on that & go for Create -> Manual Configuration
Provide the Logical Port name & description. Click on next
So in Consumer Security Provide the User Id & Password that will be Provided from CPI team (Middleware/Integration Team).
Assign the Endpoint URL which will be Provided from CPI team (Middleware/Integration Team). which will be linked to CPI system.
Change the Message ID protocol to Suppress ID transfer and click on finish.
Once after finishing the soamanger configuration click on the below highlighted icon for Ping the web service.
By pinging the SOAMANGER web service we can Validate our Endpoint, Username & Password.
If it’s Successful then we will get the result as below else we will get error.
Step 6)Create a report program that consumes a SOAP API to send and receive data.
REPORT zcv_r_soap_api.
DATA:ls_req TYPE zch_cl_soap_ycust_soap_api,
ls_res TYPE zch_cl_soap_ycust_soap_apiresp.
SELECT FROM kna1 FIELDS kunnr,name1 INTO TABLE (gt_cust).
LOOP AT gt_cust INTO DATA(ls_cust).
APPEND VALUE zch_cl_ych_cust_req( customer = ls_cust-kunnr name = ls_cust-name1 ) TO ls_req-im_request-item.
ENDLOOP.
DATA(go_ref) = NEW zch_cl_co_ysrv_srv_def( ).
TRY.
go_ref->ycust_soap_api(
EXPORTING
input = ls_req
IMPORTING
output = ls_res
).
CATCH cx_ai_system_fault INTO DATA(ls_error). ” Communication Error
MESSAGE ls_error->get_text( ) TYPE ‘E’.
ENDTRY.
In the above report program, ZCH_CL_SOAP_YCUST_SOAP_API and ZCH_CL_SOAP_YCUST_SOAP_APIRESP are automatically generated structures from the proxy class ZCH_CL_CO_YSRV_SRV_DEF, and are defined as the exporting and importing parameters, respectively, for the method YCUST_SOAP_API.
In the report, I am using the statement APPEND VALUE ZCH_CL_YCH_CUST_REQ at line 8. Here, ZCH_CL_YCH_CUST_REQ is a deep structure that is part of the structure ZCH_CL_SOAP_YCUST_SOAP_API, which was generated by the proxy class.
Later, we created an object of the class ZCH_CL_CO_YSRV_SRV_DEF, through which we called the method YCUST_SOAP_API. The request data is passed in the structure ls_req, and the response is received in the structure ls_res.
Any errors related to the proxy call will be handled in the CATCH block using ABAP’s TRY…CATCH exception handling mechanism.
Hi Everyone,In this blog post, I will walk you through the process of creating a SOAP-based web service in SAP S/4HANA, and demonstrate how to configure and expose it using SOAMANAGER for consumption by external systems.What is SOAP API ?SOAP API stands for Simple Object Access Protocol.It is a protocol-based method of communication that allows different systems to exchange data over a network — usually using XML messages over HTTP or HTTPS.Difference Between SOAP API and Rest APIFeature / Aspect SOAP API (in SAP) REST API (in SAP)TechnologyWeb Service (Enterprise Service, Function Module via SOAMANAGER)OData service via SAP Gateway (or RAP in S/4HANA)Tool UsedSPROXY,SOAMANAGER, SE37SAP Gateway, SEGW, CDS Views, RAP Model.Data FormatXML onlyMostly JSON (also supports XML)Typical Use CaseIntegration with legacy systems, middleware, PI/POFiori apps, mobile apps, third-party REST integrationsSecurityWS-Security, SAML, SSLHTTPS, OAuth 2.0, SAMLPerformanceHeavier (due to XML parsing and SOAP envelope)Faster and lighter (especially with JSON)Contract DescriptionWSDL file.$metadata (EDMX format) via OData.Preferred InECC or S/4 for BAPIs, ALE, PI/PO scenarios.S/4HANA, Fiori Elements, RESTful integrations.Step 1:Create a Structure & Table Type for Request and Response.Objects with the naming convention ZCH* are designed to be transported across all systems (DEV → QA → PROD).In contrast, objects with the naming convention YCH* are typically created only for development purposes and are stored in the $TMP package, meaning they are local objects and will not be transported. These may be deleted later.YCH_CUST_REQ is the request structure.We need to save in $TMP.YCH_CUST_REQ_TT is the table type which is consuming YCH_CUST_REQ structureWe are storing the request table type in $TMPYCH_CUST_RES_S is the Response Payload and stored in the $tmp packageTable type YCH_CUST_RES_TT is the table type & it is consuming YCH_CUST_RES_S and stored in $TMP package. Step2) Creating RFC FM and saved in $TMP PackageSo here we are declaring IM_REQUEST as Import parameter with type of Table Type of Request (YCH_CUST_REQ_TT)So here we are declaring EX_RESPONSE as Export parameter with type of Table Type of Request (YCH_CUST_RES_TT)There will be no logic written inside the function module only Importing and exporting parameter will be definedStep 3)Creation of Web serviceWe need to go for Utilities ->More Utilities->Create web service->From the function Module.Provide the service definition name and DescriptionBy Default it will take Function module nameBy Default it will assign SOAP Appl & ProfileClick on local object check box so that by default it will be assigned to $TMP packageClick on finish to create web serviceWhat is WSDL ?It is an XML-based language used to describe web services and how to access them. Think of it as a contract between the service provider and the consumer, detailing what the service does, where it can be accessed, and how to interact with it.Once after that go to WSDL tab and Click on export symbol and download the data in NotepadSo in the WSDL file change the filed type from “tns:char10” to “xsd: String” as below in the downloaded Notepad from WSDL tab. Step 4) Go to Sproxy tcodeClick on New icon to create Service Consumer.Select the service Consumer radio buttonSelect External/WSDL schema.Chose local fileChoose the local file path for the WSDL.Provide the package with workbench task request & provide the prefix so that we will taken as reference to create a SOAP class.click on finishSave the Service Consumer YSRV_SRV_DEFChange the Release status from Not Released to Released state and Activate the Service Consumer.So in the External View Tab we can see all Request and Response Fields.Soap Class ZCH_CL_CO_YSRV_SRV_DEF will be generated automatically which is helpful in sending and receiving the data using the method YCUST_SOAP_APIStep 5) Execute SOAMANAGER Tcode.An web page will be opened Select Web service ConfigurationSearch our proxy(YSRV_SRV_DEF) in Object type as showed belowWe will get the SOAP Class click on that & go for Create -> Manual ConfigurationProvide the Logical Port name & description. Click on nextSo in Consumer Security Provide the User Id & Password that will be Provided from CPI team (Middleware/Integration Team).Assign the Endpoint URL which will be Provided from CPI team (Middleware/Integration Team). which will be linked to CPI system.Change the Message ID protocol to Suppress ID transfer and click on finish.Once after finishing the soamanger configuration click on the below highlighted icon for Ping the web service.By pinging the SOAMANGER web service we can Validate our Endpoint, Username & Password.If it’s Successful then we will get the result as below else we will get error.Step 6)Create a report program that consumes a SOAP API to send and receive data.REPORT zcv_r_soap_api.
DATA:ls_req TYPE zch_cl_soap_ycust_soap_api,
ls_res TYPE zch_cl_soap_ycust_soap_apiresp.
SELECT FROM kna1 FIELDS kunnr,name1 INTO TABLE (gt_cust).
LOOP AT gt_cust INTO DATA(ls_cust).
APPEND VALUE zch_cl_ych_cust_req( customer = ls_cust-kunnr name = ls_cust-name1 ) TO ls_req-im_request-item.
ENDLOOP.
DATA(go_ref) = NEW zch_cl_co_ysrv_srv_def( ).
TRY.
go_ref->ycust_soap_api(
EXPORTING
input = ls_req
IMPORTING
output = ls_res
).
CATCH cx_ai_system_fault INTO DATA(ls_error). ” Communication Error
MESSAGE ls_error->get_text( ) TYPE ‘E’.
ENDTRY.In the above report program, ZCH_CL_SOAP_YCUST_SOAP_API and ZCH_CL_SOAP_YCUST_SOAP_APIRESP are automatically generated structures from the proxy class ZCH_CL_CO_YSRV_SRV_DEF, and are defined as the exporting and importing parameters, respectively, for the method YCUST_SOAP_API.In the report, I am using the statement APPEND VALUE ZCH_CL_YCH_CUST_REQ at line 8. Here, ZCH_CL_YCH_CUST_REQ is a deep structure that is part of the structure ZCH_CL_SOAP_YCUST_SOAP_API, which was generated by the proxy class.Later, we created an object of the class ZCH_CL_CO_YSRV_SRV_DEF, through which we called the method YCUST_SOAP_API. The request data is passed in the structure ls_req, and the response is received in the structure ls_res.Any errors related to the proxy call will be handled in the CATCH block using ABAP’s TRY…CATCH exception handling mechanism. Read More Technology Blog Posts by Members articles
#SAP
#SAPTechnologyblog