cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to Lock/Enqueue objects and keep it locked until we explicitly dequeue it.

nandini_borse
Participant
0 Likes
2,461

What is the best way to lock/enqueue an object even after the code that created the lock ends. Only an explicit dequeue call on that object should be able to unlock/dequeue that object.

I want to dequeue only if the transaction is completed. Currently my code is working in the case when we are in the process of

Any idea or solution would be greatly appreciated.

here is my code..

CALL FUNCTION 'ENQUEUE_READ'
  EXPORTING
*       GCLIENT               = SY-MANDT
    gname                 = 'ISEG'
*       GARG                  = ' '
*        guname                = sy-uname
*       LOCAL                 = ' '
*       FAST                  = ' '
*       GARGNOWC              = ' '
* IMPORTING
*       NUMBER                =
*       SUBRC                 = '0'
  TABLES
    enq                   = enq
  EXCEPTIONS
    communication_failure = 1
    system_failure        = 2
    OTHERS                = 3.
  IF sy-subrc <> 0.
** Implement suitable error handling here
  ENDIF.
  IF enq is INITIAL.

    CALL FUNCTION 'ENQUEUE_EZTESTLOCK'
      EXPORTING
       MODE_ISEG      = 'X'
       MANDT          = SY-MANDT
        iblnr          = lv_iblnr
        gjahr          = lv_gjahr
*       X_IBLNR        = ' '
*       X_GJAHR        = ' '
        _scope         = '3'
*       _WAIT          = ' '
*       _COLLECT       = ' '
      EXCEPTIONS
        foreign_lock   = 1
        system_failure = 2
        OTHERS         = 3.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*     EXPORTING
*       WAIT          =
*     IMPORTING
*       RETURN        =
              .
    ELSE.
    CONCATENATE  iblnr lv_gjahr   INTO ld_garg SEPARATED BY space.
    LOOP AT enq INTO wa_enq WHERE garg CS ld_garg.
      EXIT.
    ENDLOOP.
    CHECK sy-subrc EQ 0.
    IF wa_enq-guname EQ sy-uname.
      ls_entityset-zmessage = |User | && sy-uname && | blocks physical inventory document | && ld_garg .
      APPEND ls_entityset TO et_entityset.
      ENDIF.
***************OPTIONAL
    EXIT.

************End Enque

ENDIF.

Accepted Solutions (0)

Answers (1)

Answers (1)

KjetilKilhavn
Active Contributor
0 Likes

Scope '3' should do the trick, but I have experienced similar problems. Is your program executing without GUI context, e.g. as a web service implementation or in a background job?