Release tables locks
I have a program that has table locks for 6 tables. When the program is canceled by deleting the background process in SM50, the locks somehow are not released and they have to be manually deleted from SM12. Is there anything in the code that can detect a manual cancelation of the runnning background process in SM50 and also release the locks too? Or when this happens they have to be manually deleted from SM12. Thanks
I am under the impression that when a program ended correctly then all outstanding locks held by that program were released even if the appropriate dequeue was not issued, but when it was terminated by an abend or some other non-normal method they were not.
However, some one such as Wolfgang or John Jarboe should be able to answer this in better detail.
Regards
R
Is there anything in the code that can detect a manual cancelation of the runnning background process in SM50 and also release the locks too? Thanks
Thanks for the repsonse.
I wanted to rephrase my question in terms of whether if there is additional code that I myself can write to detect a non-normal method of stopping a background job, in this case deleting the background process from SM50 or an abend, and then write IF-ELSE condition to check for this non-normal method to allow the release of the locks automatically?
I would want to get sample code if there is a way to do this.
Thank you
You can probably cobble something together from this....
These are statuses of batch jobs in SM35:
*
* Batch statuses
*
c_batch_new like apql-status value ' ',
c_batch_processed like c_batch_new value 'F',
c_batch_batch like c_batch_new value 'R',
c_batch_incorrect like c_batch_new value 'E',
c_batch_in_error like c_batch_new value 'E',
c_batch_created like c_batch_new value 'C',
c_batch_background like c_batch_new value 'S',
c_batch_closed like c_batch_new value '*',
This is how you get at those statuses:
*
* Wait for the batch to complete.
*
Do.
Move '*' to w_status.
Select single qstate
into w_status
from apqi
where mandant = sy-mandt and
qid = w_qid.
*
* Whats the batch up to ?
*
Case w_status.
When c_batch_processed. Exit.
When c_batch_in_error.
Move False to g_results-result.
Move text-070 to g_results-msg.
Exit.
When c_batch_incorrect.
Move False to g_results-result.
Move text-070 to g_results-msg.
Exit.
EndCase.
Wait up to 1 seconds.
EndDo.
The following routine looks for locks in the enqueue tables. You should be able to pick this apart. The main function modules are ENQUEUE_READ and ENQUE_READ (yep - that's right.....)
*
* Get the current workprocess.
*
Call Function 'TH_GET_OWN_WP_NO'
Importing
Subrc = w_subrc
Wp_No = W_Wp
Wp_Pid = W_Pid
Exceptions
Others = 1.
*
* The group arguments (garg), vary from lock function to lock
* function therefore, we cannot recreate them here so send in a blank
* Garg and search for the values we have in the enque table sent back.
*
* Try for locks via RFC and CPIC
*
Move i_tabname to w_gname.
Call Function 'ENQUEUE_READ'
Exporting
Gname = w_gname
Importing
Number = w_lines
Subrc = w_subrc
Tables
Enq = t_seqg3
Exceptions
Communication_Failure = 1
System_Failure = 2
Others = 3.
*
* Nothing here - try via NFS
*
If w_subrc <> 0.
Call Function 'ENQUE_READ'
Exporting
Gname = w_gname
Importing
Number = w_lines
Subrc = w_subrc
Tables
Enq = t_seqg3
Exceptions
Others = 1.
*
If w_subrc <> 0
or sy-subrc <> 0.
Move c_no_lock to w_status.
EndIf.
EndIf.
*
* If we have anything here, scan the table for any of our entries...
*
* If additional arguments are needed, just add them to the argument
* list in the function header. The code will take these into account
*
If w_status = c_ok.
Loop at t_seqg3.
Do.
Move sy-index to w_argn.
Concatenate 'i_arg' w_argn into w_arg.
Assign (w_arg) to <f_arg>.
*
* Any errors here mean that we've run out of arguments to
* process, and everything was found to the point of the
* last argument, so set the 'FOUND' flag.
*
If sy-subrc = 0.
*
* This argument has a value ?
*
If <f_arg> = ''.
*
* No Value, so we've gone all through the arguments
* that were presented so it's a 'FOUND'.
*
* If the work process is different then this isn't the
* one we're after.
*
If w_wp = t_seqg3-gtwp.
Move True to w_found.
EndIf.
Exit.
Else.
*
* Check this argument. If it's in the garg string then
* continue onto the next one, otherwise exit this loop
* and get on with the next entry.
*
If t_seqg3-garg ns <f_arg>.
Exit.
Else.
*
* At least PART of the argument is here. As Colored
* fibers are just prefixed with CF but have the same
* main part number, check that it's not one of
* those that we have picked up.
*
If <f_arg> ns c_colored_prefix.
Concatenate c_colored_prefix <f_arg>
into w_acheck.
If t_seqg3-garg cs w_acheck.
Exit.
EndIf.
EndIf.
EndIf.
EndIf.
Else.
If w_wp = t_seqg3-gtwp.
Move True to w_found.
EndIf.
Exit.
EndIf.
*
* Exit this loop if we've found our key...
*
If w_found = True.
Exit.
EndIf.
EndDo.
*
If w_found = True.
Exit.
EndIf.
EndLoop.
*
* Have we got a lock ??
*
If w_found = false.
Move c_no_lock to w_status.
EndIf.
EndIf.
Hope this helps.
Regards
R