当前位置:网站首页>1. Create SAP OData project in SAP ABAP transaction code segw
1. Create SAP OData project in SAP ABAP transaction code segw
2022-07-16 08:37:00 【Wang Zixi】
Start with this article , We step out and use the thing code SEGW Development OData The first step of service .
We will develop a library management (Book Management) Of OData service , First, create a model of the book entity , That is to say ABAP Dictionary, Things code SE11 Create a ABAP structure (Structure), named ZTS_BOOK.
The following figure shows the thing code SE11 The interface of :
Create a new one Structure:

We first create a key That is, the primary key field , Field called BOOK_GUID, Type words , choice ABAP Self contained RAW type . In order to input this ABAP Standard type , Let's order Built-in Type, And then in turn Data Type and Length Field maintenance RAW and 16:

Maintain other fields in turn :
- BOOK_ID: Recording books ID, The type is CHAR, The length is 4 Characters .
- BOOK_NAME: Record the name of the book , The type is SSTRING, The length is 20 Characters .
- AUTHOR_ID: The author of the book ID, The type is CHAR, The length is 4 Characters .
- AUTHOR_NAME: The name of the author of the book , The type is SSTRING, The length is 20 Characters .
- STOCK_NUMBER: The number of books in stock , integer .

Then enter the thing code SEGW, Create a new project :

The project name is maintained as ZBOOK_MANAGE, Project Type Maintenance into Service with SAP Annotations, Click on Local Object Can be stored locally $tmp In the development package .

Then we will see these new folders under the project folder :

We're facing Data Model Under the folder Entity Types Right click , Select... From the right-click menu Create.
The purpose of this step is to create OData The entity type of the service model , That is to say SAP What the help document says Entity Type.
because OData It's a protocol , It can be implemented based on many high-level programming languages ,ABAP Is one of them , So take ABAP Realized OData service , Its data model is also based on ABAP DDIC Data structure created in . Next steps , We will put SEGW Created in OData Model Entity Type, Same as ABAP DDIC Structure namely ZTS_BOOK Fields in , Establish a one-to-one mapping relationship .

Entity Type The name of , Maintenance into Book:

Click on * after , You can see the following interface , among ABAP Structure The column below is empty .

Manual input we just SE11 Created in ABAP Structure ZTS_BOOK after , Using shortcut keys Ctrl + S Save changes :

Now, on the left Entity Type Under the folder , There will be one more node :Book

double-click Book Under the folder Properties Folder , The discovery is empty . At this time, we need to maintain manually Book Every field of this entity type .
Click on this. Append Row Button , Create a new blank line :

First of all, it needs to be Entity Type Define a primary key (key): stay Name Manually enter book_guid, hold Is Key Of * In the play , indicate book_guid Property is primary key , And then in Edm Type Field , from F4 help Interior selection Edm.Guid This type .

Next, you need to maintain whether this attribute is supported in OData Service implementation is created , Be modified , Is sorted and whether to allow its value to be Null.

because Edm.Guid The value of type is shaped like this 16 The combination of digits and letters :00163EA720001ED29D9420A624836ED3, So obviously , Once this data format is created , Should not be modified , therefore Updatable Of * Should not be selected . Empathy ,Sortable and Nullable Nor should it be chosen , Because of GUID The sorting is unreasonable ,GUID Nor should it be allowed Null Exists as an initial value .
Filterable Search according to this field , about GUID It's not suitable for .
But the next steps in this tutorial , our OData Service implementation , Will support direct passage OData Create new Book data , therefore Creatable Of * It should be .
Last , It needs to be for this Entity Type attribute field , Choose one from ABAP structure ZTS_BOOK Medium ABAP Field . Or from the F4 Value Help Interior selection BOOK_GUID:

Select and save , give the result as follows :

Repeat the above steps , take ZTS_BOOK Other fields , Also manually maintain one by one until Entity Type Properties Under the folder :

Be careful ,ABAP DDIC Inside CHAR and SSTRING type , stay OData Entity Type The corresponding type in , All for Edm.String.
After property maintenance , Choose ZBOOK_MANAGE project , From the right-click menu , choice Check Consistency, Make sure there is no Error That is, the error message is reported .

