Using Custom Fields and Logic

Objectives

After completing this lesson, you will be able to:

  • Create data source extensions
  • Create custom fields
  • Enable custom database fields for usage in SAP Fiori applications
  • Create custom logic

Extensibility

The extensibility apps help you customize applications and their UIs, reports, email templates, and form templates. Using extensibility apps, you can create database tables for segmentation and design queries.

Note
You can extend applications and their UIs, reports, email templates, and form templates only if the applications that you want to extend are extensible.

With the extensibility apps, you can create custom fields, data source extensions, and enhancement implementations for specific business contexts to enhance predelivered applications that are extensible, in order to adapt them to your business needs.

You can also create custom CDS views based on predelivered data sources. The data of an application is distributed across several database tables. Using CDS views, you can merge the data from different data sources and rearrange the table fields according to application-specific needs.

It is possible to create custom business objects with UIs and add custom logic to custom business objects. Thus, you can create your own applications based on custom business objects.

Extension items can be transported with the Configure Software Packages and Register Extensions for Transport apps to be productively available and usable.

You can view a list of your extensibility items, and the dependencies between them, in the Extensibility Inventory.

Custom Fields and Logic App

Different users and business contexts require different document layouts, or application functionality. To address these specific needs, you can use the Custom Fields and Logic app to adapt accordingly, for example, predelivered templates and logic.

This app combines the following three extensibility options:

  • Custom fields
  • Data source extensions
  • Custom logic

Data Source Extensions

You can create, edit, and delete data source extensions, in order to enable the usage of existing fields in predelivered data sources.

To create and maintain data source extensions, proceed as follows:

  1. Open the Custom Fields and Logic app. You can open the app either directly from the SAP Fiori launchpad, or from an extensible application by choosing Add Field in the UI adaptation mode of an application.

    Switch to the Data Source Extensions tab.

  2. Create a data source extension for the data source where it is needed.

    Choose Create above the list of existing data source extensions and select the data source to be extended. Enter an extension ID and description.

  3. Edit the data source extension.

    Enable the usage of additional standard fields (fields delivered by SAP) in the data source. Select additional standard fields, which can already be reached by the extended data source, but whose values are not yet retrieved by this data source.

  4. Adjust the proposed field names, if necessary.
  5. Publish your data source extension.
Note
  • Adding additional standard fields might enable end users to access restricted data in the extended data source, without having the required authorization.
  • Depending on the field path and the nature of the selected fields, data retrieval might become slower after a data source extension has been added.

To use new fields from a data source extension in an SAP Fiori app, you have to restart the app in the UI adaptation mode.

How to transport data source extensions to the production system is described later.

Create a Data Source Extension

Business Scenario

In this demonstration, you will create a data source extension to retrieve data of additional fields, delivered by SAP in the predefined Manage Customers app. For the additional standard fields, you create input fields on the object page of the app. 

Result

Now you know how to create a data source extension.

Custom Fields

You can use the Custom Fields and Logic app to create and maintain your own fields that can be used to enhance applications that have enabled their extensibility for key users.

In addition to the things listed in figure, Custom Fields, you can:

  • Choose a field type
  • Make your fields available in other languages
  • Publish fields to your test system
  • Edit fields that have already been published
  • Discard changes you have done to a field that was already published and thus reset all modifications to get back to the state of the last published version of a field with one click

To create custom fields, proceed as follows:

  1. Open the Custom Fields and Logic app. You can open the app either directly from the SAP Fiori launchpad, or from an extensible application by choosing Add Field in the UI adaptation mode of the application.
  2. Create a custom field in the business context where it is needed.
  3. Edit a custom field.

    Decide where the custom field is needed and if it has to be searchable. Translate the field, if required. You can also define the aggregation behavior of the field. Depending on the field type, you can choose among the following aggregation behaviors:

    • None: Field values are not aggregated. This aggregation behavior is the default for the field types Date and Time.
    • Sum: Field values are summed up. This aggregation behavior is the default for numeric field types.
    • Maximum: The maximum field value is calculated.
    • Minimum: The minimum field value is calculated.
    Note

    Fields of the types Checkbox, Email Address, Code List, Web Address, and Text cannot be aggregated.

    As soon as a field is enabled for field usage in UIs and reports that show aggregated data, the selected aggregation behavior is applied to the field.

    If your field is a character-like type or supports the usage of decimal places, you can adapt the field length and number of decimal places as needed.

    Note
    When you publish a field with a certain length, you cannot decrease the field length later on.
  4. Publish your custom fields for transport.

To use a field in an SAP Fiori app, you have to restart the app in the adaptation mode.

Create Custom Fields

Business Scenario

In this exercise, you will learn to enhance the predefined Manage Customers app by adding custom fields.

Steps

  1. Start the predefined Manage Customers app using the SAP Fiori launchpad. In this app, navigate to the object page for a customer and open the Custom Fields and Logic app by choosing Add Field in the UI adaptation mode for this page.

  2. In the Custom Fields and Logic app, create and publish the following two custom fields:

    Business ContextLabelIdentifierTooltipType
    S4D425: Student 01Premium StatusZZ1_ispremium_01Premium StatusCheckbox
    S4D425: Student 01DiscountZZ1_Discount_01DiscountNumber (Length: 5, Decimal Places: 2)

    Make sure that the usage of the two custom fields in the Manage Customers app is enabled.

  3. Add the two custom fields to the General Information group on the object page of the Manage Customers app.

  4. To test the added custom fields, edit an existing customer in the Manage Customers app. Set the Premium Status flag for the customer to true, enter a discount other than zero, and save your changes.

