Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to consume third-party services in ABAP programming environment

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to consume third-party services in ABAP programming environment". In daily operation, I believe that many people have doubts about how to consume third-party services in ABAP programming environment. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to consume third-party services in ABAP programming environment". Next, please follow the editor to study!

In the ABAP On-Premises environment, using ABAP programming to consume third-party services, I believe many ABAP consultants are already very familiar with nothing more than using CL_HTTP_CLIENT or CL_REST_HTTP_CLIENT to send and receive HTTP requests.

The short 38 lines of code below show how to use the ABAP tool class CL_HTTP_CLIENT to visit Baidu's home page and get a reply.

The response returned from Baidu is obtained by the method GET_CDATA and stored in the variable rv_data:

Of course, if we are doing formal product development, we generally do not hard-code the URL of the third-party service in the application, but manage the endpoint of the third-party service through the Destination created by the transaction code SM59, and then store the Destination name in the configuration table, so that the URL of the third-party service is uncoupled with the application code.

The following figure is an example. I maintain a Destination that points to a C4C system in the SM59 transaction code, named C4C:

Then use cl_http_client= > create_by_destination in the ABAP code to create an instance of the HTTP utility class. The subsequent actions are consistent with the code for constructing the instance using cl_http_client= > create_by_url, and will not be repeated here.

If we directly move the ABAP code from the On-Premises environment to the ABAP environment of SAP Cloud Platform, we will encounter a lot of syntax errors:

The reason is that in Jerry's first article introducing the ABAP programming environment of SAP cloud platform, it has been mentioned in the first ABAP program written on SAP cloud platform ABAP programming environment that the ABAP programming model in the cloud only supports a subset of the ABAP programming language, and we can only use the resources in the open whitelist of SAP, which is the content contained in Released Objects on the left side of the figure above.

Because CL_HTTP_CLIENT, CL_REST_HTTP_CLIENT, IF_HTTP_CLIENT and other ABAP classes and APIs used by Jerry in On-Premises environment are not on the whitelist, it cannot be used in ABAP cloud environment.

Now that we are in the cloud, we have to use the cloud programming paradigm.

Jerry's article last year used Java+SAP Cloud platform + SAP Cloud Connector to call functions in the ABAP On-Premise system. It described how Java applications running on the cloud can call RFC functions in the ABAP On-Premises system through the Destination created on the SAP cloud platform. Today, the programming language of our applications running on the cloud has changed from Java to ABAP, but the idea of using Destination to make third-party service calls remains the same.

Jerry first publishes the correct answer. The code to access the third-party service in the SAP Cloud Platform ABAP programming environment is as follows:

You can see that the idea is to get the Destination instance through CL_HTTP_DESTINATION_PROVIDER, a Destination factory class in the cloud, and then create an ABAP HTTP client instance on the cloud based on that instance. Factory class requires two parameters to produce Destination instances:

I_name

I_service_instance_name

According to the interface comments of this method, these two parameters are the name of Destination and the name of Service instance, respectively. The following Jerry describes how to get the values of these two parameters.

Create a new Destination instance in SAP Cloud Platform Service Marketplace:

We name the newly created instance DestService, and then create a Destination configuration based on that instance, which is like the Destination we created in the SM59 transaction code of ABAP On-Premises:

Destination I named ZJERRY_API, which is the origin of the first parameter iname value in the factory method mentioned earlier.

Click Check Connection to ensure that the URL pointed to by the Destination can be accessed:

Then click Open Dashboard to open the Fiori interface of the SAP Cloud Platform ABAP instance:

Click Launchpad tile to create a new Communication Arrangements:

You need to select a Communication Scenario for the newly created Communication Arrangement. Here, I choose the scenario published by the SAP standard specifically for integrating CloudFoundry environment with third-party services. The ID is SAP_COM_0276:

Also maintain Service Key information when creating a Communication Arrangement:

Information about this Service Key can be obtained from the Service Key maintenance interface of the Destination instance list:

In the created Communication Arrangement, the value of the maintenance Service Instance Name is jerry-service-instance, which is the second parameter passed to the factory method in the ABAP code.

Execute the ABAP class:

Get the desired output:

At this point, the study on "how to consume third-party services in the ABAP programming environment" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 295

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report