In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
SAP OData programming how to understand, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
The OData (Open Data Protocol) protocol is an open industry standard for defining the design and use of RESTFul API.
At present, OData is widely used in many Fiori applications of SAP Business Suite and SAP S/4HANA, as well as SAP Customer Engagement Center and some new generation cloud products under development. In addition, OData is also a technical means recommended by SAP Cloud for Customer to integrate C4C and customer third-party applications.
OData development in SAP Business Suite
Take SAP CRM as an example. SAP provides a version that can be tried out in the cloud for many Fiori applications, which can be accessed through the following link:
Https://www.sapfioritrial.com/
After clicking the link, you can see in Fiori Launchpad that there are several Tile in the CRM directory, which are developed and maintained by the CRM Fiori development team of SAP Chengdu Research Institute. Click on a Tile, such as My Opportunities:
Then we can see the details page of the application. On the Network tab of the Chrome developer tool, we can observe a request for metadata:
Let's copy the url of this metadata request from the Chrome developer tool, and the full link is as follows:
Https://www.sapfioritrial.com/sap/opu/odata/sap/CRM_OPPORTUNITY/$metadata?sap-language=en&sap-client=001
By visiting the link directly in the browser, you can observe the metadata (metadata) of the OData service named CRM_OPPORTUNITY contained in the link. We can compare the model of an OData service to a SAP Business Object, which also consists of a root node and several child nodes, each containing several fields. Some nodes provide executable logic, which is called function import (equivalent to action in Business Object) in the OData protocol. The relationship between different nodes is established by defining Navigation-SAP modeling methods for different products based on Netweaver are similar, which can be analogous.
Another important request:
Https://www.sapfioritrial.com/sap/opu/odata/sap/CRM_OPPORTUNITY/Opportunities?$skip=0&$top=20&$inlinecount=allpages&sap-client=001
Requested analysis:
$skip=0&$top=20: notifies the backend to perform a paged search, taking only the first 20 records that meet the query criteria from the database and returning them to UI.
$inlinecount=allpages: returns the number of records in the database that meet the search criteria. Because Jerry does not specify search criteria, the total number of Opportunity in the system is returned to 1051.
The following is a brief description of how to develop OData models and services in SAP Business Suite systems.
Before starting development, we need to review the architecture of Fiori.
SAP Fiori applications:
When it comes to Fiori development, as far as this diagram is concerned, it can be summarized into two sentences:
1. Develop OData model and service on ABAP Back-End server
two。 Register the OData service on the ABAP Front-End server so that Fiori applications can consume
First, let's go to the ABAP Back-End server and open the OData service CRM_OPPORTUNITY using the transaction code SEGW. You can see that the Data Model contains many nodes, each node is actually implemented by an ABAP DDIC Structure, and each field on the node corresponds to the field on the Structure. After we have defined which Structure the OData model contains, click the Generate Runtime Objects button on the toolbar:
The SAP Gateway framework automatically generates four ABAP classes and two models based on the OData model we defined.
MPC and MPC_EXT: when a consumer accesses the service's metadata, these two classes are responsible for converting the metadata information described by ABAP DDIC Structure into the format of the OData protocol specification and returning it. Every time a developer modifies the OData model and clicks the Generate button, the MPC code is regenerated. If the developer needs to add some additional information to the model, such as some version control information or related comments (annotation), then it needs to be done through ABAP code in MPC_EXT. MPC_EXT is a subclass of MPC and its code is not overridden by the Generate button. An example is as follows:
DPC and DPC_EXT: contains the implementation of OData services, which is actually the implementation of CRUD operations, search operations and function import based on the OData model. Take Opportunity as an example, because the underlying model uses the CRM One Order model, DPC_EXT contains a large number of CRM_ORDER_* and other function calls, CRM consultants should be very familiar with these functions.
After the ABAP Back-End server completes the OData development, log in to the ABAP Front-End server and use the transaction code / IWFND/MAINT_SERVICE to register the OData service done by the background server.
The following figure shows the registration interface of the OData service with the ABAP Front-End server. From the figure below, you can see that theoretically one ABAP Front-End server can connect to multiple ABAP Back-End servers.
SAP refers to this relationship as Multiple Origin Composition. A typical usage scenario is a multinational company whose application runs on Back-End server 1 in America and Back-End server 2 in Europe. A sales manager uses the Fiori application to view the global sales data of the enterprise over a certain period of time, and its OData implementation collects the background data of the two servers, aggregates them, and returns them to UI.
OData development in S/4HANA
CDS view is an important modeling method in S/4HANA.
Let's look at a concrete example. Suppose you need to develop a Fiori application to manage Service Order in S/4HANA, and the function is tentatively scheduled to support read-only operations on Service Order, that is, query and browse. With S/4HANA 's CDS view modeling technology, doesn't it sound amazing that we can automatically generate a Fiori application that meets the requirements without writing a single line of JavaScript?
We need to create a CDS view that can be used to automatically generate OData models and services, that is, the green Z_C_Service_Order_View shown below. The View takes data from other lower-level CDS view and aggregates the header, line items, status information and other data of the Service Order.
After CDS view is developed, you just need to load it in the transaction code SEGW through Reference- > Data Source:
You can automatically generate the OData model, as well as the two sets of MPC and DPC mentioned in the previous chapter, with a total of four ABAP Class, corresponding to the blue and red areas shown below, respectively, without the need for application developers to write ABAP code.
Then use SAP WebIDE to create a new Fiori application, be careful not to use the normal SAPUI5 Application template, but use the Smart Template Application template. Specify the previously automatically generated OData service based on CDS view in the creation wizard.
Click the wizard's Finish button and eventually get such a Fiori application without writing a single line of JavaScript code:
The source code of CDS view mentioned in the figure above, and how Smart Template works.
Further, if you want to add some features to this automatically generated Fiori application, such as supporting Service Order modification and creation operations.
It is worth mentioning that there is a powerful note in CDS view:
@ OData.publish: true
Like SpringBoot annotations can achieve many magical functions, CDS view defined by this annotation can automatically generate OData models and services without the help of SEGW, further simplifying the configuration that developers need to do OData development, and helping developers to quickly build standardized OData services.
Consumption of OData services
Having said so much about the development of OData models and services, let's talk about how to consume it.
Consume OData services with ABAP code
Take the standard OData service of consuming C4C Opportunity as an example.
First figure out how to use HTTP Post plus the $batch operation of OData to create Opportunity in postman:
In fact, the main task is to implement the whole process of $batch operation in ABAP code. The body requested by $batch is populated with a series of strings for the custom macro operation insert_line in the following code.
Because ABAP Netweaver can be used as both Web Server and Web Client, using ABAP code to consume the RESTFul API of OData is essentially using the SEND and RECEIVE methods of IF_HTTP_CLIENT to send and receive network requests.
Using Java Code + Apache Olingo to consume OData Services
I'm sure most developers don't want to directly manipulate OData $batch body like the following code, which is both troublesome and error-prone.
So in Java you have Apache Olingo, an open source library, which you can think of as the Java SDK of OData, encapsulating the underlying details of OData. Both BatchChangeSet and BatchChangeSetPart that need to be populated in the batch operation are encapsulated in Olingo. Let's see if the following figure uses Java code to call OData services to create ServiceTicket. Compared with the ABAP code in the figure above, is it semantically clearer?
The complete Java code in the figure above
Using UI5 to consume OData services
Detailed API instructions can be found on the official website of SAP UI5.
Jerry only adds two points of original content.
1. Synchronous and asynchronous parameters of UI5 OData API.
The following figure shows the timing of five requests issued in synchronous mode in the Network tab of the Chrome developer tool:
The following figure shows five requests issued in asynchronous mode:
two。 Consume ABAP On-Premise OData services under the CloudFoundry environment of SAP cloud platform
Scenario: consume the OData service of On-Premise system in Wechat.
OData performance test
1. Use the performance testing tools provided by Netweaver
two。 Using JMeter to test the performance metrics of OData services in high concurrency scenarios
In previous customer projects, many customers have put forward this kind of performance testing requirements, such as initiating 1000 Service Request OData creation requests at the same time to measure their average response time.
There are two ways:
(1) write Java code by yourself, use multithreaded programming technology, each thread initiates an OData creation request, and measure the average response time.
(2) use the performance testing artifact JMeter, so that you don't have to write a single line of code.
Explanation of Kapsel OData plugin principle
The Offline (offline) mode of the SAP mobile solution uses Kapsel OData plugin to extract business data from the background system and store it in the local offline storage area of the device.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.