In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to use the SAP Cloud Application Programming model to develop OData". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Juergen Mueller uses a decision tree to introduce that SAP practitioners with different levels of development skills can choose different levels and combinations of development tools and programming models according to this tree according to their own situation and project needs.
The branch on the right of the above figure shows that if you don't want to abandon the acquired ABAP development skills, you can choose the ABAP programming environment on the SAP cloud platform; on the contrary, if you prefer the technology stacks such as nodejs,Java, then the SAP cloud platform will not let you down: SAP Cloud Application Programming Model (CAP for short) is the best practice recommended by SAP for development on SAP Cloud Platform.
What on earth is SAP Cloud Application Programming Model? SAP official website gives the definition: a set of development languages, development tools and libraries organically integrated framework, providing an efficient, fast, full-stack enterprise-level services and application development means. CAP includes a set of development best practices that allow developers to focus on the development of specific business logic within the application without distracting the implementation of repetitive underlying infrastructure functions.
Look at a specific example, through Cloud Application Programming Model to achieve a simple online bookstore application. Many books are sold in the bookstore (Books). Each book contains four fields: ID, name, author (Author) and inventory. Users make purchases by creating an order (Orders).
If you use the ABAP technology stack to implement this requirement, an easier way is to use the transaction code SEGW, through the OData protocol to achieve. Create Books,Author and Orders models in SEGW, as well as the corresponding additions, deletions, modifications and queries. Jerry described it in detail in last year's article, the SAP OData programming Guide. Later, with CDS view, you can quickly create an OData service by annotating @ OData.publish on CDS view.
When it comes to the SAP Cloud Platform ABAP programming environment, we have a more useful tool: Restful ABAP Programming Model
Develop a Fiori application supporting additions, deletions, modifications and queries with Restful ABAP Programming model in 30 minutes
Jerry takes you to the second part of the Restful ABAP Programming model series: the implementation of Action and Validation
From the above short description, we can feel the trend that ABAP technology stack has been rapidly evolving with the transformation of SAP to the cloud in recent years.
Let's take a look at how to use SAP CAP to meet the requirements of this online bookstore.
The command line executes the following command:
Npm set @ sap:registry= https://npm.sap.com
Npm I-g @ sap/cds
Download the cds library from SAP's npm repository and install it globally:
Next, type the cds command directly, and if you see the help below, the installation is successful. Since then, all CAP development has revolved around this cds command.
IDE developed by CAP can use Visual Studio Code as well as other text editing tools. The reason for recommending Visual Studio Code is that SAP has released a Visual Studio Code extension for CAP, which supports syntax highlighting and static checking, which can be downloaded from the official website of SAP:
Https://tools.hana.ondemand.com/#cloud
Similar to how we develop a nodejs application, the first step in CAP-based programming is cds init, which automatically creates the skeleton of the CAP application and downloads the necessary library files for the CAP application from http://npm.sap.com.
After the execution of cds init, open Visual Studio Code. The interface is as follows, all of which are automatically generated by cds init:
Create a new srv folder, and create the file cat-service.cds below to complete the modeling of Books,Authors and Orders, that is, define the fields of each model and the jump relationship between models:
Once defined, execute the command cds run, and you can preview the model we just created locally. This command starts a local server and accesses it through http://localhost:4004:
So far, because we haven't implemented the persistence layer of this model, we haven't seen any data yet.
Before implementing the persistence layer, we can mock some data. Create a new cat-service.js and hard-code some test data in it:
In this way, request Books and Authors again, and you can see the data of mock in the browser:
Let's do the development of the persistence layer. Create a new folder db, and then create a new file data-model.cds to copy the model definition that was previously implemented in cat-service.cds. The managed in line 17 means to entrust the addition, deletion, modification and query of the Orders model to the framework for completion.
At this point, the implementation in cat-service.cds is much cleaner and directly reuses the model defined in the previous step data-model.cds. Notice the @ readonly and @ insertonly annotations here.
In this example, we use SQLite, a lightweight database, to store data. Install SQLite with the command line npm I sqlite3-D, and then deploy the database:
Cds deploy-to sqlite:db/my-bookshop.db
According to the output prompt of the cds deploy command, package.json is updated accordingly:
As mentioned earlier, the Books and Authors models have @ readonly annotations, so we create two new csv files and maintain some data in the file:
Then import the two csv files into the database with the command cds deploy.
Log in to the sqlite console and use the select statement to view the data successfully imported from the csv file:
The annotation for Orders mentioned earlier is @ insertonly, and now we want to implement a new feature that reduces the inventory of a book by one per order.
There are only 12 copies of Biohazard at present:
Open the cat-service.js where the mock data was previously stored, and reduce the inventory by one in the hook before placing the order:
Then test: execute the post request in postman, place an order and buy another copy:
At this point, the get request was executed again, and it was found that the inventory of "biochemical Evil" had been deducted as expected:
That's all for "how to use the SAP Cloud Application Programming model to develop OData". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.