Skip to Content
0
Dec 01, 2008 at 11:15 AM

Which lock should I use for material batch characteristics?

596 Views

Hi All,

I am creating material batches in a custom program in a loop (e.g. 3 batches, their characteristics plus the associated goods movements).

Problem I have is that sometimes it works, sometimes it doesn't.

When it fails the message I get is:

"Object is currently locked by user Object is currently locked by user"

(yes, twice on the same line).

The section of code that does the batch changing is below. Can you see anything wrong with this?

The error message above comes from the FM 'BAPI_OBJCL_CHANGE'.

When I debug, it never fails so it looks like the timing is the issue....but the loop below should never finish until the lock is successful.

      WHILE l_while IS INITIAL.
* potentially infinite loop - remember to change

        CALL FUNCTION 'ENQUEUE_EMMCHA'
             EXPORTING
                  matnr          = zrp_batchscreen-rec_matnr
                  werks          = zrp_batchscreen-rec_plant
                  charg          = l_batch
             EXCEPTIONS
                  foreign_lock   = 1
                  system_failure = 2
                  OTHERS         = 3.
        IF sy-subrc = 0.
          l_while = 'X'.
        ENDIF.
      ENDWHILE.

      IF sy-subrc = 0.
        CALL FUNCTION 'BAPI_OBJCL_CHANGE'
             EXPORTING
                  objectkey          = l_objkey
                  objecttable        = 'MCHA'
                  classnum           = l_class
                  classtype          = '022'
             TABLES
                  allocvaluesnumnew  = x_numtab
                  allocvaluescharnew = x_chatab
                  allocvaluescurrnew = x_curtab
                  return             = x_rettab.
      ELSE.
        EXIT.
      ENDIF.

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
           EXPORTING
                wait   = 'X'
           EXCEPTIONS
                OTHERS = 0.


      CALL FUNCTION 'DEQUEUE_EMMCHA'
           EXPORTING
                matnr = zrp_batchscreen-rec_matnr
                charg = l_batch.

Is ENQUEUE_EMMCHA the correct lock for batches?

Our batches are created based on material/plant/st location, which is MCHB, but MCHA and MCH1 are also populated.

There is no lock for MCHB so I am using MCHA's lock.

Is this okay???

Thanks,

Kroc.