cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute Function after save in RAP/Fiori Elements?

08-23-2022 11:43 AM
Marian_Zeis Active Contributor
6212 views 10 comments
SAP Managed Tags
Subscribe

Hello experts,

we have a Fiori Elements App with managed RAP and OData V4 and Draft (2021SPS01).

We would like to execute a function module (with 'COMMIT WORKS' in it) after every save in the Fiori App (Create/Update).

As far as I know, the following options are still before the commit or the data is persisted in the table.
So the function module can't access it yet.

We tried this so far:

"with additional save"
"determination method on save { create; update;}"

In both implementations, when we try so SELECT from the database, the newly created data is not yet commited.

Are there other alternatives in the RAP Framework?

In the Fiori Framework there is the event "attachAfterActivate", but apparently only in the V2 Framework?
What I have not tried yet, but what is also not ideal,attach to an event directly on the V4 model like createCompleted.

What options do we have here?

Accepted Solutions (0)

Answers (4)

Answers (4)

lutzi3
Active Participant

What about CALL FUNCTION IN UPDATE TASK ? The module is started in this case after commit work only. But it runs completely asynchronously you have to pass all values as parameters.

Sschlegel
SAP Champion
SAP Champion

Perhaps a "CALL FUNCTION DESTINATION 'NONE' IN UPDATE TASK" to be very sure 😄

This is probably the best idea. Better ideas might come with more info about what you want to do.

Marian_Zeis
Active Contributor

Hi lutzi3 and sschlegel ,

thank you for your answers.
We have also used exactly that:

CALL FUNCTION ''
STARTING NEW TASK 'UPDATE
DESTINATION 'NONE'.

Of course 'COMMIT' is used in the FM.
But I suspect with this, it is not waiting for the commit, because if i do a select in the commit, the DB is not yet updated.

With 'IN UPDATE TASK' it would probably wait for the commit, but that doesn't work together with 'DESTINATION NONE'.

Without 'DESTINATION' it dumps.

lars_kr
Participant
0 Likes

Hi Marian,

Even if the post is a bit older, how did you solve the problem?
A COMMIT WORK within a managed RAP app also presents me with challenges from time to time. So far, I have always solved this problem with CALL FUNCTION '....' DESTINATION 'NONE'.
However, I would be interested to know if there is now a general workaround for this.

 

regards

Lars

Christophe_SW
Participant
0 Likes

Has anyone found a fundamental solution for this problem so far?
I often encounter the "Destination 'NONE'" method, but this causes a lot of unexpected behavior in my case.

We want to trigger a workflow after the RAP framework has updated/created it's entity.
I'm encountering issues where the workflow tries to manipulate the data before the RAP framework was finished committing / wrapping up.

My solution so far, is this:

  1. Fiori app sends a create request --> rap creates / updates the entity
  2. Fiori app waits for the response
  3. if the response was ok --> trigger the workflow via a custom RAP action


But even this approach can cause issues:
when you place a breakpoint in the action handler, the workflow will run inside it's own LUW and perform updates before RAP finished it's own internal commit.

The transition to RAP feels like a step back for my specific scenario compared to SEGW.
I need the guarantee that our logic is ran sequentially, but it isn't clear how to achieve it.



pfoehn94
Explorer

Hi Christophe

Your Problem (Start WF after all Tables are saved and commited by RAP) might be solved with RAP Business Events which are introduced in Release 2023.
I can't test it out right now. Maybe you have already?

Sounds promising 🙂

"As event provider, an event can be defined in the behavior definition of a RAP business object with the key word event EventName with or without parameters. After the event has been defined, it can be raised in the behavior implementation in the late save phase. Usually, an event with the respective message is raised after a change of state has been completed, e.g. if a BO entity like a travel or a booking has been created, updated or deleted. When the change is saved to the database, the event is raised during the SAVE sequence after the point of no return has passed."

Kind regards

Paul

dhegde
Participant
0 Likes

Hi Marian

One other option you could try is to set a event handler for event TRANSACTION_FINISHED of class CL_SYSTEM_TRANSACTION_STATE in SAVE_MODIFIED method.

This event is raised at the end of RAP save sequence when "COMMIT WORK" is executed. So, you can be sure that the changes are saved to DB by this time.

Hope this helps.

Thank you,

Dhananjay

Marian_Zeis
Active Contributor
0 Likes

Hi dhananjayhegde ,

thank you for your answer.

Unfortunately this does not work because I get this error when I want to implement the handler.
Also I haven't found anything else about it, so I guess that this is rather a workaround that is not so ideal.

dhegde
Participant
0 Likes

You could have separate class where you define the event handler method and then set this event handler in save_modified. That should work.

dhegde
Participant

Regarding whether this is ideal solution or not:

I not sure as well. On one hand, this is not part of public API. So, may not be ideal to use it.

On the other hand, when I check the where used list of this event, I see many applications including RAP BOs using it. May be a work around, used by many 🙂

Would be nice if RAP framework provides a exit in save sequence to plug into after COMMIT WORK is done. I think we cannot redefine the CLEANUP method as well in "managed" implementations.