Sub topic 5
Choosing the right business context
This chapter covers how extensibility business contexts decide where a custom field appears and which objects can carry it. It assumes you can open the Custom Fields and Logic app in the SAP Fiori launchpad. It also assumes you know the business objects involved, such as sales orders, business partners and products. You should know what a custom field is, but you don't need to have created one yet.
What a business context is
A business context is a grouping that SAP delivers for the extensibility of one area of the system. It ties together the database structures, the CDS views, the UIs, the forms and the APIs that belong to one business object or process step.
When you create a custom field, you pick one or more business contexts. That choice decides three things:
- Which database tables store the field value.
- Which UIs, reports, forms and APIs can show the field.
- Which other contexts can receive the value, because related contexts can pass a field along.
Key users can't create contexts. SAP delivers them, and each context is tied to a specific set of released extension points. Your job is to choose from the list that is offered.
Why the choice matters
The context is the most consequential decision in the field creation dialog. A field belongs to the context it was created in. Moving it later is not a simple edit.
If you pick a context that doesn't match the process, the field may exist in the system but never appear where users need it. If you pick one that is too broad, you may create fields in places that don't need them. Both mistakes cost effort to correct, and the second one leaves unused fields in the system.
A field also has to fit the object that holds the data. A value like "customer approval reference" belongs on the sales order header, not on a product. A value like "storage hint" belongs on the product. Decide first which object owns the value, then choose the context for that object.
Typical contexts
The exact list depends on your release and on which applications are active. The names below are common examples. Check your own system for the list that applies.
| Business context (example) | Typical use | Example field |
|---|---|---|
| Sales: Header | Data about the whole sales document | Customer PO approval reference |
| Sales: Item | Data about one line of a sales document | Packaging remark per line |
| Product (Basic Data) | Master data of a product | Hazard class note |
| Business Partner | Master data of a customer or supplier | Preferred contact channel |
| Purchasing: Header or Item | Data on purchase orders | Contract reference |
| Cost center or accounting objects | Financial master data or postings | Cost center note |
The context name tells you the object and the level, header or item. Pay attention to the level. Header and item contexts are separate, and a field created for the header does not exist on the items.
How a context connects a field to its uses
A context bundles several technical elements. You don't maintain them yourself, but it helps to know they exist, because they explain what happens after you publish.
- Extension include or extension field in the database structure. The system stores the value here. Its name starts with the prefix YY1_.
- Extension of released CDS views. The field is added to the released views of the context, so it can be read by reports and by APIs.
- UI adaptation. The field can be added to the screen through the adaptation tools.
- Forms and email templates. The field becomes available as a field for form templates.
- Release of the field in APIs. The field is added to the OData service or the other API of the context.
The following diagram shows how one context connects the pieces.
Choosing a context step by step
Use this sequence when you plan a field.
- Name the business object that owns the value. Ask which object a user would describe the value as belonging to.
- Decide the level. Ask whether the value is the same for the whole document or differs per item.
- Decide where the value must appear. List the UIs, reports, forms and APIs you need.
- Open the context list in the Custom Fields app and look for the entry that matches steps 1 and 2.
- Check the usage of the context. The app shows which UIs, forms and APIs the context supports. Confirm that the places from step 3 are covered.
- If two contexts seem to fit, prefer the one that is closest to where the data is entered.
Example: an approval reference
A company wants to record an internal approval reference for each sales order. The reference applies to the whole order, so the level is header. The sales team enters it in the order app and the billing team needs it on the invoice form.
The owning object is the sales order, the level is the header, and the field must appear on the UI and on a form. The right choice is the sales order header context, provided the app shows that form and UI support. A field on the item context would force users to enter the same value on every line.
Example: a field that is needed on both header and item
Sometimes the same business meaning is needed on both levels, for example a delivery priority. In that case you do not create one field that covers both. You create one field for each level, in the matching context, and decide how the item value is derived. Often the item value defaults from the header through custom logic. The chapter on custom logic with BAdIs shows how such a default can be set.
Passing a field between contexts
Many processes copy data from one document to the next, for example from a sales order to a delivery to an invoice. Related contexts can be connected so that a field created in one context is also available in the next.
When you create a field, the dialog can offer to use it in other contexts that follow from the same process. This is called field migration or field propagation in some documents, and the name varies by release. If you accept the offered contexts, the value is carried over in the standard copy flow.
Keep these points in mind:
- The field in the target context has its own storage. It is a related field, and its name stays consistent with the source field.
- Copy control depends on the standard copy logic. If the standard process doesn't copy a value, a field in a connected context will still be empty.
- You choose the connected contexts when you create the field. Treat the list as part of the design. Changing it later is limited.
Contexts and the clean core
Business contexts are the mechanism that keeps key user extensions upgrade-safe. The field is stored and exposed only through extension points that SAP has released. An upgrade can therefore keep the field and its value, because the extension doesn't touch standard objects.
This also explains a restriction. If a business object has no released context, a key user can't add a field to it. You need a different approach for that object, such as developer extensibility, which later chapters of the plan compare with key user extensibility.
Common mistakes
- Choosing the wrong level. A header field does not appear on items. Check header and item contexts before you save.
- Choosing by the app name. An app may show data from several objects. Choose by the object that owns the data, not by the screen where users first notice the gap.
- Creating duplicates. Two fields with the same meaning in different contexts lead to inconsistent reports. Before you create a field, search the existing fields in the app.
- Ignoring the intended uses. A context that does not support the form you need will not give you that form field. Check the supported usage first.
- Expecting a context for every object. Not every object has one. The list is limited to released extension points.
Recognizing the result in the system
After the field is created in a context, you can recognize it by its identifier. Custom fields created by key users carry the YY1_ prefix, so you can tell them apart from standard fields in field lists, reports and API responses.
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.The suffix reflects the context, so two fields with similar names in different contexts are still distinguishable. This helps when you read an API response and want to know which context a field came from.
Checking your choice before you continue
Before you move on to field creation, confirm these points.
- You know which object owns the value.
- You know whether the value is per document or per item.
- You have confirmed that the context supports every UI, report, form and API you need.
- You have decided whether connected contexts should receive the value.
- You have searched for an existing field with the same meaning.
The next chapter takes these decisions and turns them into a field, step by step.
Exercise
A purchasing team wants to store a "contract reference" that is the same for the whole purchase order, and they want it to appear on the printed purchase order form. Which kind of context should you look for, and what should you check in the Custom Fields app before you create the field?
Show answer
Look for the purchasing context at header level, because the value applies to the whole order. Before creating the field, check in the app that this context supports the form used for the printed purchase order, and search the existing fields to make sure no field with the same meaning already exists.
Exercise
A sales manager asks for a "packaging remark" that can differ for each line of a sales order. A colleague creates it in the sales order header context. What goes wrong, and how do you fix it?
Show answer
A header field holds one value for the whole order, so users cannot enter a different remark per line, and the field does not exist on items. The fix is to create a new field in the sales order item context, and then migrate or retire the header field so reports do not contain two fields with the same meaning.