‎2009 May 13 12:31 PM
hi friends,
i know this is a general question, but this isn't working in my system.
i would like to apply lock to a custom transaction. for this i applied a lock to a custom table which i'm reading and writing and the type i used is exclusive lock. when i logged the tcode with another user i executed both , then the tcode worked with both the users simultanious. i believe am i missing any thing.
scenario to be done.
at a time only one session should be opened for one user only i.e. if the another user or same user opens another session it should give error 'table has been locked or t code is locked'.
please suggest which type do i use and where do i apply. i used enqueue at start of dialog program and dequeue at exit of the dialog program.
thanks & regards,
kat.
Edited by: kat k on May 13, 2009 1:31 PM
‎2009 May 13 12:39 PM
Hi ,
if you want to get the error table has been loacked you need to create a lock object for the tables used in the Custom transaction...
and you need to lock the tables when ever you are editing..
and second way is..
if you want to lock the t-code ..
use the Below function modules...
" Locking the transaction in SM01
PERFORM bit-set USING tstc-cinfo 6.
CALL FUNCTION 'RSAU_WRITE_SM01_LOG'
EXPORTING
tcode = tstc-tcode "Enter custom t-code to unlock
lock = 'X'.
IF sy-subrc <> 0.
ENDIF.
" UNLocking the transaction in SM01
PERFORM bit-reset USING tstc-cinfo 6.
CALL FUNCTION 'RSAU_WRITE_SM01_LOG'
EXPORTING
tcode = tstc-tcode "Enter custom t-code to Lock
unlock = 'X'.
IF sy-subrc <> 0.
ENDIF.
FORM bit-set USING hexval TYPE x
bitpos TYPE p.
CASE bitpos.
WHEN 8. IF hexval O x80. ELSE. hexval = hexval + x80. ENDIF.
WHEN 7. IF hexval O x40. ELSE. hexval = hexval + x40. ENDIF.
WHEN 6. IF hexval O x20. ELSE. hexval = hexval + x20. ENDIF.
WHEN 5. IF hexval O x10. ELSE. hexval = hexval + x10. ENDIF.
WHEN 4. IF hexval O x08. ELSE. hexval = hexval + x08. ENDIF.
WHEN 3. IF hexval O x04. ELSE. hexval = hexval + x04. ENDIF.
WHEN 2. IF hexval O x02. ELSE. hexval = hexval + x02. ENDIF.
WHEN 1. IF hexval O x01. ELSE. hexval = hexval + x01. ENDIF.
WHEN OTHERS.
ENDCASE.
ENDFORM. "bit-set
FORM bit-reset USING xval TYPE x
pos TYPE p.
CASE pos.
WHEN 8. IF xval O x80. xval = xval - x80. ENDIF.
WHEN 7. IF xval O x40. xval = xval - x40. ENDIF.
WHEN 6. IF xval O x20. xval = xval - x20. ENDIF.
WHEN 5. IF xval O x10. xval = xval - x10. ENDIF.
WHEN 4. IF xval O x08. xval = xval - x08. ENDIF.
WHEN 3. IF xval O x04. xval = xval - x04. ENDIF.
WHEN 2. IF xval O x02. xval = xval - x02. ENDIF.
WHEN 1. IF xval O x01. xval = xval - x01. ENDIF.
WHEN OTHERS.
ENDCASE.
ENDFORM. "bit-reset
Regards,
Prabhudas
Edited by: Prabhu Das on May 13, 2009 5:09 PM
‎2009 May 13 1:46 PM
hi prabu,
i really don't understand , is it really necessary to fill hex val in perform.
could you please expalin logic in perform.
thanks!!
kat
‎2009 May 13 12:41 PM
Hi,
Here is an example on the Table : VTTK (Shipment number), where, assume we create a Lock object on the field TKNUM (Shipment Number).
Our aim is, at one time, no two persons can open a Shipment.
Here the code goes:
CALL FUNCTION 'ENQUEUE_EYVTTKTKNUM'
EXPORTING
mode_vttk = 'E'
mandt = sy-mandt
tknum = v_tknum
_scope = '2'
_wait = ' '
_collect = ' '
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
* Getting the UserId of the Locked Transport Number
wg_lock_user = sy-msgv1.
Also Note that the system variable, sy-msgv1 will have the <User name>.
We can even display the UserName also dynamically.
Based on teh above SY-SUBRC, we can give Error Message for restricting another user from using this Shipment Number.
Rgds,
Ramani N
Edited by: Ramani Nagarajan on May 13, 2009 1:41 PM
‎2009 May 13 12:43 PM
Hi,
Make a COMMIT WORK after adding a lock to the customer table.
Issa
‎2009 May 14 12:03 PM
the only possible way to lock a tcode . accordingg to my research is to use TSTC table while creating enqueue and dequeue FM.
and i found success in my research.
thankyou for sharing.
kat