Custom Database Fields

Custom fields can be created not only using the SAP Fiori app Custom Fields and Logic but also using back-end transactions to create database fields.

You might face the following situation: Custom fields (database fields) are available in the back-end already, but need to be used in an SAP Fiori application. To use database fields also to enhance SAP Fiori applications, you need to enable the database fields for usage with SAP Fiori.

Note
The adaptation transport organizer has to be set up in the system in which you want to enable database fields for usage in SAP Fiori apps. This is done by means of transaction S_ATO_SETUP.

To enable database fields for usage in SAP Fiori apps, proceed as follows:

Open the transaction Enable Fields for Use in App 'Custom Fields and Logic' (transaction SCFD_EUI) and search for the database fields that you want to enable for usage.

A list of database fields is displayed. These fields were added to database tables using append structures or customer includes. The field status indicates whether a field can be enabled directly, whether it needs to be prepared beforehand, or whether it has already been enabled.

Among others, there are the following statuses:

  • Preparation Required

    In this case, choose Prepare and follow the step-by-step instructions provided in the dialog that opens.

  • Can Be Enabled
  • Enabled
  • Cannot Be Enabled

    This means that the field either does not reside in a database table which was prepared by SAP for use in the app Custom Field and Logic, or its ABAP dictionary data type is not supported by the app.

After enabling, and before the SAP Fiori app Custom Fields and Logic is used to add a field to UIs, reports or email templates, please check whether your database field was added manually to any Core Data Services (CDS) data definitions delivered by SAP.

Once enabled for the SAP Fiori app Custom Fields and Logic, the fields are available in the app together with any newly created custom fields, and can be added to SAP Fiori UIs and reports, form templates and email templates, as well as business scenarios in the same way as custom fields.

This means that you have to enable the usage of the custom database fields in the Custom Fields and Logic app.

Enable Custom Database Fields for Usage in SAP Fiori Applications

Business Scenario

The predefined Manage Customers app uses a database table in the SAP namespace to store the customers. This table has been extended using an append structure in the customer namespace. The additional fields from the append structure are available in the back end already, but cannot be used in the Manage Customers app yet.

In this demonstration, you enable the custom database fields for usage with SAP Fiori and add corresponding input fields to the UI of the Manage Customers app.

Note
You will learn to enable the custom database fields for usage with SAP Fiori and add corresponding input fields to the UI of the Manage Customers app.

Result

Now you know how to manage the custom database fields usage.

Custom Logic

With the Custom Fields and Logic app, you can also create enhancement implementations to adapt applications.

Using this app, you can:

  • Implement custom logic
  • Test your custom logic, for example, with predefined test variants
  • Create filter conditions, to define when an enhancement implementation is executed
  • Publish enhancement implementations to your test system
  • Edit enhancement implementations that have already been published
  • Delete enhancement implementations

To create and maintain custom logic that can be used to enhance applications, which have enabled their extensibility for key users, proceed as follows:

  1. Open the Custom Fields and Logic app. You can open the app either directly from the SAP Fiori launchpad, or from an extensible application by choosing Add Field in the UI adaptation mode of an application.
  2. Create an enhancement implementation for the business context, where custom logic needs to be run.
  3. Edit your enhancement implementation.

    Custom logic is implemented in an enhancement implementation using ABAP for Key Users in a web-based editor.

  4. Publish enhancement implementations for transport.

ABAP for Key Users is used to implement business logic extensions using a web-based editor in the SAP Fiori environment.

For more information about how to use ABAP for Key Users to implement your custom logic using the Custom Fields and Logic app, you can refer to the documentation.

Restricted ABAP

Information about restricted ABAP:

  • Key user extensibility apps Custom Fields and Logic, Custom Business Objects and Custom Reusable Elements include an in-app ABAP editor for coding, for example, data validations, substitutions, or determinations. In this editor, only a restricted form of ABAP is possible.
  • Supported language features in restricted ABAP are:

    • Basic expressions, control and flow statements, variables, and internal tables
    • String, math, data, and time operations
    • Read and write access to the interface of the enhancement option
    • Read and write access to white-listed SAP APIs (classes)
    • Read access (full SQL select support) to white-listed SAP CDS views
  • The following ABAP features are not allowed, to ensure the robustness, security, and the data consistency target:

    • Any database operation, except selects from released views, for example, the commit work statement is not allowed
    • Access to files and other I/O commands
    • Creating new tasks (parallel processing)
    • Dynamic programming
    • Code generation
    • To simplify the syntax, obsolete ABAP statements are removed from the syntax
  • The complete list of allowed ABAP statements is available in the documentation.

Create Custom Logic

Business Scenario

There is a predefined BAdI for the Manage Customers application, which can be used to validate the country of a customer. In this demonstration, you will learn how to create a corresponding enhancement implementation for this BAdI.

Log in to track your progress & complete quizzes