Hello,
For locking packages: http://help.sap.com/saphelp_erp2004/helpdata/en/f4/89c27a29c311d5b2be0050da3f31b1/content.htm
To lock the program.
Try below program. Execute it xecute this program in two sessions and also Also dequee it after program gets executed.
TYPE-POOLS:abap.
DATA:lock TYPE boolean.
PARAMETERS: pa_chr TYPE char12.
INITIALIZATION.
IF lock = abap_off.
PERFORM enqueue_program.
ELSE.
PERFORM dequeue_program.
ENDIF.
START-OF-SELECTION.
WRITE :/ 'Processing Starts'.
WRITE :/ 'Program locked'.
WRITE :/ 'This program will not be allowed to be executed by multiple'.
WRITE :/ 'Users in the same time'.
FORM enqueue_program .
CALL FUNCTION 'ENQUEUE_E_DSVAS_TRDIR'
EXPORTING
mode_trdir = 'X'
name = sy-repid
x_name = ' '
_scope = '2'
_wait = ' '
_collect = ' '
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
lock = abap_on.
ENDIF.
ENDFORM. " ENQUEUE_PROGRAM
FORM dequeue_program .
lock = abap_off.
CALL FUNCTION 'DEQUEUE_E_DSVAS_TRDIR'
EXPORTING
mode_trdir = 'X'
Thanks,
Abhijit