The object that can be used to set a field to read-only in all applications of the RESTful Application Programming model (RAP) is the behaviour definition. The behaviour definition is a CDS artefact that defines the business logic and the UI behaviour of a business object. A business object is a CDS entity that represents a business entity or concept, such as a customer, an order, or a product. The behaviour definition can specify the properties of the fields of a business object, such as whether they are mandatory, read-only, or transient. These properties are valid for all applications that use the business object, such as transactional, analytical, or draft-enabled apps12. For example:
The following code snippet defines a behaviour definition for a business object ZI_PB_APPLICATION. It sets the field APPLICATION to read-only for all applications that use this business object:
define behavior for ZI_PB_APPLICATION { field ( read only ) APPLICATION; … }
You cannot do any of the following:
A. Service definition: A service definition is a CDS artefact that defines the interface and the binding of a service. A service is a CDS entity that exposes the data and the functionality of one or more business objects as OData, InA, or SQL services. A service definition can specify the properties of the fields of a service, such as whether they are filterable, sortable, or aggregatable. However, these properties are only valid for the specific service that uses the business object, not for all applications that use the business object12.
C. Projection view: A projection view is a CDS artefact that defines a view on one or more data sources, such as tables, views, or associations. A projection view can select, rename, or aggregate the fields of the data sources, but it cannot change the properties of the fields, such as whether they are read-only or not. The properties of the fields are inherited from the data sources or the behaviour definitions of the business objects12.
D. Metadata extension: A metadata extension is a CDS artefact that defines additional annotations for a CDS entity, such as a business object, a service, or a projection view. A metadata extension can specify the properties of the fields of a CDS entity for UI or analytical purposes, such as whether they are visible, editable, or hidden. However, these properties are only valid for the specific UI or analytical application that uses the metadata extension, not for all applications that use the CDS entity12.
References: 1: ABAP CDS - Data Definitions - ABAP Keyword Documentation - SAP Online Help 2: ABAP CDS - Behavior Definitions - ABAP Keyword Documentation - SAP Online Help