SAP-CDS+Odata+BOPF 创建与使用介绍,fiori一体化测试
目錄
?一、創建CDS+BOPF暴露給Fiori
?1.1??創建CDS VIEW抽取層VIEW
?1.2 創建CDS 轉換層VIEW( transfer)
1.3?創建CDS 輸出層 VIEW(Consumption)
二、BOPF相關開發測試?
?2.1 BOPF里面ACTION的實現
?2.2 BOPF里面Validations的實現
三、Fiori測試
BOPF是業務對象處理框架(Business Object Processing Framework,以下簡稱BOPF),SAP有很多標準的BOPF,本例主要是使用CDS創建自開發的BOPF
整體的CDS結構一般做三層,類似于BW,分別是抽取層(View),轉換層(Basic),輸出層(Consumption),分別對Basis層和Consumption層搭建BOPF框架,Consumption層暴露給Fiori使用
【前期準備】
- HANA數據源表準備好,本例用SAP的航線表
- Eclipse安裝好,裝好ABAP插件,創建CDS
- WebIDE環境搭建好
?一、創建CDS+BOPF暴露給Fiori
?1.1??創建CDS VIEW抽取層VIEW
@AbapCatalog.sqlViewName: 'ZDDL_P_FLY' @AbapCatalog.compiler.compareFilter: true @AbapCatalog.preserveKey: true @AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: '航班信息抽取層 basis' define view ZZ_P_FLY as select from spfli {key spfli.carrid ,key spfli.connid ,spfli.countryfr ,spfli.cityfrom ,spfli.airpfrom ,spfli.countryto ,spfli.cityto ,spfli.airpto ,spfli.fltime ,spfli.deptime ,spfli.arrtime ,spfli.distance ,spfli.distid ,spfli.fltype ,spfli.period }?1.2 創建CDS 轉換層VIEW( transfer)
? ? ? ?CDS轉換層也是主要的邏輯處理部分,抽取層基本不對數據處理,為轉換層搭建BOPF框架,激活之后就會產生對應的BOPF(T-code:BOBX)?,之后對BOPF這塊詳解
@AbapCatalog.sqlViewName: 'ZDDL_I_FLY' @AbapCatalog.compiler.compareFilter: true @AbapCatalog.preserveKey: true @AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: '航班信息轉換層 transfer'@ObjectModel:{modelCategory: #BUSINESS_OBJECT,compositionRoot: true,representativeKey: ['carrid','connid'],semanticKey: ['carrid','connid'],transactionalProcessingEnabled: true,writeActivePersistence: 'SPFLI',// enable crudcreateEnabled: true,updateEnabled: true,deleteEnabled: true } define view ZZ_I_FLY as select from ZZ_P_FLY {key carrid ,key connid ,countryfr ,cityfrom ,airpfrom ,countryto ,cityto }1.3?創建CDS 輸出層 VIEW(Consumption)
? ? ? ? CDS 輸出層 VIEW指消費層,同樣要搭建BOPF框架,但不會產生BOPF對象,這一層主要是把CDS發布成ODATA服務暴露給Fiori調用
@AbapCatalog.sqlViewName: 'ZDDL_C_FLY' @AbapCatalog.compiler.compareFilter: true @AbapCatalog.preserveKey: true @AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: '航班信息輸出層 consumption'@ObjectModel:{semanticKey: ['carrid','connid'],transactionalProcessingDelegated: true,// enable crudcreateEnabled: true,updateEnabled: true,deleteEnabled: true }@UI.headerInfo: {typeName: 'fly', typeNamePlural: 'fly', title: {value: 'carrid'}}@OData.publish: true define view ZZ_C_FLY as select from ZZ_I_FLY { @UI: {lineItem: [{ type: #FOR_ACTION, position: 1,dataAction: 'BOPF:SET_CITY',label: 'Set CITY_TO' }],identification: [{type: #FOR_ACTION,position: 1,dataAction: 'BOPF:SET_CITY',label: 'Set CITY_TO' }]}key carrid , @UI: { lineItem: [{ position: 20}], identification: [{position: 20}], fieldGroup: [{qualifier: 'Basic'}] } key connid , @UI: { lineItem: [{ position: 30}], identification: [{position: 30}], fieldGroup: [{qualifier: 'Basic'}] } countryfr , @UI: { lineItem: [{ position: 40}], identification: [{position: 40}], fieldGroup: [{qualifier: 'Basic'}] } cityfrom , @UI: { lineItem: [{ position: 50}], identification: [{position: 50}], fieldGroup: [{qualifier: 'Imsg'}] } airpfrom , @UI: { lineItem: [{ position: 60}], identification: [{position: 60}], fieldGroup: [{qualifier: 'Imsg'}] } countryto , @UI: { lineItem: [{ position: 70}], identification: [{position: 70}], fieldGroup: [{qualifier: 'Imsg'}] } //@ObjectModel.readOnly: truecityto }二、BOPF相關開發測試?
以上CDS+BOPF的框架就完成了,接下來是找轉換層生成的BOPF(TCODE:BOBF/BOBX)
?
?2.1 BOPF里面ACTION的實現
method /BOBF/IF_FRW_ACTION~EXECUTE.data(lt_DATA) = value ZTZIFLY( ).DATA: ls_msg TYPE symsg,lv_dummy_msg TYPE string."Read UI clicked sale orderio_read->retrieve(exportingiv_node = is_ctx-node_key " BO Node Nameit_key = it_key " BO Keyimportinget_data = lt_DATA ). " Data Return Structure"Assuming single instance for a actionLOOP AT lt_DATA assigning field-symbol(<fs_DATA>).<fs_DATA>-CITYTO = 'BOPFCIT'."Now update the BO instanceio_modify->update(exportingiv_node = is_ctx-node_key " Nodeiv_key = <fs_DATA>-key " Keyiv_root_key = <fs_DATA>-root_key " NodeIDis_data = ref #( <fs_DATA>-node_data ) " Datait_changed_fields = value #(( ZIF_Z_I_FLY_C=>sc_node_attribute-ZZ_I_FLY-CITYTO ) )).ENDLOOP.IF <fs_DATA>-CARRID = 'AA'. * MESSAGE S000(zyk_cm_bus_plan) WITH 'THIS IS ANOTHER!' INTO lv_dummy_msg. * MOVE-CORRESPONDING sy TO ls_msg. * eo_message->add_message( * EXPORTING * is_msg = ls_msg " Structure of Message Variables * iv_node = is_ctx-node_key " Node Name * iv_key = <fs_DATA>-key " Key ** iv_lifetime = /bobf/cm_frw=>co_lifetime_state * ). * APPEND VALUE #( key = <fs_DATA>-key ) TO et_failed_key .ENDIF.IF eo_message IS BOUND .eo_message = /bobf/cl_frw_factory=>GET_MESSAGE( ) .ENDIF.endmethod.使用(tcode:BOBT)測試ACTION
2.2 BOPF里面Validations的實現
? ?Validations和action類似需要創建實施類,Trigger Action勾選Action就會觸發校驗
2.3 BOPF里面Query的實現
?
三、Fiori測試
??
總結
以上是生活随笔為你收集整理的SAP-CDS+Odata+BOPF 创建与使用介绍,fiori一体化测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OkHttp-get方法
- 下一篇: 地图可视化:零编程,BDP轻松制作动态轨