2007 Sep 07 12:33 AM
Hi ppl,
We have an RFC being called from external system. We need to terminate the Program execution in SAP after 30 seconds as thats the time limit set for returning the values from SAP. This termination may need to happen in the middle of a select query taking too much time. Please provide some inputs on this.
Really appreciate ur help on this on.
Thanks & Regards,
Bikash
2007 Sep 07 10:07 PM
Hey Bikash,
Check th report program
VBTST300, there are some function calls here which are used to stop transactions in update task etc... Looking into it.
<b>AS</b>
2007 Sep 07 4:37 AM
In the RFC, check for time wherever required
data : a type i,
b type i.
get run time field a.
select matnr from mara into table itab.
get run time field b.
c = b - a.
if c gt 30.
leave program.
endif.
2007 Sep 07 6:21 PM
Thanks a lot for the reply Kris,
But lets say the select statement itself takes around 1 minute. In that case it takes 1 min to go to the next code and leave the program. What we need to do is to terminate the program (Perhaps using a code external to the main program) immediately when the runtime exceeds 30 seconds.
Please put in ur inputs.
Thanks once again,
Bikash
2007 Sep 07 6:27 PM
This is an interestig requirement, there is a problem with this though, if you are doing an array fetch, meaning SELECT .... INTO TABLE, the execution is passed off to the database layer and the application is actually waiting for the response, so there is no way to interrupt this internally to the program. If you are using SELECT...... ENDSELECT, then this may be possible, but the selecting of the data would be slower due to the one record at a time execution.
Regards,
RIch Heilman
2007 Sep 07 7:44 PM
Rich,
Will native SQL help? Maybe an EXEC performing .. ENDEXEC.
We can probably break the select without too much of a performance overhead. Not too sure about this..
2007 Sep 07 7:57 PM
Thanks for the reply Rich,
What about calling a program in a separate task and putting a counter ther which kills the original program (this is just a thought), if at all such kind of thing is possible..
What about simulating the Stop Transaction option that we have on SAP Screen to terminate any session ( when we right click on the application toolbar) ?
Please throw in some light if things above bear weight.
Thanks & Regards,
Bikash
2007 Sep 07 8:06 PM
Just a thought..
Arent there any basis settings for time outs ??
2007 Sep 07 8:21 PM
I think you're trying to do this the hard way. Rather than trying to kill the process after it starts, do some checking (SELECT COUNT ( * ) or something like that). If there are too many records to process, don't continue).
Rob
2007 Sep 07 9:43 PM
Bikash,
If the requirement is like that then you may utilize the background processing.
You have to create a job using SM36 and in the RFC, submit (and release) the background job and keep on checking the time using the GET RUNTIME FIELD. If the processing takes longer than 30 seconds, you can exit the RFC otherwise send back the values e.g. from a z-table that can be filled by the background job submitted earlier.
Hope this helps.
2007 Sep 07 10:07 PM
Thanks guys for the reply,
Sanjeev, could you please tell in detail how this background job thing works. I didnt get it completely. i ll appreciate ur help.
Srihari, Dunno much abt basis settings but here the normal timeout setting is 30 minutes for a program. This RFC Interface is just a small piece of the project. do not sure if basis wud do any specific setting for this alone. would definitely check this though. Thx for the help.
Rob, the queries we have are mostly having non-unique keys, hence even select count would eat up a lot of time. So we avoided doing that. Thx for the reply though.
any more inputs guys?
Thanks,
Bikash
2007 Sep 07 10:07 PM
Hey Bikash,
Check th report program
VBTST300, there are some function calls here which are used to stop transactions in update task etc... Looking into it.
<b>AS</b>
2007 Sep 07 11:58 PM
Hi Bikash,
Find the code for terminating a session. What is being done is we get all the Work processes and for a particular use and if the WP is running more than 30 sec we terminate.
REPORT zztest_arun_sdn_1 .
TABLES: wpinfo.
DATA : opcode_wp_dump TYPE x VALUE 3,
with_cpu TYPE x VALUE 0.
*--Table to hold the work processes
DATA : wp_tabl TYPE STANDARD TABLE OF wpinfo WITH HEADER LINE.
CLEAR : wp_tabl, wp_tabl[].
CALL FUNCTION 'TH_WPINFO'
EXPORTING
with_cpu = with_cpu
TABLES
wplist = wp_tabl
EXCEPTIONS
OTHERS = 0.
LOOP AT wp_tabl WHERE wp_bname = 'Person's User ID '.
IF wp_tabl-wp_eltime GT 30. " If the elapsed time is more than 30 then terminate
CALL 'ThWpInfo' ID 'OPCODE' FIELD opcode_wp_dump
ID 'PID' FIELD wp_tabl-wp_pid.
ENDIF.
ENDLOOP.
<b>AS</b>
2007 Sep 08 12:34 AM
Thanks Arun,
This seems to work within SAP.. need to check if it works from an external system. Will get back soon.
Thanks & Regards,
Bikash
2007 Sep 10 4:14 AM
One thing you can do is to pass the queries to an background program
(you can have multiple performs in there so that all teh queries can come in the same program)
as soon as the job has started, start the timer
once you get the query data in the background program, export it to database like this
DATA: wa_indx TYPE indx.
EXPORT tab = itab TO DATABASE indx(xy) FROM wa_indx CLIENT
sy-mandt
ID 'QUERY01meanwhile, in the foreground program, after your required interval of time, import that same table from database as follows
IMPORT tab = itab FROM DATABASE indx(xy) TO wa_indx CLIENT sy-mandt
ID 'QUERY01'.
DELETE FROM DATABASE indx(xy)
CLIENT sy-mandt
ID 'QUERY01'if the imported table is initial or of the import fails, it means the query wasn't executed in the required amount of time, so you can end the program
make sure you delete from database as well, so that subsequent executions will not be affected
2007 Sep 08 12:34 AM
Hi Bikash,
interesting. I think the solution will be something like
When the RFC function is called, it must determine the process ID uniquely.
The start a function in separate task using a timer event (CL_GUI_TIMER) After timeout this should kill the process the same way you can kill a process from SAPGUI.
this is just roughly...
Regards,
Clemens
2007 Sep 10 4:16 AM
report yzm_t1 .
----
CLASS lcl_event_handler DEFINITION
----
class lcl_event_handler definition.
public section.
class-methods: on_finished for event finished of cl_gui_timer.
endclass. "lcl_event_handler DEFINITION
----
CLASS lcl_event_handler IMPLEMENTATION
----
class lcl_event_handler implementation.
method on_finished. "what happen while the time receive
leave .
endmethod . "on_finished
endclass. "lcl_event_handler IMPLEMENTATION
***********************************************************************
data timer type ref to cl_gui_timer.
data event_handler type ref to lcl_event_handler.
INITIALIZATION .
create object timer exporting parent = cl_gui_container=>screen0 .
timer->interval = 30 . "after 30 seconds your programe will be terminated .
set handler lcl_event_handler=>on_finished for timer.
call method timer->run.
**************************************************************************
START-OF-SELECTION .
write : 'it will be stop in 30 seconds .' .