Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
Dr_Joerg_Rett
Advisor
Advisor


Picture this, you’re trying to create your own Situation Handling use case. There’s an urgent business issue that Situation Handling can detect and bring to the attention of the end users. Your idea is to calculate a ratio based on summing up some line items that should trigger the situation.  You start to create your own view using the Custom CDS Views app and suddenly you realize that defining “group by” and aggregations aren’t available as stated in this blog post. This doesn’t have to be a showstopper for you. Let me show you why (not).

My name is Joerg Rett and I am the lead for Data, Analytics and Developer Extensibility in the Situation Handling team. In this blog post series you will follow as I show you the steps for creating your own Situation Handling use case as introduced in Angelika Salmen’s blog post. The blog post series is organized in the following way:

  1. This first blog post introduces the use case, the 3-system landscape and the part of developer extensibility.

  2. The second blog post follows up with the first part of key-user extensibility from the perspective of an extensibility specialist.

  3. The third and final blog post deals with the second part of key-user extensibility from the perspective of a business process configuration expert. It shows how the business user experiences situation instances and monitoring of activities.


While overcoming the challenge described, you will experience the power and freedom you get when you combine developer extensibility with key user extensibility.

With the SAP S/4HANA Cloud ABAP Environment, also known as Embedded Steampunk, it is possible to develop ABAP Cloud extensions on SAP S/4HANA Cloud, public edition as introduced in Boris Gebhardt’s blog post. This means you can use public SAP APIs released by SAP to access SAP data as well as ADT (ABAP Development Tools) as your ABAP IDE.

In another blog post, this one written by Georg Wilhelm, you can see how the combination of developer extensibility and key user extensibility lets you create custom fields with ABAP implemented Value Help.

Let’s start by understanding the use case.

Cost center budget threshold exceeded

In this case, our business user is Sarah, an overhead accountant. In the Cost Center Budget Report app, she can monitor the budget spent. Each GL Account Group receives a certain budget per quarter, for example, € 100.000 for travel. If most of the budget has been spent and the end of the quarter is still a ways off, Sarah may need to take a closer look. Maybe someone needs to postpone their business trip or travel expenses need to be restricted. In any case, Sarah would know what to do. In our example she can see that most of the budget for an accounting group has been spent in fiscal period two.


Sarah starts thinking that her life would be so much easier if she were notified about budgets requiring her attention.


But hey, isn’t that why the Situation Handling framework was built? You just need to create a CDS view that calculates a ratio based on summing up the line items reflecting the money that has been spent. The easiest way to do that is to aggregate based on the “group by” function you’re familiar with. The problem is that “group by” isn’t available in the Custom CDS Views app. But don’t worry, you can create a custom CDS view using developer extensibility; from there continue with key user extensibility to create situation objects.

So, first, let’s figure out where you need to create the artifacts and which role you need.

What’s created where and by whom?

Let’s start with the question: Where you can implement your objects? The 3-system landscape, as shown on SAP Help Portal, consists of a development system, a test system, and a production system (see below).


The development system is divided in the development tenant (080) and the customizing tenant (100). The path you need to follow looks like this:

  1. Start as a developer in the development tenant.

  2. Log in as an extensibility specialist to develop on the customizing tenant.

  3. Log in as a business process configuration expert to configure on the customizing tenant again.

  4. Log in as an administrator to the test system and then to the production system, where you import the artifacts.

  5. Log in as an overhead accountant to experience Situation Handling in the production system.


While following this path, you will create the artifacts below.




  1. Start to create a custom CDS view in the development tenant.

  2. Reference this custom CDS view in a situation object in the customizing tenant.

  3. Create a situation scenario that uses this situation object.

  4. Create a situation template based on the situation scenario.

  5. Create a situation type from the situation template.


Note: The last four steps all take place in the customizing tenant.

This is the way. The first artifact you need to develop is the custom CDS view that does the aggregating.

Get started with developer extensibility

As mentioned, before you aggregate using “group by”, which is not available in the Custom CDS Views app and take advantage of the vast possibilities offered by developer extensibility. As described in Boris Gebhardt’s blog post, in your case it would make sense to base your custom CDS view on an SAP CDS view released by SAP with a C1 contract for use in for ABAP Cloud development.

Using as ADT (ABAP Development Tools) as your ABAP IDE you can see that the interface view I_COSTCENTERBUDGET is released for use in cloud development.


With this pre-condition fulfilled, you can now create your custom CDS view, for example, ZI_COSTCENTERBUDGET
@EndUserText.label: 'Cost Center Budget with consumption'
define view entity ZI_CostCenterBudget

