文章目录
SAP BTP ABAP环境:创建和公开基于cd的数据模型
1.0 遇到报错
1 无法创建ABAP environment instance :
https://answers.sap.com/questions/13005478/scp-abap-trial-service-broker-error.html
2:Can not connect to a SAP BTP Trial ABAP Environment instance
https://blogs.sap.com/2021/06/09/can-not-connect-to-a-sap-btp-trial-abap-environment-instance/
教程: https://developers.sap.com/mission.cp-starter-extensions-abap.html
2.0 创建ABAP
第一步:SAP BTP ABAP Environment: Create and Expose a CDS-Based Data Model
教程: https://developers.sap.com/tutorials/abap-environment-trial-onboarding.html
1.0 Got to Trial Account -> Booster -> Prepare an Account for ABAP Trial–>click start
下载key 文件
如果提示创建子账户
子账户创建完毕
2.0 Open ADT Create ABAP Cloud Project
选择BTP Environment - use key
导入 key
打开浏览器页面
完成后->Finish
第二步:SAP BTP ABAP Environment: Create and Expose a CDS-Based Data Model
参考教程: https://developers.sap.com/tutorials/abap-environment-persistence.html
1.0 Open ADT 在Zlocal 下创建子包
2.0 Create Database
粘贴代码
@EndUserText.label : 'Database for Trial 33191'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table ztlxx_table {
key client : abap.clnt not null;
key mykey : sysuuid_x16 not null;
travel_id : /dmo/travel_id;
agency_id : /dmo/agency_id;
customer_id : /dmo/customer_id;
begin_date : /dmo/begin_date;
end_date : /dmo/end_date;
@Semantics.amount.currencyCode : 'ztlxx_table.currency_code'
booking_fee : /dmo/booking_fee;
@Semantics.amount.currencyCode : 'ztlxx_table.currency_code'
total_price : /dmo/total_price;
currency_code : /dmo/currency_code;
description : /dmo/description;
overall_status : /dmo/overall_status;
created_by : syuname;
created_at : timestampl;
last_changed_by : syuname;
last_changed_at : timestampl;
}
3.0 Create Class
ADT 版本太旧,更新就OK
解决了ADT 问题
CLASS zcl_generate_travel_data_33191 DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_generate_travel_data_33191 IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA itab TYPE TABLE OF ztlxx_table.
* fill internal travel table (itab)
itab = VALUE #(
( mykey = '02D5290E594C1EDA93815057FD946624' travel_id = '00000022' agency_id = '070001' customer_id = '000077' begin_date = '20190624' end_date = '20190628' booking_fee = '60.00' total_price = '750.00' currency_code = 'USD'
description = 'mv' overall_status = 'A' created_by = 'MUSTERMANN' created_at = '20190612133945.5960060' last_changed_by = 'MUSTERFRAU' last_changed_at = '20190702105400.3647680' )
( mykey = '02D5290E594C1EDA93815C50CD7AE62A' travel_id = '00000106' agency_id = '070005' customer_id = '000005' begin_date = '20190613' end_date = '20190716' booking_fee = '17.00' total_price = '650.00' currency_code = 'AFN'
description = 'Enter your comments here' overall_status = 'A' created_by = 'MUSTERMANN' created_at = '20190613111129.2391370' last_changed_by = 'MUSTERMANN' last_changed_at = '20190711140753.1472620' )
( mykey = '02D5290E594C1EDA93858EED2DA2EB0B' travel_id = '00000103' agency_id = '070010' customer_id = '000011' begin_date = '20190610' end_date = '20190714' booking_fee = '17.00' total_price = '800.00' currency_code = 'AFN'
description = 'Enter your comments here' overall_status = 'X' created_by = 'MUSTERFRAU' created_at = '20190613105654.4296640' last_changed_by = 'MUSTERFRAU' last_changed_at = '20190613111041.2251330' )
).
* delete existing entries in the database table
DELETE FROM ztlxx_table.
* insert the new table entries
INSERT ztlxx_table FROM TABLE @itab.
* output the result as a console message
out->write( |{ sy-dbcnt } travel entries inserted successfully!| ).
ENDMETHOD.
ENDCLASS.
第三步: Define and Expose a CDS-Based Travel Data Model
教程
https://developers.sap.com/tutorials/abap-environment-data-model.html
1.0 Define CDS-based travel data model
创建数据定义
编辑如下内容
@EndUserText.label: 'Travel data 33191'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define root view entity ZI_TRAVEL_M_33191
as select from ztlxx_table as Travel
/* Associations */
association [0..1] to /DMO/I_Agency as _Agency on $projection.agency_id = _Agency.AgencyID
association [0..1] to /DMO/I_Customer as _Customer on $projection.customer_id = _Customer.CustomerID
association [0..1] to I_Currency as _Currency on $projection.currency_code = _Currency.Currency
{
key mykey,
travel_id,
agency_id,
customer_id,
begin_date,
end_date,
@Semantics.amount.currencyCode: 'currency_code'
booking_fee,
@Semantics.amount.currencyCode: 'currency_code'
total_price,
currency_code,
overall_status,
description,
/*-- Admin data --*/
@Semantics.user.createdBy: true
created_by,
@Semantics.systemDateTime.createdAt: true
created_at,
@Semantics.user.lastChangedBy: true
last_changed_by,
@Semantics.systemDateTime.lastChangedAt: true
last_changed_at,
/* Public associations */
_Agency,
_Customer,
_Currency
}
2.0 Create projection view for travel
@EndUserText.label: 'Travel projection view - Processor'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@UI: {
headerInfo: { typeName: 'Travel', typeNamePlural: 'Travels', title: { type: #STANDARD, value: 'TravelID' } } }
@Search.searchable: true
define root view entity ZC_TRAVEL_M_33191
as projection on ZI_TRAVEL_M_33191
{
@UI.facet: [ { id: 'Travel',
purpose: #STANDARD,
type: #IDENTIFICATION_REFERENCE,
label: 'Travel',
position: 10 } ]
@UI.hidden: true
key mykey as TravelUUID,
@UI: {
lineItem: [ { position: 10, importance: #HIGH } ],
identification: [ { position: 10, label: 'Travel ID [1,...,99999999]' } ] }
@Search.defaultSearchElement: true
travel_id as TravelID,
@UI: {
lineItem: [ { position: 20, importance: #HIGH } ],
identification: [ { position: 20 } ],
selectionField: [ { position: 20 } ] }
@Consumption.valueHelpDefinition: [{ entity : {name: '/DMO/I_Agency', element: 'AgencyID' } }]
@ObjectModel.text.element: ['AgencyName'] ----meaning?
@Search.defaultSearchElement: true
agency_id as AgencyID,
_Agency.Name as AgencyName,
@UI: {
lineItem: [ { position: 30, importance: #HIGH } ],
identification: [ { position: 30 } ],
selectionField: [ { position: 30 } ] }
@Consumption.valueHelpDefinition: [{ entity : {name: '/DMO/I_Customer', element: 'CustomerID' } }]
@ObjectModel.text.element: ['CustomerName']
@Search.defaultSearchElement: true
customer_id as CustomerID,
@UI.hidden: true
_Customer.LastName as CustomerName,
@UI: {
lineItem: [ { position: 40, importance: #MEDIUM } ],
identification: [ { position: 40 } ] }
begin_date as BeginDate,
@UI: {
lineItem: [ { position: 41, importance: #MEDIUM } ],
identification: [ { position: 41 } ] }
end_date as EndDate,
@UI: {
lineItem: [ { position: 50, importance: #MEDIUM } ],
identification: [ { position: 50, label: 'Total Price' } ] }
@Semantics.amount.currencyCode: 'CurrencyCode'
total_price as TotalPrice,
@Consumption.valueHelpDefinition: [{entity: {name: 'I_Currency', element: 'Currency' }}]
currency_code as CurrencyCode,
@UI: {
lineItem: [ { position: 60, importance: #HIGH },
{ type: #FOR_ACTION, dataAction: 'acceptTravel', label: 'Accept Travel' } ],
identification: [ { position: 60, label: 'Status [O(Open)|A(Accepted)|X(Canceled)]' } ] }
overall_status as TravelStatus,
@UI.identification: [ { position: 70, label: 'Remarks' } ]
description as Description,
@UI.hidden: true
last_changed_at as LastChangedAt
}
3.0 Create service definition
ZC_TRAVEL_M_33191
Service definition for travel
@EndUserText.label: 'Service definition for travel'
define service ZUI_C_TRAVEL_M_33191 {
expose ZC_TRAVEL_M_33191 as TravelProcessor;
expose /DMO/I_Customer as Passenger;
expose /DMO/I_Agency as TravelAgency;
expose /DMO/I_Airport as Airport;
expose I_Currency as Currency;
expose I_Country as Country;
}
4.0 Create service binding
点击激活,然后发布
第四步:Create Behavior Definition for Managed Scenario
1.0 Create behavior definition
直接next–Finish
managed implementation in class zbp_i_travel_m_33191 unique;
strict ( 1 );
define behavior for ZI_TRAVEL_M_33191 //alias <alias_name>
persistent table ztlxx_table
lock master
authorization master ( instance )
//etag master <field_name>
{
// semantic key is calculated in a determination
field ( readonly ) travel_id;
// administrative fields (read only)
field ( readonly ) last_changed_at, last_changed_by, created_at, created_by;
// mandatory fields that are required to create a travel
field ( mandatory ) agency_id, overall_status, booking_fee, currency_code;
// mandatory fields that are required to create a travel
field ( mandatory ) Begin_Date, End_Date, Customer_ID;
// standard operations for travel entity
create;
update;
delete;
}
2.0 Create behavior definition for projection view
3.0 选中 Now switch to your service binding and activate your service binding again.