07-24-2014 2:58 PM
Hello Everyone (and apologies if this is in the wrong location)!
I have a program that is using RSCRMBW_REPORT to extract data from a table. It seems that the program does not wait for the job to finish and simply starts the function module and proceeds with the remaining statements (check if g_t_return is initial, close rscrmbw).
As of right now, I've tried two methods of attempting to wait for the report to finish. The first method is below.
IF sy-subrc = 0.
WHILE ( l_status NE 'SUCC' ).
CALL FUNCTION 'RSCRMBW_BATCH_STATUS_CHECK'
EXPORTING
i_batchid = gv_batchid
IMPORTING
e_status = l_status
EXCEPTIONS
no_job_data = 1
inherited_error = 2
OTHERS = 3.
IF l_status = 'RUNN' OR l_status = ' ' OR l_status = 'SCHE'.
WAIT UP TO 30 SECONDS.
ENDIF.
ENDWHILE.
IF l_status = 'SUCC'.
IF sy-subrc = 0.
WRITE 'Query finished'.
MESSAGE i162(00) WITH 'Status' 'Green'. "Used to tell Process Chain to Continue
ENDIF.
ELSE.
CLEAR error.
CONCATENATE 'Job ' gv_batchid ' failed.' INTO error.
MESSAGE error TYPE 'E'.
MESSAGE e162(00) WITH 'Status' 'Red'. "Used to tell Process Chain to Fail
ENDIF.
ENDIF.
For small queries, this works- to an extent. Performance is very poor and I feel there is an issue with wait and the extraction, as it will work for some reports and not others.
The second solution I've tried is as follows :
CALL FUNCTION 'RSCRMBW_REPORT'
EXPORTING
i_mode = 'START'
i_reportuid = repuid
i_execmode = 'TABLE'
i_extract = extrname
i_clearextract = 'X' "replaces the contents of the target extraction table
i_packsize = packsize
i_split = split
IMPORTING
e_batchid = gv_batchid
e_jobname = gv_jobname
e_jobcount = gv_jobcount
e_done = gv_status
TABLES
e_t_return = g_t_return.
while gv_status = ' '.
endwhile.
Here, I was hoping to continue looping until the function module updates gv_status. However, I'm a little confused with the import on the function module. I'm not sure if this simply schedules the report to run in the background while proceeding with the rest of the program.
I've noticed that if I remove both and simply follow-up with my check and closing the report, the program ends and I assume the function module does as well. Does that simply work as an interrupt and stops the function module?
Any help is greatly appreciated!
Thanks and Regards,
Christian
(Apologies if my problem isn't clear. I'm working as an intern and this is my first exposure to ABAP!)
07-24-2014 5:54 PM
Hello,
Have you consider below approach.
CALL FUNCTION Remotefunction
STARTING NEW TASK Taskname
PERFORMING RETURN_FORM ON END OF TASK.
SAP Help Link
https://help.sap.com/saphelp_nw04/helpdata/en/22/0425ac488911d189490000e829fbbd/content.htm
Example.
report zrich_0001.
data: functioncall1(1) type c.
data: functioncall2(1) type c.
constants: done(1) type c value 'X'.
data: cstgdetail1 type bapicustomer_kna1.
data: cstgdetail2 type bapicustomer_kna1.
parameters: p_kunnr1 type kna1-kunnr,
p_kunnr2 type kna1-kunnr.
start-of-selection.
call function 'BAPI_CUSTOMER_GETDETAIL2'
starting new task 'FUNC1'
destination 'NONE'
performing set_function1_done on end of task
exporting
customerno = p_kunnr1.
call function 'BAPI_CUSTOMER_GETDETAIL2'
starting new task 'FUNC2'
destination 'NONE'
performing set_function2_done on end of task
exporting
customerno = p_kunnr2.
* Receive remaining asynchronous replies
wait until functioncall1 = done
and functioncall2 = done.
write:/ cstgdetail1.
write:/ cstgdetail2.
************************************************************************
* FORM FUNCTION1_DONE
************************************************************************
form set_function1_done using taskname.
receive results from function 'BAPI_CUSTOMER_GETDETAIL2'
importing
customergeneraldetail = cstgdetail1.
functioncall1 = done.
endform.
************************************************************************
* FORM FUNCTION2_DONE
************************************************************************
form set_function2_done using taskname.
receive results from function 'BAPI_CUSTOMER_GETDETAIL2'
importing
customergeneraldetail = cstgdetail2.
functioncall2 = done.
endform.
07-24-2014 5:54 PM
Hello,
Have you consider below approach.
CALL FUNCTION Remotefunction
STARTING NEW TASK Taskname
PERFORMING RETURN_FORM ON END OF TASK.
SAP Help Link
https://help.sap.com/saphelp_nw04/helpdata/en/22/0425ac488911d189490000e829fbbd/content.htm
Example.
report zrich_0001.
data: functioncall1(1) type c.
data: functioncall2(1) type c.
constants: done(1) type c value 'X'.
data: cstgdetail1 type bapicustomer_kna1.
data: cstgdetail2 type bapicustomer_kna1.
parameters: p_kunnr1 type kna1-kunnr,
p_kunnr2 type kna1-kunnr.
start-of-selection.
call function 'BAPI_CUSTOMER_GETDETAIL2'
starting new task 'FUNC1'
destination 'NONE'
performing set_function1_done on end of task
exporting
customerno = p_kunnr1.
call function 'BAPI_CUSTOMER_GETDETAIL2'
starting new task 'FUNC2'
destination 'NONE'
performing set_function2_done on end of task
exporting
customerno = p_kunnr2.
* Receive remaining asynchronous replies
wait until functioncall1 = done
and functioncall2 = done.
write:/ cstgdetail1.
write:/ cstgdetail2.
************************************************************************
* FORM FUNCTION1_DONE
************************************************************************
form set_function1_done using taskname.
receive results from function 'BAPI_CUSTOMER_GETDETAIL2'
importing
customergeneraldetail = cstgdetail1.
functioncall1 = done.
endform.
************************************************************************
* FORM FUNCTION2_DONE
************************************************************************
form set_function2_done using taskname.
receive results from function 'BAPI_CUSTOMER_GETDETAIL2'
importing
customergeneraldetail = cstgdetail2.
functioncall2 = done.
endform.
07-24-2014 6:40 PM
Thank you for your reply!
Unfortunately, it does not seem to work for me.
Modified code as seen below:
CALL FUNCTION 'RSCRMBW_REPORT'
starting new task 'Query'
destination 'NONE'
performing set_continue on end of task
EXPORTING
i_mode = 'START'
i_reportuid = repuid
i_execmode = 'TABLE'
i_extract = extrname
i_clearextract = 'X' "replaces the contents of the target extraction table
i_packsize = packsize
i_split = split
TABLES
e_t_return = g_t_return.
BREAK-POINT.
wait until Query = done.
*Check to See if L_status was turned with no errors
IF l_status = 'SUCC'.
IF sy-subrc = 0.
WRITE 'Query finished'.
MESSAGE i162(00) WITH 'Status' 'Green'. "Used to tell Process Chain to Continue
ENDIF.
ELSE.
CLEAR error.
CONCATENATE 'Job ' gv_batchid ' failed.' INTO error.
MESSAGE error TYPE 'E'.
MESSAGE e162(00) WITH 'Status' 'Red'. "Used to tell Process Chain to Fail
ENDIF.
*Close Report
CALL FUNCTION 'RSCRMBW_REPORT'
EXPORTING
i_mode = 'CLOSE'
i_reportuid = repuid.
END-OF-SELECTION.
*Form to Continue After Task Ends
FORM set_continue using Query.
receive results from function 'RSCRMBW_REPORT'.
Query = done.
l_status = 'SUCC'.
endform.
We were previously importing the variables e_batchid, e_jobname & e_jobcount from RSCRMBW_REPORT and then using a while loop calling BATCH_STATUS_CHECK to see if the job was still running. Since (at least to my knowledge) you can not import using task, I had to test by using the process chain responsible for extracting data. The chain ran synchronously and worked without error, however, no data was transported.
This leads me to believe that the report fm calls the a query which then runs in the background while the report function completes having done its job of starting the query. Is it correct to assume this? And if that is the case, how would I wait for the background process to finish before ending the program?
07-24-2014 7:33 PM
Hello,
Check below link on how to receive result from Asynchronous FM call.
Receiving Results from an Asynchronous RFC - RFC Programming in ABAP - SAP Library
07-24-2014 7:39 PM
Hello,
You might use the function module 'SPTA_PARA_PROCESS_START_2' for parallel processing. See demo report 'SPTA_PARA_DEMO_1' for details.
The function module internally uses ABAP objects, to do the handling.
07-24-2014 7:40 PM
07-25-2014 2:04 PM
Thank you very much! This is what I needed to help implement the solution you provided and make it work.