SAP CDS view自學教程之一:如何測試基於SAP CDS view自動生成的OData服務
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 Zjerrytest20160309as select from spfli association [0..1] to scarr as _scarron _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的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2719301/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何基於 SAP CDS view 生成 object pageViewObject
- SAP CDS view自學教程之十:SAP CDS view擴充套件性(Extensibility)實現原理View套件
- SAP CDS view自學教程之二:當SAP CDS view被啟用時,背後發生了什麼View
- SAP CDS view自學教程之八:SAP Fiori Elements裡不同型別的annotationView型別
- 如何使用 SAP CDS view 中的 currency conversion 功能View
- SAP CDS view單元測試框架Test Double介紹View框架
- SAP ABAP CDS view Association 引入的緣由View
- 如何使用SAP HANA Studio的PlanViz分析CDS view效能問題View
- 什麼是SAP CDS重定向檢視(Redirect View)?View
- 在 Excel 內使用 ODBC 消費 SAP ABAP CDS viewExcelView
- 使用CDS view開發SAP Marketing contact的facet追溯工具View
- SAP ABAP CDS view 檢視的 Replacement 技術介紹View
- SAP ABAP CDS view 裡 INNER JOIN 和 Association 的區別View
- 如何在 SAP BTP 上通過 CDS view 快速建立 Fiori Elements 應用View
- 開啟SAP CDS view DCL前後的讀取效能對比View
- SAP ABAP CDS view裡的註解在ABAP後臺是如何被解析的?View
- SAP CDS view如何取得當前系統日期和系統時間戳View時間戳
- 一步步學習 SAP CDS view Text Association 在 SAP Fiori Elements 中的應用View
- 使用SAP CDS view快速建立一個Fiori應用,管理Service OrderView
- SAP S/4HANA CDS View的訪問控制實現:DCL介紹View
- SAP CDS redirect view支援寫操作嗎,一個實驗來驗證View
- 在 Excel 裡使用 ODBC 讀取 SAP BTP 平臺上 CDS view 的資料ExcelView
- 如何用ABAP讀取CDS view association的資料View
- 使用 Excel 讀取 SAP ABAP CDS View 通過 ODBC 暴露出來的資料ExcelView
- 一行程式碼將SAP CDS view資料以ALV的方式輸出行程View
- SAP CDS view 如何將 CHAR 型別的資料欄位和當前系統日期比較View型別
- 如何用ABAP程式碼讀取CDS view association的資料View
- Python 自動化提取基因 CDSPython
- Cannot find package module sap/cds/commonPackage
- SAP ABAP OData 服務如何支援 $orderby (排序)操作試讀版排序
- SAP Cloud Application Programming CDS 模型間 association 的設定CloudAPP模型
- 使用 Postman 工具高效管理和測試 SAP ABAP OData 服務試讀版Postman
- SAP ABAP使用CDS獲取系統資訊
- SAP ABAP OData 服務如何支援 $filter (過濾)操作試讀版Filter
- SAP ABAP OData 服務如何支援建立(Create)操作試讀版
- SAP ABAP OData 服務如何支援刪除(Delete)操作試讀版delete
- SAP Business Application Studio 裡建立一個基於 CAP 模型的 OData 服務APP模型
- 關於 SAP UI5 應用的自動化測試方法UI