建模静态和动态功能控制
ABAP RESTful 应用程序编程模型 › 开发 › 开发应用程序 › 开发托管事务应用 › 开发业务逻辑 › 添加静态和动态功能控制 › 建模静态和动态功能控制
静态和动态功能控制均针对行为定义中的不同级别(实体、字段或操作级别)定义。
有关字段特征的描述,请参阅 CDS BDL - 字段特征、映射 BDEF(ABAP 关键字文档)。
有关动态功能控制的描述,请参阅 CDS BDL - 功能控制(ABAP 关键字文档)。
将功能控制添加到行为定义 /DMO/I_Travel_M
与以下编码相对应,将静态和动态功能控件添加到行为定义中的每个实体。
展开以下代码示例以查看定义 /DMO/I_Travel_M 行为的源代码。
示例代码
define behavior for /DMO/I_Travel_M alias travel
implementation in class /DMO/BP_TRAVEL_M unique
etag master last_changed_at
...
{
// 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, customer_id, begin_date, end_date, overall_status, booking_fee, currency_code;
// Semantic Key field, which is readonly for the consumer, value is assigned in early numbering
field ( readonly ) travel_id;
// dynamic action control
action ( features: instance ) acceptTravel result [1] $self;
action ( features: instance ) rejectTravel result [1] $self;
// dynamic operation control
association _Booking { create (features:instance); }
...
}
define behavior for /DMO/I_Booking_M alias booking
implementation in class /DMO/BP_BOOKING_M unique
etag master last_changed_at
...
{
// administrative fields: read only
field ( readonly ) last_changed_at;
// static field control
field ( mandatory ) carrier_id, connection_id, flight_date, booking_status;
field ( readonly ) travel_id, booking_id;
// Fields that are mandatory for create but should be read-only afterwards
field ( mandatory : create, readonly : update) booking_date, customer_id;
// dynamic operation control
association _BookSupplement { create (features:instance); }
...
}
define behavior for /DMO/I_BookSuppl_M alias booksuppl
implementation in class /DMO/BP_BOOKINGSUPPLEMENT_M unique
...
{
// administrative fields: read only
field ( readonly ) last_changed_at;
// static field control
field ( mandatory ) price,supplement_id;
field ( readonly ) travel_id, booking_id, booking_supplement_id;
...
}
对于差旅实体,我们将所有管理字段定义为只读,而创建差旅实例所需的字段定义为必填字段。
关键字段 travel_id 也设置为 readonly,因为该值由早期编号确定。业务对象的使用者不能手动设置差旅标识。对于子实体的其他键值字段和一些其他预订特定字段也是如此。这种字段控制是静态的,这意味着它不必在相应的功能控制实施中实施。
对于 ETag 字段,作为专用管理字段,建议您将相应字段指定为只读。
动态操作控制的示例包括两种方法:acceptTravel 和 rejectTravel。根据状态值(overall_status),可以启用或禁用这些操作。
通过关联创建预订是动态控制的。仅当未拒绝相应差旅实例的 overall_status 时才能创建新预订。
来源:SAP Help Portal · 2025 FPS02 (Oct 2026) · 中文为 SAP 官方机器翻译
← 添加静态和动态功能控制 · 实施动态功能控制 →