Sub topic 2
Authorization objects, fields and activities
This chapter assumes you know what an SAP S/4HANA system and the Fiori launchpad are, and that you understand users and logon. You also need a rough idea of a business process such as order-to-cash. By the end you will be able to read an authorization check, say which object, fields and values it tests, and explain why a user passes or fails it.
Why authorization objects exist
A business user who can open an app still needs permission to do things inside it. Examples are posting in company code 1000, displaying but not changing sales orders for sales organization 3000, or releasing purchase orders up to a given value. SAP expresses this permission with authorization objects.
An authorization object is a template for one kind of permission. It defines a name and a set of authorization fields. A field is one dimension of the permission, such as a company code, a sales organization or an activity. The object does not say who may do what. It only says what a check for this kind of permission looks at.
The values live elsewhere. A role holds an authorization, which is an instance of an object with concrete values entered for each field. A user's roles give the user a collection of such authorizations. When program code runs a check, the system compares the values the code asks for with the values the user holds.
| Term | Meaning | Example |
|---|---|---|
| Authorization object | Template that lists the fields of one permission type | `F_BKPF_BUK` |
| Authorization field | One dimension of the permission | `BUKRS`, `ACTVT` |
| Authorization | An instance of an object with values per field | `BUKRS = 1000`, `ACTVT = 03` |
| Authorization check | A test in code against the user's authorizations | `AUTHORITY-CHECK OBJECT ...` |
Anatomy of an object
Take the standard object F_BKPF_BUK, "Accounting Document: Authorization for Company Codes". It has two fields:
BUKRS, the company code.ACTVT, the activity.
Authorization objects are grouped into object classes, such as Financial Accounting or Sales and Distribution. The class is a way to organize the objects. It has no effect on checks.
An object can have at most ten fields. Most have two to five. Because every field must match, the more fields an object has, the finer the control it gives.
Activities
The field ACTVT appears in most objects. It holds a two-character code for the operation. Some common values:
| ACTVT | Meaning |
|---|---|
| 01 | Create or generate |
| 02 | Change |
| 03 | Display |
| 06 | Delete |
| 16 | Execute |
| 23 | Maintain |
Not every activity is valid for every object. Each object lists the activities that make sense for it, and the role editor offers only those. The code 03 is the one you will meet most often, because display access is the usual baseline for reporting users.
Two activities do not imply each other. A user with change (02) but no display (03) is possible, though unusual. Many programs check for one activity only, so grant what the process needs and test it.
How a check is evaluated
A check names an object and supplies one value per field. The system looks through all authorizations the user holds for that object. The check passes if at least one authorization satisfies every field at the same time.
Three rules matter here:
- All fields must match, within one authorization. The system does not combine fields from different authorizations of the same object. If one authorization grants
BUKRS = 1000withACTVT = 03and another grantsBUKRS = 2000withACTVT = 02, a check for company code 1000 with activity 02 fails. - Several authorizations of one object add up. A check passes if any single authorization satisfies it. Adding a second authorization never removes access.
- A check can only grant, never deny. The authorization concept has no deny entries. To remove access, you remove or narrow the authorization.
Field values
The values in an authorization can take several forms:
- A single value, such as
1000. - An interval, such as
1000to1999. - A pattern with an asterisk, such as
10*. - A full wildcard
*, which means any value.
A fully open authorization on every field is a serious risk. In particular, ACTVT = * grants every activity, including delete. Reviewers look for these entries first.
Some checks use an empty value on purpose. A field value of ' ' in a role is written as a space, which is not the same as *. Be careful when you test fields that the code leaves out of the check. A field can be marked DUMMY in the code, which means the check skips it. This is useful when a field does not apply to the current call.
Writing a check in ABAP
The next example checks display access (activity 03) to one company code. It uses the object F_BKPF_BUK.
AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
ID 'BUKRS' FIELD lv_company_code
ID 'ACTVT' FIELD '03'.
IF sy-subrc <> 0.
" The user has no display authorization for this company code.
MESSAGE e000(00) WITH 'No authorization for company code' lv_company_code.
ENDIF.Reading this statement:
OBJECT 'F_BKPF_BUK'names the authorization object.- Each
ID ... FIELD ...pair names an authorization field and the value the program needs. sy-subrcholds the result. Zero means the user passed. Any other value means the check failed.
Common return codes:
| sy-subrc | Meaning |
|---|---|
| 0 | The user has a matching authorization |
| 4 | The user has authorizations for the object, but none matches the values |
| 8 | A field name in the check does not match the object definition |
| 12 | The user has no authorization for the object at all |
A missing check is the most common design error. If a custom program reads sensitive data and never calls AUTHORITY-CHECK, no role can restrict it. The authorization concept only works where the code asks.
Where checks fire in a Fiori scenario
Several layers can check authorizations for a single user action:
- The launchpad checks whether the user's role contains the catalog that exposes the app. Chapter by chapter, this tutorial covers that layer later.
- The service that the app calls checks whether the user may start it. This is usually the object
S_SERVICE. - The application logic runs
AUTHORITY-CHECKstatements for business data, such as company codes. - CDS access controls filter the rows that a query returns, based on the same authorization objects.
A user can pass one layer and fail another. A visible tile with an empty list is typical: the app starts, but the data-level checks return nothing. Keep this layering in mind, because later chapters on SU53 and traces depend on it.
Authorization objects and roles
Authorization data enters the system through roles. In the classic model, an administrator maintains roles in transaction PFCG. The role editor shows each object with its fields and values. The next chapter covers how a role turns into generated profiles.
For now, you only need this chain:
- An object defines the fields.
- A role holds an authorization of that object with values.
- A user receives the role, and so the authorization.
- A program checks the object and compares values.
Inspecting objects yourself
You can explore objects without changing anything. Useful transactions:
SU21shows authorization objects, grouped by object class, with their fields and valid activities.SU53shows the last failed authorization check for your own user. Later chapters use it for troubleshooting.SUIMprovides reports, for example to find which roles contain a given object.
A quick practice routine: open SU21, find the class for Financial Accounting, and open F_BKPF_BUK. Note the two fields and the activities it allows. Then run a SUIM search for roles that contain the object, and read the values in one of them.
Edge cases and common mistakes
- Treating the object as the permission. Having the object in a role means nothing until values are filled in. An object with empty fields grants nothing, and the role editor marks it as incomplete.
- Forgetting the activity. A role that grants
BUKRS = 1000but leaves out the rightACTVTfails every check that asks for the missing activity. - Assuming fields combine across authorizations. See rule 1. Splitting values across two authorizations does not produce the product of their values.
- Using
*to silence a failing check. This fixes the symptom and widens access to every value. Find the missing value instead. - Relying on the launchpad alone. Hiding a tile does not stop a call to the service behind it. Data-level checks must exist in the application or in CDS access control.
Exercise
A user holds two authorizations of FBKPFBUK. The first has BUKRS = 1000 and ACTVT = 03. The second has BUKRS = 2000 and ACTVT = 02. A program checks BUKRS = 1000 with ACTVT = 02. Does the check pass, and what is the likely sy-subrc?
Show answer
The check fails. No single authorization matches both fields: the first has the right company code but only display, and the second has change but for another company code. Fields are never combined across authorizations. Because the user has authorizations for the object but none matches, sy-subrc is 4.
Exercise
Name the three parts a check supplies in ABAP code, and explain what happens if a custom report reads financial data but contains no AUTHORITY-CHECK statement.
Show answer
A check supplies the authorization object name, each field name (ID), and the value the program needs for that field (FIELD). If the report contains no check, no role can restrict it. Any user who can start the report sees the data, because the authorization concept only applies where the code asks for it.