If you have to start a backend process from your FPM application, which takes longer than one second you have two options:
- Block the UI and show a waiting cursor as long as the backend needs to fulfill the task
- Start the process in a seperate asynchronous task, allowing the user to continue to work with the application
The first option causes a bad user experience, the 2nd a usability issue: When the task is completed, how do you inform the user? You could add a ‘refresh’ button to your application allowing the user to request the current status of the background task. Or you could simply check the status with every subsequent roundtrip. Or you can trigger recurring roundtrips simply for status checking by using a timed trigger.
Of course the appropriate option depends on the use-case.
Since Netweaver 7.31 SP07 FPM now offers asynchronous events, which offers a better solution for this issue. You can simply trigger an FPM event when the task is done.
To do this you have to do the following steps:
- Register the FPM event with IF_FPM. It will return a notification ID
data: lv_id type wdr_notification_id.
lv_id = mo_fpm->register_asynchronous_event( lo_event ).
- Start your asynchronous task and pass it the notification ID
call function ‘MY_ASYNCHRONOUS_TASK’ starting new task mytask
iv_notification_id = lv_id
- When the asynchronous task completes trigger the FPM event by calling
event_id = iv_notification_id
event_status = cl_wd_notification_service=>c_status_done ).
If the functionality is available in your system you can also have a look at the test application FPM_TEST_ASYNCHRONOUS_EVENT which shows this feature in a very simple application.