Sub topic 8
Released objects and the ABAP restrictions for key users
This chapter explains which repository objects your custom logic may use and why the editor rejects the rest. It assumes you know the Custom Fields and Logic app, have seen a BAdI implementation, and can read basic ABAP SQL. The next chapter, on BAdI implementations, builds on it.
Why key users get a restricted ABAP
Custom logic written in the Custom Logic app runs inside the standard SAP S/4HANA system, in the same process as standard code. A careless statement can slow down a posting, read data the user may not see, or break after an upgrade. SAP limits this risk in two ways:
- A restricted language version. Key user code is written in ABAP for Key Users. This is a subset of ABAP for Cloud Development, which is itself a subset of classic ABAP. Statements that touch the file system, the operating system, or other sessions are not available.
- A closed set of usable objects. Your code may only use objects that SAP has explicitly released for this purpose. Everything else exists in the system but is invisible to your code.
Both rules are checked by the ABAP syntax check. A violation is a compile-time error. It does not fail at run time.
What "released" means
A released object is a repository object (a CDS view, class, interface, data element, BAdI definition, and so on) that SAP has published with a stability promise. SAP agrees to keep its name, signature, and meaning compatible across upgrades. This promise is what keeps your extension upgrade-stable, as described in the clean core chapter.
Each object has a release state for each release contract. The contract tells you what kind of use SAP guarantees:
| Contract | Typical meaning | Relevant to key users |
|---|---|---|
| C0 | You may extend the object, for example add fields to a CDS view | Indirectly |
| C1 | You may use the object in your own development, for example read from a view or call a class | Yes, together with the key user flag |
| C2 | You may use the object as a remote API | No |
An object can be released for use in developer extensibility without being usable in key user apps. Key user code is the more restricted case. The object must be released for both the C1 contract and use in key user apps. Treat these as separate checks:
- Is the object released at all?
- Is it released for use in key user apps?
An unreleased object, or a released one without the key user flag, produces the same kind of error in the editor: the object is unknown or not permitted.
How the check decides
The check runs each time you reference an object. The following diagram shows the logic.
The check has two layers. The first layer asks whether the object may be used. The second asks whether the statement may be used. You can pass the first and still fail the second. For example, you can read a released view legitimately but combine it with an unsupported statement.
Reading data: released CDS views only
The most common task in custom logic is reading business data. In classic ABAP you might SELECT from a table such as MARA. Here that is not allowed, because database tables are internal implementation details that SAP may change in any release. You read through released CDS views instead. These views are the public data model. They keep their field names even if the tables below them change.
" 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.Three details in this example matter:
- The source is a CDS view.
I_Productis a released interface view. Names starting withI_are the stable interface layer. Views starting withC_are consumption views for specific apps and are usually not released for your use. - Host variables are escaped with
@. ABAP SQL in the strict syntax requires@before program variables. This applies tolv_productandlv_product_type. Without the@, the statement is treated as old-style syntax and is rejected. - The type is taken from the view.
TYPE I_Product-ProductTypeborrows a type from the released view. You do not need to know the underlying data element. The view itself must be released for key user use, and so must any type you reference.
The example also tests sy-subrc after SELECT SINGLE. A missing record is a normal case, not an exception. Without the check, lv_product_type stays at its initial value and your logic proceeds as if the product type were blank.
What happens with unreleased sources
Suppose you tried this variant:
" Not allowed in key user custom logic: direct table access.
SELECT SINGLE mtart
FROM mara
WHERE matnr = @lv_product
INTO @DATA(lv_type).The syntax check rejects it because MARA is a database table that is not released. The error appears in the editor while you type or when you run the check. The fix is not to work around the restriction. Find the released view that exposes the field you need. For product type, that is I_Product.
What else is restricted
The released-object rule covers more than data access. In practice you will run into these limits:
| Area | Typical restriction |
|---|---|
| Database tables | Direct access to tables is not possible. Use released CDS views. |
| Function modules and classes | Only released ones can be called. Most classic function modules are not released. |
| Writing data | Standard business data is not changed directly from your code. Logic works on the data the BAdI hands you. |
| Transaction control | You cannot commit or roll back. The standard process owns the transaction. |
| System access | No file access, no operating system calls, no calls to other systems. |
| Dynamic access | Dynamic calls and access to arbitrary objects by name are not available. |
| Output | Classic `WRITE` and screen output are not available. Use the message mechanism of the BAdI. |
Some of these are a consequence of where the code runs, not just policy. A BAdI inside a posting transaction cannot issue its own commit, because that would split a business transaction in half. Treat this table as a guide, not a complete list. The syntax check is the authoritative answer for your release.
Finding released objects
When you need a field or a lookup, work from the business object outward:
- In the Custom Logic editor, use code completion on the
FROMclause. It offers only objects that the key user check accepts. - If completion does not show what you expect, check whether the data is available as an importing or changing parameter of the BAdI. Often the BAdI already supplies what you need, and no extra
SELECTis required. - For a wider search, use the released objects view in ABAP Development Tools or the SAP Business Accelerator Hub. Confirm the release state and the key user flag before you plan around an object.
- If no released view exposes the data, you have two options. You can request a release from SAP, or you can move the scenario to developer or side-by-side extensibility. Do not try to get at the data through an indirect route that bypasses the check.
Reading from a view also respects authorizations in the way the view defines. A released CDS view may carry access control. If the user running the transaction lacks authorization for the data, your SELECT returns fewer rows than you expect. This is easy to miss in testing with a powerful user.
Common errors
- Using a table or view name from the classic data model. The error says the object is not released. Look for the matching
I_view. - Forgetting
@on host variables. You get a syntax error that looks unrelated to released objects. Check the SQL syntax first. - Referencing a type that is not released. Even a harmless
TYPEreference fails if the data element is not released for key user use. Prefer types from the released view, as inI_Product-ProductType. - Assuming a released view is complete. Released views expose a chosen subset of fields. A field you know from the table may not exist in the view.
- Testing only with an administrator. Authorization checks inside the view hide rows from normal users. Test with a representative business role.
- Ignoring
sy-subrc. An empty result silently leaves your variable initial.
Decision criteria
Use key user custom logic when all of these hold:
- The BAdI you need is released for key user apps.
- Every piece of data you read is available through a released view or through the BAdI parameters.
- The logic is small: a derivation, a validation, a default value.
Choose another extensibility option when you need unreleased objects, you need to write data outside the BAdI contract, or you need to call external systems. The choice is not about skill. The restricted language and the released-object rule are the controls that keep key user extensions safe to upgrade.
Exercise
A colleague writes SELECT SINGLE mtart FROM mara WHERE matnr = @lv_product INTO @DATA(lv_type). in a key user BAdI implementation, and the editor reports an error. Why does it fail, what should the colleague do instead, and which release states must the replacement object have?
Show answer
MARA is a database table and is not released, so key user code cannot read it directly. The colleague should read the value through a released CDS view such as IProduct, for example `SELECT SINGLE ProductType FROM IProduct WHERE Product = @lvproduct INTO @DATA(lvtype).` The view must be released with a stable contract for use in custom development and also released for use in key user apps. The colleague should also check sy-subrc after the SELECT.
Exercise
Your SELECT on a released view works for you as an administrator but returns no rows for a sales clerk. Name one likely cause and one way to confirm it.
Show answer
The view probably has access control that filters rows by the user's authorizations, and the sales clerk's role does not cover that data. To confirm, run the same logic with a test user that has the clerk's business role, and compare the result with the administrator's. Do not widen authorizations until you know the filtering is unintended.