Shown above , There are two warning messages (Warning Message):Potential loss of data: EDM type is more restriction. Map instead to the ABAP type ‘CHAR[20]’.
The main idea of these warning messages is , our book_name and author_name, Select the Edm Type The type is Edm.String, Maximum length is 20, We call these two attribute fields , Bound to ABAP structure ZTS_BOOK Of BOOK_NAME and AUTHOR_NAME Field , these two items. ABAP The data types of fields are SSTRING, Because we expect these two fields to be case sensitive . and SEGW It is suggested that we map to the type CHAR 20 Of ABAP Field .
For this warning message , We can ignore .

Check Consistency After finding no errors , From the right-click menu , choice Generate Runtime:

Pop it out Model and Service Definition The dialog . up to now , We just finished OData Model creation , These models are not yet operational , It can't be consumed by the outside world . therefore , We pass the Generate Runtime, Automatic generation OData Implementation class of metadata (MPC, Metadata Provider Class) and OData Service business data providing class (DPC,Data Provider Class):

Click on * after ,SEGW Will be generated automatically MPC,MPC_EXT and DPC,DPC_EXT four ABAP class , On the left Runtime Artifacts You can see it under the folder .

MPC and DPC Implementation source code of , Every time we talk to SEGW The project in , After modification , Click... Again Generate Runtime after , Will be automatically overwritten , Replace it with the present SEGW The source code corresponding to the latest settings . therefore ,MPC and DPC It is not an ideal place for developers to write business logic .
So if we want to be right SEGW Created OData Metadata of the model , Must be in MPC_EXT This ABAP Class .MPC_EXT Class is MPC Subclasses of classes , stay MPC_EXT Code written in , stay Generate Runtime It will not be covered later . Empathy ,OData The business logic of services , It should also be written in DPC_EXT In class , instead of DPC In class .
So far we're done SEGW Model creation , The next step in this tutorial , We'll show you how to build a good OData Model to test .
边栏推荐
- Introduction to word2vec and the application of CNN in natural language
- (手工)【sqli-labs27、27a】报错回显、布尔盲注、过滤后注入
- (2.4)【服务型木马-SlimFTP】介绍、使用
- 左倾堆 - 解析与实现
- Test basis 3
- FreeBSD bNXT Ethernet driver source code reading records.
- Binomial reactor principle and analysis
- 【Renesas RA6M4开发板之I2C(模拟)驱动ssd1306 OLED屏幕】
- 二项堆原理与解析
- How to solve the problem that the computer shared file cannot be opened
猜你喜欢

要么退休,要么转行,要么转管理ps居然俩月没写博客了

mySQL上的应用了解

电脑共享文件打不开要如何解决

想成为硬件工程师,难不?

Wechat classroom reservation of applet completion works applet graduation design (3) background function

Linear table concept

2022 cloud native programming challenge starts! Tutor analysis service grid competition questions

Common dataset format + dataset annotation

基于华为WAC双机VRRP热备份下旁挂三层组网隧道转发模式解决方案

【每日一题】735. 行星碰撞
随机推荐
Summary of some experiences in the process of R & D platform splitting
[Unity] 初探
[play with fpga8 in simple terms ----- metastable]
基于华为WAC双机VRRP热备份下旁挂三层组网隧道转发模式解决方案
Jerry's broadcast linein prompt tone may crash [chapter]
cuDNN神经网络加速库的配置
HJ8 合并表记录 HJ08
EMQX Cloud 更新:新增 Redis 和 JWT 外部认证授权
Small program graduation project of wechat enterprise company (7) Interim inspection report
【历史上的今天】7 月 13 日:数据库之父逝世;苹果公司购买 CUPS 代码;IBM 芯片联盟
HJ9 提取不重复的整数 HJ09
What is fastmixer cash virtual currency encryption mixer?
From the perspective of global value chain, how will JD cloud digital intelligence supply chain affect the future economy?
[unity] preliminary discussion
STM32 realizes nRF24L01 communication
线性表概念
【Renesas RA6M4开发板之按键和LED的GPIO】
浅谈——对技术转型做管理的看法
win10系统如何实现开机启动程序?用shell:startup命令
常见数据集格式+数据集标注