Sub topic 8
Released objects and the ABAP restrictions for key users
This chapter assumes you can navigate the SAP Fiori launchpad and have created a custom field in the Custom Fields and Logic app. You should also be able to read basic SQL or ABAP. Here you learn which objects your custom logic may use, and why the editor rejects the rest.
Why key user ABAP is restricted
Key user custom logic runs inside standard SAP processes. If your code called any internal function module or read any internal table, an upgrade could change or remove that object and break your extension. To prevent this, SAP limits key user logic to a restricted ABAP language version, often called ABAP for Cloud Development. You can only use objects that SAP has explicitly released for this purpose.
A released object is a repository object, such as a CDS view, class, interface or data element, that SAP has marked with a stable contract for customers. SAP promises not to change that contract in an incompatible way. The mark is called a release contract. Key users work with contract C1, which allows use in key user extensions.
What the restrictions mean in practice
The restricted language version changes what you can write. These are the rules you meet most often:
| Area | Allowed | Not allowed |
|---|---|---|
| Reading data | ABAP SQL on released CDS views | Direct access to database tables such as `MARA` |
| Calling code | Released classes and interfaces | Unreleased function modules, classic reports |
| Statements | Modern ABAP SQL, string expressions | Dynpro, `WRITE` lists, file access, `CALL TRANSACTION` |
| Data types | Released data elements and types | Unreleased DDIC types |
Your own custom fields are also usable. After you publish a field, the system makes it available in the logic editor and in released CDS views that are extended with it.
Reading data through a released CDS view
The example below reads the product type from the released CDS view I_Product. Notice that it queries the view, not the table behind it. It uses the @ escape on every host variable, which is required in modern ABAP SQL.
" 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.Always test sy-subrc after SELECT SINGLE. If the product does not exist, the target variable stays empty and your logic would continue with a blank value.
Finding out what is released
Do not guess. Check the release state before you write the code.
- In ABAP Development Tools, open the object and read its API State in the properties. Look for "Use in Key User Apps" or contract C1.
- In the SAP Fiori launchpad, use the Released Objects app (where available in your release) to search by name.
- In the Custom Fields and Logic app, run the syntax check. It names each unreleased object it finds.
If you cannot find a released object for your need, you have two options. Look for a released successor, which SAP lists in the object's documentation. Or move the requirement to a custom CDS view or to developer extensibility, which later chapters cover.
Common errors
- "... is not released" or "not visible in this language version." You used a table, class or view that has no C1 contract. Replace it with a released CDS view.
- Your custom field is not found in the select list. The field is not published yet, or the CDS view it extends is not part of the field's business context.
- Logic works in the test system but not after transport. The target system lacks the published field or a required view. Transport the field first.
Exercise
A colleague writes SELECT SINGLE matkl FROM mara WHERE matnr = @lv_product INTO @lv_group. in key user custom logic, and the syntax check fails. Why does it fail, and what should the colleague do?
Show answer
MARA is a database table with no release contract for key users, so the restricted ABAP version rejects direct access to it. The colleague should find a released CDS view that exposes the product group, such as I_Product, check its release state, and select from that view instead.
Exercise
Which two places can you check to confirm that an object is released for key user use?
Show answer
The API State in the object's properties in ABAP Development Tools, and the Released Objects app in the SAP Fiori launchpad. The syntax check in the Custom Fields and Logic app also reports unreleased objects.