How to add a factory action to a Fiori Elements App

In SAP ECC the „Frontend“ Development was done by using SAP Dynpro (Dynamic Programming) in combination with process before outcome (PBO) and process after input (PAI) logic. It allowed developers to design interactive interfaces and customizable screens for SAP applications enabling users to interact with the system in a user friendly way. Dynpro screens are typically used for data entry, display, and navigation within SAP applications, providing a structured and consistent user experience.

While Dynpro is the older and more customizable technology, Fiori Elements is a newer, template-driven approach that enables a standardized and responsive webbased user experience. The choice between them depends on factors such as the specific requirements of the application and the desired level of customization and the sap system landscape. Here is a comparison between the two interface technologys:

Dynpro:

  • Traditional technology used for building SAP GUI-based interfaces.
  • Requires more manual design and development effort for creating screens.
  • Offers a high degree of customization but may result in a more time-consuming development process.
  • Well-suited for complex and highly customized applications.

Fiori Elements:

  • Modern UI technology based on SAP Fiori design principles.
  • Follows a more standardized and template-driven approach, reducing manual development effort.
  • Provides pre-defined templates for common use cases like lists, tables, and forms.
  • Promotes a consistent and responsive user experience across different devices.
  • Faster development with a focus on out-of-the-box usability.

Dynpros and Web Dynpros cant be used in a SAP Fiori App anymore that follow the ABAP RESTful application programming model. The ABAP RESTful application programming  model is a way to create web services and applications in S/4HANA. This model benefits by the new cloud native (optimized to fully leverage the capabilities of cloud computing environments) approach.

In this example we want to enhanceaFiori Elements App that got created before following the Rest model by adding a factory action.

In SAP Fiori a Factory Action is a design pattern that allows users to trigger specific actions or workflow from a central location, enhancing user efficiency and experience by providing a unified and easily accessible way to perform common tasks.

First of all the factory action need to implemented into the behavior definition.  That is a specific CDS (Core Data Service) view in the Rest Model. The behavior definitions dictate how the app responds to user actions and system events, ensuring a consistent user experience and aiding in the separation of UI design and underlying logic.

In the Metadata Extension CDS view we need to add the following annotation. Annotations are code elements that enrich the technical view definition with semantic information. They are part of the new ABAP Enitry Manipulation Language EML for CDS views. Annotations start with an at-sign (@).

    @UI.lineItem: [ {

    position: 100 ,

    importance: #MEDIUM}

  ,{ type: #FOR_ACTION, dataAction: ‚copyTravel‘, label: ‚Copy Travel‘ }]

We can use the quickfix function in eclipse to add a method for this new factory action into the local class of that behavior definition.

By pressing F2 (Code Element Information) we can check the parameter that the method is importing. The UUID (Universally Unique Identifier) is important here, as it serves as a globally unique identifier for each data entity, ensuring consistency and integrity.

In the implementation part of the method the UUID is used to read the current data record by using the READ ENTITIES statement. The entry data is stored into the internal table „travel_read_result“.  

Now the current data record can be enhanced, depending on the scenario. Here we want to add the latest Connection number out of the already existing entries for example. This was done before by using a Select Statement on an CDS View. (Normaly we would use the function „NUMBER_GET_NEXT“ that makes use of the number range objects)

  Data Lastconnectionnumber Type zc_cl_me_01_conn-ConnectionID.

„Find the last Connection number in CDS view zc_cl_me_01_conn-ConnectionID

    SELECT FROM zc_cl_me_01_conn

       FIELDS

       MAX( ConnectionID )

     INTO ( @Lastconnectionnumber ).

  Lastconnectionnumber = Lastconnectionnumber + 1.

Lastly the internal table „travels“ that contain the enhanced data record is used to create a draft table entry by using the statement MODIFY ENTITIES.

This Method reports back an internal table „mapped_create“ that contains a new UUID. This UUID belongs to the draft entry that got created. We can verify this by using the Debugger.

We can finally create the Connection entry by pressing the „create“ button on the Fiori Elements App.

This entry was posted in ABAP.