With a select on the interface view
as select from I_CostCenterBudget (

you can access the important fields, such as cost center. You need to decide which fields from the interface view you also want to have available in your custom CDS view. This requires some imagination about what you might need later on, on the way from the custom CDS view to the situation type. You also need to think about how you want business users to experience situation instances through notifications and My Situations – Extended app. These are the fields that play a role in this specific use case:

  • Anchor Object Key:
    A situation needs to by “anchored” to a unique entry in your custom CDS view, so the anchor object key field needs to be part of your custom CDS view.

  • Semantic Key Fields:
    The anchor object key is often a concatenation of fields that form a unique ID. To give the user the information about which field contributes to which part of the key, you define a sematic key whose fields need to be part of your custom CDS view.

  • Condition Filter:
    You want to create situations only for company code 1010. The business process configuration expert will define this in the condition filter of the Manage Situation Types – Extended You need to include all the fields that will be used as conditions in your custom CDS view.

  • Text Parameter:
    You want to the number of the cost center to be visible in the notification. The business process configuration expert will define this in the texts for the messages in the Manage Situation Types – Extended You need to include all the fields that will be used as variables in your custom CDS view.

  • Navigation Parameters:
    You want that the navigation to the Cost Center Budget Report app already sets the filter for the fiscal year. The extensibility specialist will define this in the navigation parameters of the Manage Situation Objects You need to include all the fields that will be used as parameters in your custom CDS view.


For other use cases you also might want to consider a trigger object key different from the anchor object key, parameters that are needed for the callback action, columns with detailed data in the My Situations – Extended app, and what should be part of the detail section in the situation page.

You’ll see the following custom CDS view fields again along the way.
BudgetCarryingCostCenter,
GLAccount,
@EndUserText.label: 'G/L Account Group'
GLAccountHierNodeSemanticKey,
FiscalYear,
FiscalPeriod,
CompanyCode,
CompanyCodeCurrency,

Now you need to verify whether any of the fields can serve as a unique identifier for the anchor object (see SAP Help Portal for more details).

This identifier needs to come from a field in a table, which means it should be persistent in the database. In cases in which this is not possible, you may use a calculated field in the CDS view and concatenate multiple fields into a new unique identifier. However, you need to be aware of the limitations: using calculated fields will have a negative effect on performance, and cause both the detection of situations and the determination of responsible users to become significantly slower. If the underlying data set is too large, this can cause the processing to fail. Thus, this approach can only be recommended if you expect the data set exposed by your CDS view to be small (max. a few hundred entries).

Once you are sure which combination of fields will define a single record, you can concatenate them. In your case, it is the combination of Cost Center, G/L Account and a period.
@EndUserText.label: 'Cost Center Budget Key'
concat(concat(BudgetCarryingCostCenter, GLAccount), concat(FiscalYear,FiscalPeriod)) as CostCenterBudgetKey,

 

Next, aggregate the line items for costs and budgets using “sum()” as and “group by”. This type of aggregation is exactly what is possible only with developer extensibility.
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
@EndUserText.label: 'Assigned Costs Sum'
sum(TotAssgdAmtInCoCodeCurrency) as TotAssgdAmtInCoCodeCurrencySum,

As the last step you simply calculate the budget consumption from the assigned costs and the budget.
@EndUserText.label: 'Budget Consumption'
case when sum(BudgetAmountInCompanyCodeCrcy) > 0.0
then
cast ( cast( 100 * sum( TotAssgdAmtInCoCodeCurrency ) as
abap.fltp ) / cast( sum( BudgetAmountInCompanyCodeCrcy )
as abap.fltp) as abap.dec( 9, 2 ) )
else cast( 0.0 as abap.dec( 9, 2 ) )
end as BudgetConsumption

Finally, your custom CDS view to be release with a C1 contract so it can be used in the system. It is crucial that the release state confirms the use in key user apps.


The additional confirmation for use in cloud development is not important for this use case but might be useful in cases you in which you want to reuse the view for developer extensibility later on.

What you learned and what will come next

You started as a developer to create a custom CDS view based on a public SAP API with standard source code to aggregate line items and calculate a consumption ration.

Next as an extensibility specialist you will use this CDS view to create a situation object which represents the budget consumption.

Want to learn more or refresh your knowledge on Situation Handling?

More blog posts about Situation Handling are available:

For more information, see SAP Help Portal for Situation Handling – Extended Framework for SAP S/4HANA and SAP Community for Intelligent Situation Handling. We welcome your valuable feedback.