Enhancement for Fiori — finding the places for enhancement — getting custom error message (ABAP)

In this blog, I am going to explain one these problems and its solution.

The problem: The customer wants to get an error message in Fiori if the document is once canceled you cannot cancel again the same document after reversing.

The purpose of this blog, finding points for enhancement and a solution for getting an error message in Fiori. (database: s4hana)

Launch Fiori from SAP GUI using /N/UI2/FLP t-code. Search for the application Material Documents Overview and click it. Then write the material document number and click to Go. We will see the screen below. In Posting date box write the earlier date and choose the item and finally click OK.

We will get the error message:

Clarifying the problem: the customer wants in this page the error message with the text ‘You cannot cancel the document canceled before!’ before getting the error shown in the picture.

So, how to do it?

We understand that we have to enhance for getting custom error in Fiori application. And where to enhance and how to find the places for enhancement — these are our next questions.

Firstly, we have to find where all data is collected (selected). For finding it we have to know its OData Service. There are 2 ways:

1. https://fioriappslibrary.hana.ondemand.com/sap/fix/externalViewer/ – go to the link, click:

All apps -> Search application name (in our example: Material Documents Overview) -> click the application name -> Implementation information -> Configuration — on this page, we can find OData Service name.

2. In Fiori open the application, Press F12 (opening the inspection of the website). Open Network tab and try to reverse the document. And click OK for reversing the document. In Network tab find the row with the name ‘batch’. In this file, we’ll find OData service name.

Okay, we found the OData service name. The next step is explained below.

In SAP GUI, open t-code /n/iwfnd/maint_service. Here we’ll see the services list. Click find icon and paste the web service name. Find and click on the web service name and right below click Service Implementation button.

This screen will appear:

Then double-click on Data Provider class and it redirects us Class Builder page. On this page, we’ll see the methods of a class. Some of these methods are blue and some of them are black. If we set a breakpoint for each of them (of course external breakpoint) and launch the application to reverse the document we’ll see that the application redirects us to methods colored black. So, it means we can enhance into these methods. While debugging the methods we see the method with the name cancellation.

Double-click on the name of the method. And there we are! Here we’re going to enhance.

According to our experience with an error message in this method which has type ‘E’, this error message breaks the connection and directly closes the Fiori application. So that’s why we cannot write the error message in this method. But we have to keep in mind that we can only access this section of code when we run the application from Fiori. If we run migo it won’t be redirected to this section. So where do we have to write this error message then? For finding it we continue debugging.

There is an idea that we can write this error message where the Posting date error is written.

Run the migo -> Enter the document number -> Click to Item OK -> Check — we’ll get the same error message about the posting date that we’d got in Fiori application. Click the long text of the error message and copy message no.

Then return to the method for cancellation and set the external breakpoint. Open Fiori application and try to reverse it. It will redirect us to SAP GUI debug screen.

Set the breakpoint at the message. Enter the message details:

And we continue debugging.

Here, we found that error message. It means we can implement the error message here (in this form). Take the program name, form name, and find it in se80.

Firstly, back to the screen shown in the 7th picture, and double-click on the cancellation method. And enhance here. We have to know that it comes from Fiori application. (only through Fiori we are redirecting here).

So we used memory here for exporting data that provide us with the data that request comes from Fiori application.

Then in include FM07MEW0, in form werk_pruefen or inside werk_prufen — in form werk_lesen we can write error message:

Time to test. Go to Fiori application and try to reverse the document.

Here you are, the problem is solved.