data: gt_return type bapiret2_tt.
call function 'RM_FREE_SESSION_CHECK'
exceptions
no_free_session = 1
others = 2.
if sy-subrc eq 0.
"Z FM with standard one iside to be able to do commit & rollback
call function 'Z_BAPI_GOODSMVT_CREATE'
starting new task 'NEW_TASK'
performing check_return on end of task
exporting
goodsmvt_header = fs_goodsmvt_header
goodsmvt_code = fs_goodsmvt_code
testrun = space
* GOODSMVT_REF_EWM =
* IMPORTING
* GOODSMVT_HEADRET =
* MATERIALDOCUMENT =
* MATDOCUMENTYEAR =
tables
goodsmvt_item = ft_goodsmvt_item
* GOODSMVT_SERIALNUMBER =
return = ft_return
* GOODSMVT_SERV_PART_DATA =
* EXTENSIONIN =
.
wait until g_separatetask_done eq 'X' up to 120 seconds.
else.
message e027(14).
* Maximum number of sessions reached
endif.
* Rest of the code goes here
*-----------
* form that is called after task is complete
form check_return using taskname.
receive results from function 'Z_BAPI_GOODSMVT_CREATE'
tables
return = gt_return.
g_separatetask_done = 'X'.
endform. "check_return
Secure call of "starting new task" using RM_FREE_SESSION_CHECK
When you need to call a FM with option starting new task there is always a risk that user already has maximum number of sessions opened, so there is a risk that our call will be unsuccessful. There is a way to avoid such risk -> easily call FM RM_FREE_SESSION_CHECK or TH_USER_INFO directly to check if we can afford to open new session. If yes then we can call our FM in new task, if not then we can raise an error message and stop processing of the function we're currently doing. This is very helpful when you need to call a FM in new task inside user-exit.
Here is example of the code:
Enjoy!