Sub topic 10
Custom CDS Views and Custom Business Objects
This chapter assumes you have created and published a custom field, and that you know the released-objects rule from the previous chapters. It also assumes you can read basic SQL. Here you will see two more key user tools: custom CDS views for reading data, and custom business objects for storing your own data.
Where these tools fit
A custom field adds one value to an existing standard object. Sometimes that is not enough. You may need a report that joins several tables, or a small data model that SAP does not provide. Key user extensibility covers both needs:
- A custom CDS view is a read-only data model you define on top of released objects. Reports, analytical apps and other logic can read from it.
- A custom business object is a data model you own. The system creates the database table and the services for it, so you can store and maintain your own records.
Both stay inside the clean core rules. They use only released objects, and they do not change standard code.
Custom CDS views
A CDS (Core Data Services) view describes a data selection in a declarative way. In key user extensibility you create one in the Custom CDS Views app. The view must follow these rules:
- The data source must be a released CDS view, such as
I_Product. - You choose the fields to expose and may add joins and simple associations.
- You can include published custom fields, which are available in the released views for their business context.
- After you publish the view, other tools can use it. A reporting scenario might be a query built on it.
The read pattern is the same one you used in custom logic. Your logic reads only through released objects, with escaped host variables:
" Read data through a released CDS view, as allowed in key user custom logic.
DATA lv_product TYPE matnr VALUE 'TG11'.
DATA lv_product_type TYPE I_Product-ProductType.
SELECT SINGLE ProductType
FROM I_Product
WHERE Product = @lv_product
INTO @lv_product_type.
IF sy-subrc <> 0.
" No product found: handle the case here, for example by raising a message.
ENDIF.If you publish a custom CDS view, custom logic can read from it the same way, because it is built only from released parts. Custom fields keep the YY1_ prefix wherever they appear:
Custom field ID pattern: YY1_<FieldName>_<suffix>
Example: YY1_CostCenterNote_PRD
The YY1_ prefix marks key user extensions. The suffix is generated by the system from the business context.Custom business objects
Use a custom business object when you need to store data that does not belong to any standard object. Examples are a list of approved suppliers per plant, or a log of manual approvals. You create it in the Custom Business Objects app.
You define:
- The name and the fields of the object, each with a data type such as text, number, date or amount.
- The key, which identifies each record.
- Whether the object has a UI, so users can maintain records in a generated app.
- Whether it has a service, so other tools can read and write the records.
When you publish, the system generates the database table and the access layer. You do not write table definitions or transport tables by hand.
Choosing between the tools
| Need | Tool |
|---|---|
| One extra value on a standard document | Custom field |
| A report joining released views | Custom CDS view |
| Your own records with maintenance UI | Custom business object |
| Change behavior during a standard process | Custom logic with a BAdI |
Common errors
- Using a non-released source. The editor rejects the view or object if the source is not released. Pick the released successor instead.
- Forgetting to publish a custom field first. A custom CDS view cannot expose a field that is not yet published for its context.
- Treating a business object as a copy of standard data. Store only the data you own. Read standard data through released views when you need it.
Exercise
A team needs to store a list of approved suppliers per plant, with a maintenance app for buyers. No standard object holds this data. Which tool fits, and why can you not use a custom field?
Show answer
A custom business object fits, because it creates its own table, a maintenance UI and a service. A custom field only adds one value to an existing standard object, so it cannot hold a separate list of records.
Exercise
What kind of source objects may a custom CDS view use in key user extensibility?
Show answer
Only released objects, such as the released CDS view I_Product. Non-released sources are rejected, which keeps the extension upgrade stable.