2015 Dec 12 3:50 AM
We have a requirement where we have to run a bunch of routines inside a RFC FM fetching various KPIs of the system (Basis KPIs) from an external system. But we don't want to burden the system by making performance intensive routines inside this RFC call.
So, the requirement is to call a FM and execute the RFC FM only if the entire execution time(runtime) is below a certain threshold ( < 500 ms).
If the runtime of the FM is going to take > 500 ms, we want to default certain KPIs or issue a system alert..
Can this be done ? Please share some ideas.
-Shareen
2015 Dec 13 6:46 PM
Hi Shareen,
Sounds like you need the main FM to call the second one asynchronously starting a new task. See the help for CALL FUNCTION ... STARTING NEW TASK.
Here's some sample code. Here my timeout was in seconds but you could adapt the WAIT statement to handle a shorter timeout.
FUNCTION ...
ADD 1 TO gv_task_no.
lv_timeout = 1.
* Call the maybe slow function.
CALL FUNCTION 'ZMAYBE_SLOW'
STARTING NEW TASK gv_task_no
PERFORMING fm_response ON END OF TASK
EXCEPTIONS
communication failure = 1
system_failure = 2.
* Waiting for the fm to complete.
DO lv_timeout TIMES.
IF gv_completed = 'X'.
EXIT.
ENDIF.
WAIT UNTIL gv_completed = 'X' UP TO 1 SECONDS.
ENDDO.
ENDFUNCTION.
*----------------------------------------------------------------------*
FORM fm_response USING taskname TYPE any.
RECEIVE RESULTS FROM FUNCTION 'ZMAYBE_SLOW'
IMPORTING
es_result = gs_result
EXCEPTIONS
communication failure = 1
system_failure = 2.
IF sy-subrc = 1.
gv_message = 'Sy-subrc 1 - Communication failure'.
ELSEIF sy-subrc = 2.
gv_message = 'Sy-subrc 2 - System failure'.
ENDIF.
gv_completed = 'X'.
ENDFORM.
Best regards,
Paul
2015 Dec 12 8:51 AM
Hi,
Interesting problem, but I'm not sure what you mean.
"If the runtime of the FM is going to take > 500 ms, we want to default certain KPIs or issue a system alert."
How can you know what the runtime will be, before you execute the RFC?
Please explain further.
cheers
Paul
2015 Dec 12 6:29 PM
I know we cannot pre-empt the runtime of a FM before we actually call..
But the idea is..call a FM and this FM shouldn't run for more than 500 ms..If it is going to exceed 500 ms, abandon the FM processing and exit with the message 'Query time exceeded 500 ms'
2015 Dec 13 6:46 PM
Hi Shareen,
Sounds like you need the main FM to call the second one asynchronously starting a new task. See the help for CALL FUNCTION ... STARTING NEW TASK.
Here's some sample code. Here my timeout was in seconds but you could adapt the WAIT statement to handle a shorter timeout.
FUNCTION ...
ADD 1 TO gv_task_no.
lv_timeout = 1.
* Call the maybe slow function.
CALL FUNCTION 'ZMAYBE_SLOW'
STARTING NEW TASK gv_task_no
PERFORMING fm_response ON END OF TASK
EXCEPTIONS
communication failure = 1
system_failure = 2.
* Waiting for the fm to complete.
DO lv_timeout TIMES.
IF gv_completed = 'X'.
EXIT.
ENDIF.
WAIT UNTIL gv_completed = 'X' UP TO 1 SECONDS.
ENDDO.
ENDFUNCTION.
*----------------------------------------------------------------------*
FORM fm_response USING taskname TYPE any.
RECEIVE RESULTS FROM FUNCTION 'ZMAYBE_SLOW'
IMPORTING
es_result = gs_result
EXCEPTIONS
communication failure = 1
system_failure = 2.
IF sy-subrc = 1.
gv_message = 'Sy-subrc 1 - Communication failure'.
ELSEIF sy-subrc = 2.
gv_message = 'Sy-subrc 2 - System failure'.
ENDIF.
gv_completed = 'X'.
ENDFORM.
Best regards,
Paul