sap databaselocking(scridb)

Upload: wyfwong

Post on 14-Apr-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 SAP DatabaseLocking(Scridb)

    1/4

    Page 1 of4

    SAP Database Locking

    SAP provides you with the ability to restrict access to data while the table is being updated. Thisis fairly simple to implement via the use of a lock object (Created in SE11).

    Step 1 - Create Lock object (SE11)

  • 7/29/2019 SAP DatabaseLocking(Scridb)

    2/4

    Page 2 of4

    Step 2 - ABAP code to lock table entriesAdd the following code in-order to create the table lock. This function module must be calledbefore any update takes place. If a lock has already been taken out it will display the appropriatemessage.

    CALL FUNCTION 'ENQUEUE_EZ_ZTABLENAME'

    EXPORTINGmode_ZTABLENAME = 'E' "E = Write Lock, S = Read Lock, X =Exclusive not cumulative

    mandt = sy-mandtKEYFIELD1 = "ValueKEYFIELD2 = "ValueKEYFIELD3 = "Value

    ...* X_KEYFIELD1 = ' '* X_KEYFIELD2 = ' '* X_KEYFIELD3 = ' '

    ...* _SCOPE = '2'* _WAIT = ' '

    * _COLLECT = ' '* If exceptions are not used, message is displayed within FM

    EXCEPTIONSFOREIGN_LOCK = 1SYSTEM_FAILURE = 2OTHERS = 3.

    IF sy-subrc 0.* Retrieve message displayed within Function Module

  • 7/29/2019 SAP DatabaseLocking(Scridb)

    3/4

    Page 3 of4

    message id sy-msgidtype 'I'number sy-msgnowith sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ***************OPTIONAL - Get more details of existing lock* Also within here you can also use ENQUEUE_READ to find out more detailsabout the existing lock

    data: it_enq type STANDARD TABLE OF SEQG3,wa_enq like line of it_enq,ld_gname type SEQG3-GNAME,ld_garg type SEQG3-GARG,

    ld_gname = 'ZTABLENAME'. "This is the name of the lock object as shown intcode SM12

    CALL FUNCTION 'ENQUEUE_READ'EXPORTINGGCLIENT = SY-MANDTGNAME = ld_gname "Lock opject nameGUNAME = '*' "User name, default is SY-UNAME but

    need to use * to return locks for all usersTABLESENQ = it_enq

    EXCEPTIONSCOMMUNICATION_FAILURE = 1SYSTEM_FAILURE = 2OTHERS = 3.

    "will need to check values returned by FM to check what values are neededto build ld_garg value

    concatenate sy-mandt KEYFIELD1 KEYFIELD2 KEYFIELD3 into ld_garg .loop at it_enq into wa_enq where garg cs ld_garg.exit.

    endloop.check sy-subrc eq 0.if wa_enq-guname eq sy-uname."Entry already being updated by you

    else."Entry already being updated by someone else

    endif.***************OPTIONAL

    EXIT.ENDIF.

    Step 3 - ABAP code to Remove table lock(s)The following code will remove the lock for the specific table entries.

    CALL FUNCTION 'DEQUEUE_EZ_ZTABLENAME'EXPORTING

    MODE_ZTABLENAME = 'E'MANDT = SY-MANDTmandt = sy-mandtKEYFIELD1 = "ValueKEYFIELD2 = "ValueKEYFIELD3 = "Value

    ...

  • 7/29/2019 SAP DatabaseLocking(Scridb)

    4/4

    Page 4 of4

    * X_KEYFIELD1 = ' '* X_KEYFIELD2 = ' '* X_KEYFIELD3 = ' '

    ...* _SCOPE = '3'* _SYNCHRON = ' '* _COLLECT = ' '

    .