使用OData服務將SAP C4C自定義BO的TextCollection暴露給外部消費者
In the last part of my blog Step by step to enable Text Collection for your custom BO I mentioned it is possible to create a web service in Cloud Application studio which contains a read operation, to return the Text Collection data to web service consumer. However the read operation can only support single BO instance ID as operation input parameter – on the other hand query operation does support multiple BO instance ID to fulfill the mass-handling requirement, however unfortunately it is not possible for query created in Cloud studio to directly return the transaction data of Text Collection. As a result we have to seek alternative.
The requirement to return text collection belonging to multiple BO instances could be achieved by C4C OData consisting of two steps.
Suppose I have two Custom BO instances JERRYORDER1 and JERRYORDER2, each has maintained their own Text Collection data:
The definition of my custom BO:
Here below are two necessary steps to return the Text Collection of these two BO instances via custom OData service.
(1) Create a new Custom OData Service in Work center Administrator, view OData Service Explorer, make sure you have selected Dependent object TextCollection:
Get the Object ID of the two BO instances by performing fitlering against their alternative key, in my custom BO the alternative key is MainBOID.
Create a new HTTP Get request in Chrome extension Postman with url:
https:///sap/c4c/odata/cust/v1/jerrylongtextodata/MainBORootCollection?$filter=MainBOID eq 'JERRYORDER1' or MainBOID eq 'JERRYORDER2'
write down the Object ID of these two BO instances from response:
(2) Create a HTTP post request in Postman:
Paste the following text as post body. In the post body, the Object ID of two BO instances fetched from previous step are used as input parameter of two embedded HTTP GET operation contained in the batch request.
--changeset_1Content-Type: application/httpContent-Transfer-Encoding: binaryGET MainBORootCollection('00163E20C9511ED7A9B1B0D65CCCDA81')?$expand=MainBOTextCollection HTTP/1.1Accept-Language: enAccept: application/jsonMaxDataServiceVersion: 2.0DataServiceVersion: 2.0--changeset_1Content-Type: application/httpContent-Transfer-Encoding: binaryGET MainBORootCollection('00163E20C9511ED7A9B19A78790759DE')?$expand=MainBOTextCollection HTTP/1.1Accept-Language: enAccept: application/jsonMaxDataServiceVersion: 2.0DataServiceVersion: 2.0--changeset_1--
Execute this post request in Postman, and the TextCollection for the two BO instances will be returned in a SINGLE roundtrip. Response for BO JERRYORDER2:
Response for BO JERRYORDER1:
Note
(1) If you have too many BO instances for which you would like to query their ObjectID by alternative key for subsequent query operation, it means you have to append a lengthy string like $filter=MainBOID eq ‘JERRYORDER1’ or MainBOID eq ‘JERRYORDER2’ or …. MainBOID eq ‘JERRYORDERN’ as HTTP Get request url. It is possible that the url will exceed the maximum length of a URL for HTTP Get.
In this case you can avoid it by using HTTP Post instead:
HTTP post body for doing filter operation on multiple BO instances:
--changeset_1Content-Type: application/httpContent-Transfer-Encoding: binaryGET MainBORootCollection?$filter=MainBOID%20eq%20%27JERRYORDER1%27 HTTP/1.1Accept-Language: enAccept: application/jsonMaxDataServiceVersion: 2.0DataServiceVersion: 2.0--changeset_1Content-Type: application/httpContent-Transfer-Encoding: binaryGET MainBORootCollection?$filter=MainBOID%20eq%20%27JERRYORDER2%27 HTTP/1.1Accept-Language: enAccept: application/jsonMaxDataServiceVersion: 2.0DataServiceVersion: 2.0--changeset_1--
You will get the same result as using HTTP get with url:
https://<tenant>/sap/c4c/odata/cust/v1/jerrylongtextodata/MainBORootCollection?$filter=MainBOID eq 'JERRYORDER1' or MainBOID eq 'JERRYORDER2'
(2) In case you need to develop a Java Program to achieve the above mentioned two steps, you can find sample code in my blog OData service parallel performance measurement – how to deal with XSRF token in Java Program and JMeter.
Further reading
You can find a list of all other blogs related to OData written by Jerry.
- Consume standard C4C OData service via ABAP code
- Leverage C4C Odata notification to monitor C4C Opportunity change in CRM system
- OData Service backend implementation in C4C, CRM and S4 HANA
- JMeter beginner – how to use JMeter to measure performance of OData service accessed parallelly
- Regarding cookie manipulation in CL_HTTP_CLIENT to avoid CSRF token validation failure issue
- OData service parallel performance measurement – how to deal with XSRF token in Java Program and JMeter
- Expose TextCollection data belonging to a Custom BO via OData service
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2724931/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 將SAP C4C Custom BO使用ABSL編寫的邏輯通過OData服務暴露出去
- 如何使用 ABAP 程式消費 SAP ABAP OData 服務
- 如何自行給指定的SAP OData服務新增自定義日誌記錄功能
- 如何啟用SAP C4C自定義BO的Text Collection功能
- 使用Excel消費C4C的OData serviceExcel
- 如何讓SAP C4C自定義BO實現附件上傳的功能
- 使用 HTTP PUT, PATCH 以及 MERGE 請求消費 SAP ABAP OData 服務修改操作HTTP
- 如何將SAP C4C自定義BO中型別為圖片的附件用PDF文件顯示出來型別
- springcloud之自定義簡易消費服務元件SpringGCCloud元件
- 一種不通過UI給C4C自定義BO建立測試資料的方式UI
- SAP C4C OData服務的filter,客戶端分頁和排序的使用方式Filter客戶端排序
- 使用 SAP UI5 消費 OData 服務的一些常見錯誤和解決方案UI
- 在SAP雲平臺的CloudFoundry環境下消費ABAP On-Premise OData服務CloudREM
- 使用 SAP Cloud SDK 連線 OData 服務Cloud
- 如何處理使用 SAP UI5 消費真實的 OData 服務時遇到的跨域問題UI跨域
- Clickhouse 使用者自定義外部函式函式
- 使用SAP雲平臺的destination消費Internet上的OData service
- 如何使用SAP C4C Repository Explorer裡的BO test shell
- 使用nodejs呼叫C4C的Odata服務建立銷售訂單NodeJS
- 如何使用API的方式消費SAP Commerce Cloud的訂單服務APICloud
- 如何使用 API 的方式消費 SAP Commerce Cloud 的訂單服務APICloud
- 如何使用 ABAP 程式碼消費需要傳遞 CSRF token 的 OData 服務試讀版
- 在 SAP BAS 裡使用 SAP UI5 應用消費 OData 的 Create 和 Delete 操作UIdelete
- 出行服務:消費者視角
- SpringCloud服務消費者-openFeign元件SpringGCCloud元件
- 如何在SAP Cloud for Customer自定義BO中建立訪問控制Cloud
- SAP ABAP OData 服務的 $count 操作實現
- Dubbo服務消費者呼叫過程
- 《springcloud 一》搭建註冊中心,服務提供者,服務消費者SpringGCCloud
- 如何啟用SAP C4C OData Event Notification
- SAP UI5 OData 請求的自定義 HTTP header 設定方法UIHTTPHeader
- SAP ABAP OData 服務診斷工具 /IWFND/ERROR_LOG 的使用方法Error
- SAP Gateway Service Builder 裡的 OData 服務實現方式GatewayUI
- 如何在Android平臺上建立自定義的Cordova外掛並使用SAP UI5消費AndroidUI
- Laravel Exception結合自定義Log服務的使用LaravelException
- 如何給 SAP ABAP SEGW 開發的 OData 服務新增 Access-Control-Allow-Origin 響應頭
- SpringCloud學習之路(四) - 服務消費者(Feign)SpringGCCloud
- 中國銀髮市場:中產消費者對長者服務型消費的態度