Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Lock object not working

Former Member
0 Likes
4,762

Hi Experts,

I tried to create a program that locks the database table BKPF by using lock object EFBKPF.

I only called the FM like this:

call function 'ENQUEUE_EFBKPF'

exporting

mandt = sy-mandt.

if sy-subrc eq 0.

....

endif.

I executed the program, breakpoint at sy-subrc ( = 0), and I can also see in SM12 that the table BKPF was successfully locked. However, when I try to create and post an FI document (FB01) (while it was still locked), I can still save and post the document, and an entry in BKPF was inserted.

I wonder if I'm doing something wrong here. ABAP Geniuses, please advise.

Regards,

Joyie

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,789

HI Joyie,

If your are using More docu from an ITAB then you need loop through them

call function 'ENQUEUE_EFBKPF' " in SE37 Enter this FM and Find Where used List there are many Examples
       exporting
            mode_bkpf      = 'E' " or 'X' here
            mandt          = sy-mandt
            bukrs          = bukrs
            belnr          = docno
            gjahr          = gjahr
       exceptions
            foreign_lock   = 1
            system_failure = 2
            others         = 3.
  case sy-subrc .
    when 1.
      message e130 with  'Data blocked by user'  sy-msgv1 .
    when 2.
      message e130 with 'Failed to read lock table' .
    when 3.
      message e130 with 'Error in locking table '.
  endcase.

" Or create your own Lock Object in SE11 for the DB table and the Key fields  and before you read the Table you can use this   
"   Lock Object and then do SELECT   Data base 


  call function 'DEQUEUE_EFBKPF'
       exporting
            mode_bkpf = 'E' " or 'X' Here
            mandt     = sy-mandt
            bukrs     = bukrs
            belnr     = belnr
            gjahr     = gjahr
*         X_BUKRS   = ' '
*         X_BELNR   = ' '
*         X_GJAHR   = ' '
*         _SCOPE    = '3'
*         _SYNCHRON = ' '
       exceptions
            others    = 1.

Cheerz

Ram

10 REPLIES 10
Read only

Former Member
0 Likes
2,789

at what point you are using this lock object

one thing you have to note

before using lock object

check for enqueue_read FM to check that object which you are going to lock is locked

if it is locked then throw a error message saying that the object is been locked

do u want insert some entries in BKPF is it why you are using this?

cheers

S.Janagar

Edited by: Janagar Sundaramoorthy Nadar on Apr 12, 2010 7:05 AM

Read only

0 Likes
2,789

Hi Janagar,

Thank you for your reply.

I just check the SM12 before and after the call of Enqueue FM, and I see that it has successfully locked the table. No other program/transaction has locked the table.

The purpose for locking the table is because we want to read/select the records (not update/insert), and make sure that while doing that, nobody has inserted/updated any record into the table yet.

Thanks again in advance for your help.

Regards,

Joyie

Read only

Former Member
0 Likes
2,789

Hi,

Give the Break-point in IF SY-SUBRC = 0.

then open another session and debug it.

u ll get the proper error message.

Regards,

Pravin

Read only

0 Likes
2,789

Hi Pravin,

As mentioned in my first post, I put at breakpoint at sy-subrc, and it is returning 0.

While the the enqueue statement is still successful, and SM12 also shows that the database table is locked, I run FB01 to post an FI document. I have successfully posted the FI document, and a record is inserted at BKPF.

I really dont know what the problem is.

Regards,

Joyie

Read only

Former Member
0 Likes
2,789

If you are updating the records in BKPF, use Enqueue and Dequeue with primary key.

CALL FUNCTION 'ENQUEUE_EFBKPF'
                EXPORTING
                  MODE_BKPF       = 'E'
                  MANDT           = SY-MANDT
                 BUKRS           = <comp code>
                  BELNR           = <doc no>
                  GJAHR           = <fiscal year>

If you want to create new FI document, I think you don't need to lock the table BKPF, as it will be taken care automatically.

Regards

Read only

Former Member
0 Likes
2,790

HI Joyie,

If your are using More docu from an ITAB then you need loop through them

call function 'ENQUEUE_EFBKPF' " in SE37 Enter this FM and Find Where used List there are many Examples
       exporting
            mode_bkpf      = 'E' " or 'X' here
            mandt          = sy-mandt
            bukrs          = bukrs
            belnr          = docno
            gjahr          = gjahr
       exceptions
            foreign_lock   = 1
            system_failure = 2
            others         = 3.
  case sy-subrc .
    when 1.
      message e130 with  'Data blocked by user'  sy-msgv1 .
    when 2.
      message e130 with 'Failed to read lock table' .
    when 3.
      message e130 with 'Error in locking table '.
  endcase.

" Or create your own Lock Object in SE11 for the DB table and the Key fields  and before you read the Table you can use this   
"   Lock Object and then do SELECT   Data base 


  call function 'DEQUEUE_EFBKPF'
       exporting
            mode_bkpf = 'E' " or 'X' Here
            mandt     = sy-mandt
            bukrs     = bukrs
            belnr     = belnr
            gjahr     = gjahr
*         X_BUKRS   = ' '
*         X_BELNR   = ' '
*         X_GJAHR   = ' '
*         _SCOPE    = '3'
*         _SYNCHRON = ' '
       exceptions
            others    = 1.

Cheerz

Ram

Read only

0 Likes
2,789

Thanks so much for your reply, Ram/Vinod.

I just realized that the above function works on FB02 (changing/updating the record).

But I also want to block user from inserting a new record (FB01).

That is, I can successfully insert new record, but I cant update/change an existing one. Is there a way for me to do that?

      • I mean, is there a way for me to block a user from inserting a new record as well?

Thank you so much for your help.

Regards,

Joyie

Edited by: joyie0823 on Apr 12, 2010 8:54 AM

Read only

0 Likes
2,789

HI Joyie,

" To Control the FB01 Tcode from creating/Inserting a Document you the below FM

  call function 'ENQUEUE_EFBVOR'
       exporting
*            bvorg        = bvorg " This is in BVOR Table and I am not sure how to use it
" Put a Debug in FB01 Tcode and find how this Value can be assigned.
" Go to Main Program of FB01 and find this FM and put a break Point
            mandt     = mandt
            belnr        = x_belnr
            bukrs       = bukrs
            gjahr       = gjahr

       exceptions
            foreign_lock = 1
            others       = 2.
  if sy-subrc = 1.
message 'Another User locked this Document' type 'E'
  elseif sy-subrc = 2.
    message .
  endif.

Cheerz

Ram

Read only

0 Likes
2,789

Hi Ram,

THanks so much for your help. But I can still insert new records.

I am thinking of locking the transaction FB01 instead, is there a function module for that? I've checked that there is an FM called RSAU_WRITE_SM01_LOG, but our SAP is release 4.5B, and there is no such FM. I'm thinking of just doing a call transaction for SM01, but it looks messy to do that.

Regards,

Joyreen

Read only

Former Member
0 Likes
2,789

Hi All,

We've decided to use DB_SET_ISOLATION_LEVEL instead and maybe lock the transaction too.

I've found the answer at this post:

Thanks all for your help.

Edited by: joyie0823 on Apr 13, 2010 4:51 AM