I am a newbie of CDS view related topic and recently I have to learn it. I will write down here not only the knowledge I learned but also the way how I obtain them via self study ( debugging, or other ABAP tool ). Because it would be quite easy for us to just paste the source code of sample CDS view from other guy’s blog and activate it. The CDS view works. But what have you learned from this simple Ctrl+c and Ctrl+v? For me, I always get used to dig a little bit deeper such as “what has happened in the backend after I click the activate button in ABAP development studio? “.
In this part, I will introduce how to test the OData service generated based on my CDS view via Chrome extension – postman.
Prerequisite
I have created two simple CDS views. They are:
@AbapCatalog.sqlViewName: 'z20160310'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'consume view test '
@ObjectModel: {
type: #CONSUMPTION,
compositionRoot,
semanticKey: ['Actor'],
createEnabled,
deleteEnabled,
updateEnabled
}
define view Zjerrytest20160310 as select from Zjerrytest20160309 {
key Zjerrytest20160309.carrid as Jerryid,
key Zjerrytest20160309.carrname as name,
key Zjerrytest20160309.cityfrom as startLocation,
key Zjerrytest20160309.cityto as target,
key Zjerrytest20160309.connid
}
and
@AbapCatalog.sqlViewName: 'zjerrySQL0309'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'test 233'
@ObjectModel: {
createEnabled,
deleteEnabled,
updateEnabled
}
define view Zjerrytest20160309
as select from spfli association [0..1] to scarr as _scarr
on _scarr.carrid = spfli.carrid {
key spfli.carrid,
key _scarr.carrname,
key spfli.connid,
spfli.cityfrom,
spfli.cityto
}
And create a project in tcode SEGW, import the first CDS view via context menu:
After that the project looks like below:
Generate runtime artifacts and register the odata service via tcode/IWFND/MAINT_SERVICE. Now the odata service is ready for testing.
Metadata test
Of course you can use SAP gateway client to test, however I prefer Chrome extension, postman, which can organize all my test cases in a hierarchical structure like below.
You have several ways to get the url to test metadata retrieve operation. In tcode SEGW, you can get your service name.
Search it in tcode /IWFND/MAINT_SERVICE, click “SAP Gateway Client”,
Change the url as “/sap/opu/odata/sap//?$metadata”, and then trigger request. You should see 200 return code with status OK.
Or you can also use Postman, in this case you have to paste the absolute url with host name and port number, both of which could be found in gateway client response, as marked by the black rectangle above.
Read operation test
The url I am using is: https://:/sap/opu/odata/sap/ZJERRY20160310TRY_SRV/Zjerrytest20160310 The name “Zjerrytest20160310” is the entitySet name which you can find in SEGW.
The read operation works, see the part of response data below. But how does the read operation work under the hood?
We can ensure that the response we see are fetched from the automatically generated database view when CDS view is activated, and we would like to know which exact line of code in ABAP does this job. As introduced in my blog Six kinds of debugging tips to find the source code where the message is raised we can get the answer via tcode ST05.
Switch on SQL trace in your system via tcode ST05, and then perform the read operation again. Once finished, display the trace result with filter Object Name = “030*”. ( Since at this time I am not sure whether data comes from Z20160309 orZ20160310 ).
Only one result is found, and click the button to display ABAP code.
Then we get what we look for. The line 22 does the read operation.
This method CL_SQL_STATEMENT~EXECUTE_QUERY is quite useful and would be used in following chapters of this tutorial as well. Now we can study the callstack in the debugger to know how our request sent in UI is parsed and handled.
Variable lv_sql_statement in line 629 contains the automatically generated SQL statement:
SELECT "Zjerrytest20160310"."JERRYID" AS "JERRYID", "Zjerrytest20160310"."NAME" AS "NAME", "Zjerrytest20160310"."STARTLOCATION" AS "STARTLOCATION", "Zjerrytest20160310"."TARGET" AS "TARGET", "Zjerrytest20160310"."CONNID" AS "CONNID" FROM "Z20160310" AS "Zjerrytest20160310" WHERE "Zjerrytest20160310"."MANDT" = '001' WITH PARAMETERS( 'LOCALE' = 'CASE_INSENSITIVE' )
The response data in ABAP format could be found in the variable et_flat_data in this callstack frame:
Filter operation test
The url I am using is: https://:/sap/opu/odata/sap/ZJERRY20160310TRY_SRV/Zjerrytest20160310?$filter=(Jerryid%20eq’LH’) It means I want only those records which fulfill the condition “Jerryid = LH” are returned.
This time, the automatically generated SQL statement is a little bit different from the one for read operation. Here the “?” acts as a placeholder for parameter, whose value is specified by another variable in line 29.
Once line 22 is executed, the filter operation works as expected.
How to find latest information for a list of SAP annotations from SAP help
Open this url, and go to the list of SAP Annotations from the path displayed below.
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关推荐
SAP提供了多种API和服务来促进与其他系统的交互,其中ODATA(Open Data Protocol)是一种轻量级的数据访问协议,它允许客户端通过RESTful接口访问数据。本文将详细介绍如何使用Java调用SAP ODATA服务,并针对描述中...
在深入探讨SAP UI5 OData开发之前,需要明确几个关键点:SAP UI5是一个前端开发框架,而OData(Open Data Protocol)是一种基于Web的协议,允许创建和消费可查询和可更新的数据服务。SAP Gateway是SAP NetWeaver的一...
本教程将详细介绍以上概念,并通过实际示例指导你完成一个完整的SAP ODATA ABAP开发流程,包括从数据模型设计、服务创建、业务逻辑实现到服务测试的全过程。学习完这个教程,你将具备在SAP环境中构建高效、安全的...
在Java开发中,调用SAP ODATA服务是企业级集成和数据交换的常见场景。在实际操作中,可能会遇到一些挑战,如身份验证、请求方法的使用、跨域问题以及错误处理。以下是对这些知识点的详细说明: 1. **身份验证 (401 ...
在SAP系统中,ODATA是一种基于RESTful协议的Web服务技术,用于提供与后端业务数据的交互接口。本文将详细介绍SAP后台ODATA开发的步骤,供初学者参考。 **一、数据结构** 在SAP ODATA开发中,首先需要定义数据结构,...
#### 一、OData与SAP Fiori的关系 在SAP Fiori环境中,OData(Open Data Protocol)扮演着至关重要的角色。它是一种用于定义构建和消费RESTful API的最佳实践的标准协议。通过使用OData,开发人员能够更加专注于...
SAP ODATA Training Agenda • Session 1: Introduction to SAPUI5 / FIORI (40 mins) ▫ Basic MVC concept: Model, View, Controller ▫ UI5 Control libraries • Session 2: Introduction to SAP Web IDE (20 ...
SAP Process Orchestration The Comprehensive Guide, 2nd Edition SAP流程编制综合指南 1 Introduction to SAP Process Orchestration 1.1 Historical Overview and Evolution 1.1.1 SAP Process Integration ...
1. **服务构建**:SAP Gateway允许开发者创建基于OData的服务,这些服务可以从SAP Business Suite或SAP S/4HANA等后端系统中提取数据。服务定义可以通过ABAP编程模型进行,或者通过GUI工具如SAP Gateway Service ...
而OData(Open Data Protocol)是SAP提供的一种开放的、基于REST(Representational State Transfer)架构的数据访问协议,用于简化数据交换,特别是对于移动设备和Web应用。SAP Gateway则是SAP提供的一个技术框架,...
在本教程中,我们将深入探讨如何开发一个使用SAPUI5和oData访问的数据交互应用程序。SAPUI5是SAP提供的一个强大的JavaScript框架,用于构建企业级的Web应用程序。而oData是一种开放的协议,它允许客户端通过HTTP访问...
OData:开放数据协议(Open Data Protocol,简称OData)是一种描述如何创建和访问Restful服务的OASIS标准。该标准由微软发起,前三个版本1.0、2.0、3.0都是微软开放标准,遵循微软开放规范承诺书(Microsoft Open ...
SAP Gateway是一个技术平台,它为开发人员提供了创建和提供基于OData(Open Data Protocol)的服务的工具。这些服务使得非SAP系统能够通过标准接口,如REST(Representational State Transfer)访问SAP数据。这大大...
SAP OData Training Agenda • Session 1: Introduction to REST (20 mins) • Session 2: Introduction to OData Service (40 mins) • Hands on 1: Build your 1 st OData Service (60 mins) ▫ Transaction: SEGW...
本项目“SAPUI5-OData-V4”是一个专门设计的学习资源,目标是帮助开发者理解和掌握如何在SAPUI5应用中与OData V4模型进行交互。通过这个项目,你可以了解到以下关键知识点: 1. **OData V4模型**:与V2相比,V4模型...
sap press doc 解压密码:abap_developer
SAP Fiori 是 SAP 软件和应用程序的新用户体验(UX),提供了一组应用程序,用于常规业务功能,如工作批准,金融应用程序,计算应用程序和各种自助服务应用程序。SAP Fiori 提供了 300 多个基于角色的应用程序,如...
SapAPI 该程序正在读取SAP API。 此API从防火墙后面的SAP ECC系统公开ODATA。 需要一个天蓝色的AD帐户,一个SAP-id,包括访问SAP系统中技术角色的权限。 SAP API已在Azure API管理中注册。
在这个"OData简单demo"中,开发者可能创建了一个基于OData V4的Web API服务,目的是为了测试和演示上述这些查询选项的功能。`ODataWebApi`可能是一个包含API控制器和服务配置的项目文件,通过这个项目,开发者可以...
实体集(Entity Set)则代表数据集合,类似于数据库表的概念,一个实体集对应一个实体类型,一个OData服务可以包含多个实体集。 OData服务的实现主要涉及以下几个方面: 1. **Service Implementation**:这是实现...