Sub topic 7
Publishing a field and using it in UIs, reports, forms and APIs
This chapter assumes you can open the Custom Fields and Logic app, know what a business context is, and have already created a custom field in the previous chapter. It covers what publishing does and how the published field shows up in each place a user or program can reach it.
What publishing does
A custom field you have just created is in a draft state. It exists in your definition, but nothing in the running system uses it yet. Publishing starts a background job that does the technical work for you:
- It adds the field to the database tables of the business context.
- It extends the related CDS views, so the field becomes readable in queries and reports.
- It extends the OData service and API structures that belong to the context.
- It generates the field ID with the
YY1_prefix and a system-generated suffix.
Custom field ID pattern: YY1_<FieldName>_<suffix>
Example: YY1_CostCenterNote_PRDThe YY1_ prefix marks key user extensions. You can use it to tell custom fields apart from standard fields in field lists, reports and API responses.
Using the field in UIs
After publishing, the field is available for UI adaptation. In the application that holds the field, switch on adaptation mode from the user menu. You can then place the field in the page layout, change its label, and move it between sections.
Some points to remember:
- Adaptation is a separate step from publishing. A published field does not appear on a screen until someone adds it.
- Adaptation can apply to all users or only to your own view, depending on the option you choose.
- For fields that belong to a business context with several UIs, such as a header and its items, you may need to add the field to each UI separately.
Using the field in reports
Publishing extends the CDS views that belong to the business context. That makes the field available to analytical and list-style apps built on those views. In apps such as Custom Analytical Queries, you can select the field as a dimension or a filter. In list report apps, you can add it as a column through the table settings.
If a report does not offer your field, check two things. First, confirm the app is based on a view that belongs to the same business context. Second, check that you enabled the field for analytical use when you created it, because that option must be set before publishing.
Using the field in forms
Form templates, such as those for output management, read from the data structures of the business context. After publishing, you can add the field to a form template in the Adobe Document Services based form editor. The field is then offered in the field list for that form. Re-check the form with a test document, because a field that is empty in the document stays blank in the output.
Using the field through APIs
Publishing also adds the field to the released OData services and APIs of the business context, under the same YY1_ name. A client can read or write it like a standard property, as long as the API belongs to the context.
A read request with a selected custom property looks like this:
GET /sap/opu/odata/sap/API_PRODUCT_SRV/A_Product('TG11')?$select=Product,YY1_CostCenterNote_PRDCheck the exact service and property names in the API documentation of your system. The service in your system defines the final field name, including the suffix.
For custom logic, you can read the field only through released objects. The following example reads standard product data through the released CDS view I_Product, using ABAP SQL 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.Once the field is published, the extended view returns your custom field in the same way, as a further column you can select.
Common problems
| Symptom | Likely cause |
|---|---|
| Field missing on a screen | The page was not adapted after publishing |
| Field missing in a report | The report uses a view from another context, or analytical use was off |
| Field blank in a form | The form template does not include it, or the source document has no value |
| Field not in the API response | The API is not part of the business context, or `$select` omits it |
Exercise
You published a custom field, but a colleague says it is not visible on the sales order screen. What is the most likely reason, and what do you do?
Show answer
Publishing only makes the field available in the system. It does not place it on a screen. Open the sales order app, switch on adaptation mode, and add the field to the layout, for all users if that is intended.
Exercise
Which prefix identifies a field created by a key user, and where can you see it?
Show answer
The prefix is YY1. It appears in field lists, reports and API responses, for example YY1CostCenterNote_PRD.