Wednesday, 3 August 2022

How to Display Situations in Your Custom Apps with the Extended Framework of Situation Handling

Situation Handling in SAP S/4HANA and SAP S/4HANA Cloud detects exceptional circumstances and displays them to the right users.

I’m the lead UI developer within the Situation Handling framework for end-user facing apps and I’m excited to present a new feature in the Situation Handling extended framework to you. Together with the team from SAP Fiori elements, we introduce a new, simplified way of displaying situations right in your business apps. You can enable a great user experience for your end users with low effort. You should read through this tutorial-style article which explains the details and points you to further resources that you can take as a blueprint for your successful implementation.

With the extended framework of Situation Handling, situations can be displayed in apps based on SAP Fiori elements for OData version 4. You can do this without any front-end development, just by extending the app’s OData service.

What you will get is a new button, the situation indicator, in tables and object page headers whenever there is a situation for the business object. By clicking the button, you get a preview of the situation. From this preview, you can go to the situation page with the situation details and see the proposed actions that can help you resolve the situation. This is what the end user experience looks like:

SAP S/4HANA, SAP HANA Exam, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Guides, SAP HANA Career, SAP HANA Jobs, SAP HANA Preparation
Animation of the User Experience of Situations in an SAP Fiori Elements App

The example shows the Situation Demo app. You can explore its UI service, using it as a blueprint for enabling your own app.

To enable situation indicators, you just need to do three things: one, refer to a particular ODataV4 situation entity set in the app’s UI service and two, establish a link to the situation object modelled as an anchor object within the extended framework for Situation Handling. This link is based on SAP Object Types (SOT) and SAP Object Node Types (SONT) that are referenced app’s service and the situation object model. Finally three, extend your app’s service definition.

Customers and partners can model all these steps. This is described below in detail.

Note that this method works only if you’re using the extended framework for Situation Handling and the app is based on SAP Fiori elements for ODataV4. Any other combination (like standard framework for Situation Handling or SAP Fiori elements for OData V2 or freestyle apps) will not work like this.

Step-by-Step Implementation Guide


Step 1: Link Your Situation Object Structure with an SAP Object Type (SOT) and an SAP Object Node Type (SONT)

You need to assign the situation object’s structure to an SOT and an SONT in the “Manage Situation Objects” app.

Let’s take our demo situation object ‘Flight’ as an example. It uses the SOT/SONT “BusinessSituationDemoFlight”.

SAP S/4HANA, SAP HANA Exam, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Guides, SAP HANA Career, SAP HANA Jobs, SAP HANA Preparation
Configuration of the SOT and SONT in App Manage Situation Objects

Make both assignments in the Structures The SOT and SONT that you assigned will be used in the next step.

Step 2: Extend Your App’s CDS View

For each exposed entity that is a situation anchor object (the business object that is affected by a situation) and for which you want to indicate situations, do the following:

First, extend the entity’s CDS view by adding the following privileged access annotation:

// added privileged access for association to Situation Service 
@AccessControl.privilegedAssociations: [ '_SAPSituation' ]

Then, extend the definition of the entity itself:

define view entity C_YOUR_ENTITY {
    // add the association to the situation
    association [0..1] to I_Sitn2InstanceCountAPI as _SAPSituation
        // joining on SAP Object Type of your anchor object
        on  _SAPSituation.SitnAnchorObjectSOT = 'YourSAPObjectType'
        // and SAP Object Node Type of your anchor object
        and  _SAPSituation.SitnAnchorObjectSONT = 'YourSAPObjectNodeType'
        // and the property that holds the anchor object key 
        and _SAPSituation.SitnInstceAnchorObjectKey =
            $projection.YourAnchorObjectKeyProperty
    ...

    // further down in the view, expose the joined association as
    // a navigation property. the name of association is not fixed,
    // but it must be the same as in the privilegedAssociations
    // annotation from above internally.
    // SAP Fiori elements will identify this association by detecting
    // the annotation
    // @ObjectModel.sapObjectNodeType.name: 'BusinessSituation'
    // from the view I_Sitn2InstanceCountAPI 
    _SAPSituation,
    ...
}

To see a complete example of an extended view, take a look at the C_SITN2DEMOFLIGHTTP view in your development system.

Step 3: Extend Your App’s Service Definition

In addition you need to extend the OData V4 service definition by exposing the following additional entity sets:

@EndUserText.label: 'Your Label'
    define service YOUR_SERVICE_NAME {

    // Example Application Part (the entity sets you already have)
    expose C_SITN2DEMOFLIGHTTP_DEMO as Flight;
    expose C_SITN2DEMOBOOKINGTP_DEMO as Booking;
    expose C_Sitn2DemoCarrierTP as Carrier;
    ...      

    // Additional entity sets required for Situation Service
    expose I_Sitn2InstceCountAPI        as SituationIndicationCount;
    expose I_Sitn2InstcePreviewAPI      as SituationInstance;
    expose I_Sitn2InstceAttributeAPI    as InstanceAttribute;
    expose I_Sitn2InstceAttribValueAPI  as InstanceAttributeValue;
    expose I_Sitn2InstceTextAPI         as SituationInstanceText;
}

To see a complete example of an extended service definition, you can refer to the demo service C_SITN2DEMOFLIGHTSRV in your development system.

No comments:

Post a Comment