cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP - SAP PS WBS Element still locked or not in DB after BAPI + WAIT + ENQUEUE

Marçal_Oliveras
Active Contributor
0 Kudos

Hi,

I created a method to add a WBS element to an existing project from a WBS template project. This method has an optional indicator to also copy the "Easy Cost Planning" or cost estimation from the reference WBS.

The cost can only be copied after the new WBS exists, which it's done with the BAPI_PROJECT_MAINTAIN. After the call to the BAPI I execute the BAPI_TRANSACTION_COMMIT with the WAIT parameter set and I found out that this was not enought to ensure that all the changes are commited to the database.

Then I added the method below that uses the ENQUEUE_EC_PROJS function to ensure that the WBS is really not locked. But surprisingly this is not working and the copy cost part is failing because of the data being locked or non-existing in the DB. If I execute slowly with the debugger everything works.

My last option is to just add a fix WAIT UP to X SECONDS but I don't like the idea at all. Can you think of a better solution?

METHOD wait_for_wbs_unlocked.

      DATA: lv_counter TYPE i.
      LOOP AT it_wbs_element ASSIGNING FIELD-SYMBOL(<ls_wbs_element>).

        WHILE lv_counter < zcl_XXX=>lock_wait_limit. "Wait "limit" seconds

          CALL FUNCTION 'ENQUEUE_EC_PROJS'
            EXPORTING
              mode_proj_enq = 'S' "Read-lock
              typ           = 'P' "P=WBS
              pspid         = <ls_wbs_element>-wbs_element
              _scope        = '3'
              _wait         = abap_true "This should already wait 5 seconds...
            EXCEPTIONS
              OTHERS        = 1.
          IF sy-subrc = 0.
            CALL FUNCTION 'DEQUEUE_EC_PROJS'
              EXPORTING
                mode_proj_enq = 'S' "Read-lock
                typ           = 'P' "P=WBS, D=Project
                pspid         = <ls_wbs_element>-wbs_element
                _scope        = '3'.
            lv_counter = zcl_XXX=>lock_wait_limit.
          ELSE.
            IF lv_counter = zcl_XXX=>lock_wait_limit.
              "RAISE EXCEPTION
            ELSE.
              ADD 1 TO lv_counter.
              WAIT UP TO 1 SECONDS.
            ENDIF.
          ENDIF.
        ENDWHILE.
      ENDLOOP.
    ENDMETHOD.

Accepted Solutions (1)

Accepted Solutions (1)

raymond_giuseppi
Active Contributor

Could you try to replace the ENQUEUE call with a SELECT FROM PRPS, the WAIT option should insure the lock is released if no exotic option was used in the ENQUEUE call.

Marçal_Oliveras
Active Contributor
0 Kudos

Thanks Raymond,

I already tested this but it was failing sometimes. But I didn't think about the simple solution of combining the SELECT PRPS + ENQUEUE... This seems to work so far with all the tests I've done.

Answers (0)