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

BAPI_OBJCL_CHANGE cannot commit ???

former_member1137458
Participant
0 Likes
1,764
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
    EXPORTING
      OBJECTKEY          = LV_OBJECTKEY
      OBJECTTABLE        = 'MCHA'
      CLASSNUM           = 'BATCH_01'
      CLASSTYPE          = '022'
    IMPORTING
      CLASSIF_STATUS     = CLASSIF_STATUS
    TABLES
      ALLOCVALUESNUMNEW  = IT_VALUES_NUM
      ALLOCVALUESCHARNEW = IT_VALUES_CHAR
      ALLOCVALUESCURRNEW = IT_VALUES_CURR
      RETURN             = IT_BAPIRET2.


  IF CLASSIF_STATUS = 1.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT   = 'X'
      IMPORTING
        RETURN = WA_BAPIRET2.

  ELSE.

     CALL FUNCTION 'C14ALD_BAPIRET2_SHOW'
       TABLES
         I_BAPIRET2_TAB       = IT_BAPIRET2
               .
  ENDIF.

IT_BAPIRET2 return error message:

Object is currently locked by user.

The assigment was not changed

currently, no user to change batch's characteristics.

How to solve this problem??

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,261

Hi,

I was confused with your question. Check whethere some body is editing the current entry. and change your code like this

The user name will be there in the return table. you can identify who is locking the entry. when you are passing WAIT = 'X'

there will not be any problem. It will be synchronous.


CALL FUNCTION 'BAPI_OBJCL_CHANGE'
    EXPORTING
      OBJECTKEY          = LV_OBJECTKEY
      OBJECTTABLE        = 'MCHA'
      CLASSNUM           = 'BATCH_01'
      CLASSTYPE          = '022'
    IMPORTING
      CLASSIF_STATUS     = CLASSIF_STATUS
    TABLES
      ALLOCVALUESNUMNEW  = IT_VALUES_NUM
      ALLOCVALUESCHARNEW = IT_VALUES_CHAR
      ALLOCVALUESCURRNEW = IT_VALUES_CURR
      RETURN             = IT_BAPIRET2.
 
 
  read table IT_BAPIRET2 with key type = 'E' transporting no fields.

   if sy-subrc ne 0.
     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT   = 'X'
      IMPORTING
        RETURN = WA_BAPIRET2.
   ELSE.
      CALL FUNCTION 'C14ALD_BAPIRET2_SHOW'
       TABLES
         I_BAPIRET2_TAB       = IT_BAPIRET2            .
  ENDIF.

6 REPLIES 6
Read only

Former Member
0 Likes
1,261

Hi cpliu903

You can try to put "wait up to..." statement after first fm. It should fix the problem .

Best Regards

Yossi Rozenberg

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,261

It should locked by you only. Please check the code , you just execute the bapi and if the classification status is not 1 you are doing something. In the mean time your process is not completed.

Read only

0 Likes
1,261

Loop at MAT_ITEM.

call -> BAPI_OBJCL_CHANGE

if classification status = 1

commit.

else

popup error.

endloop

This is whole flow. please see the image. that is capture from SM12

[http://img193.imageshack.us/img193/4613/lockyo.png|http://img193.imageshack.us/img193/4613/lockyo.png]

Read only

0 Likes
1,261

I had same problem.

The usual commit work and wait is not enought.

You should add more time for the operation to end it's processes and remove locks.

If you will add wait up to lets say 3 seconds at end of each loop run - you will see if this is the problem.

and then find your own logic to optimize the run time

Best Regards

Yossi

Read only

Former Member
0 Likes
1,261

Goto SM12 and check and delete any locks are present

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,262

Hi,

I was confused with your question. Check whethere some body is editing the current entry. and change your code like this

The user name will be there in the return table. you can identify who is locking the entry. when you are passing WAIT = 'X'

there will not be any problem. It will be synchronous.


CALL FUNCTION 'BAPI_OBJCL_CHANGE'
    EXPORTING
      OBJECTKEY          = LV_OBJECTKEY
      OBJECTTABLE        = 'MCHA'
      CLASSNUM           = 'BATCH_01'
      CLASSTYPE          = '022'
    IMPORTING
      CLASSIF_STATUS     = CLASSIF_STATUS
    TABLES
      ALLOCVALUESNUMNEW  = IT_VALUES_NUM
      ALLOCVALUESCHARNEW = IT_VALUES_CHAR
      ALLOCVALUESCURRNEW = IT_VALUES_CURR
      RETURN             = IT_BAPIRET2.
 
 
  read table IT_BAPIRET2 with key type = 'E' transporting no fields.

   if sy-subrc ne 0.
     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT   = 'X'
      IMPORTING
        RETURN = WA_BAPIRET2.
   ELSE.
      CALL FUNCTION 'C14ALD_BAPIRET2_SHOW'
       TABLES
         I_BAPIRET2_TAB       = IT_BAPIRET2            .
  ENDIF.