-1

I am trying to delete an equipment class using BAPI_OBJCL_DELETE but when running in debug mode, the class gets deleted but it doesn't get deleted in normal mode. I am using below program to delete it. I have tried COMMIT WORK and BAPI_TRANSACTION_COMMIT.

May you provide some insight on this problem?

Program:

    Get list of current class assignments.
    CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
      EXPORTING
        classtype          = cv_klart
        object             = iv_objnum
        objecttable        = cv_object_tab
      TABLES
        t_class            = lt_class
        t_objectdata       = lt_obj
      EXCEPTIONS
        no_classification  = 1
        no_classtypes      = 2
        invalid_class_type = 3
        OTHERS             = 4

    IF sy-subrc EQ 0 AND lt_class IS NOT INITIAL.

      lv_objectkey = iv_objnum.

      "Delete all existing classes.
      LOOP AT lt_class INTO ls_class.

        CALL FUNCTION 'BAPI_OBJCL_DELETE'
          EXPORTING
*           OBJECTKEY            =
            objecttable          =
            classnum             =
            classtype            =
*           CHANGENUMBER         =
*           KEYDATE              = SY-DATUM
*           OBJECTKEY_LONG       =
          TABLES
            return               =
                  .
        CALL FUNCTION 'BAPI_OBJCL_DELETE'
          EXPORTING
            objectkey   = lv_objectkey
            objecttable = cv_object_tab
            classnum    = ls_class-class
            classtype   = cv_klart
          TABLES
            return      = lt_return.

        IF sy-subrc NE 0.
          APPEND LINES OF lt_return TO et_messages.
        ENDIF.

        WAIT UP TO 1 SECONDS.

        COMMIT WORK.

      ENDIF.

      WAIT UP TO 1 SECONDS.

    ENDLOOP.

    WAIT UP TO 1 SECONDS.

  ENDIF.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 1
    Your code doesn't compile for obvious reasons (syntax errors), please fix it so that people can test it. Please post a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). Please describe in details what the "normal mode" is. Deletion may fail according to many reasons described in the `return` parameter. You should never use `commit work` with BAPI, always use `bapi_transaction_commit` (possibly with parameter `wait = 'X'`). `WAIT UP` is to be used only if your ABAP trace reveals that there are asynchronous calls which require to end before next call. – Sandra Rossi Aug 20 '23 at 06:17
  • dont call the function twice. the first time with no arguments. – phil soady Aug 20 '23 at 13:24

1 Answers1

0

You are looking for errors by checking IF sy-subrc NE 0.. This doesn't work on BAPIs. It only works on function modules that communicate error conditions via EXCEPTIONS. Which BAPI function modules never do. BAPIs communicate error conditions via massages through their return tables of type BAPIRET2.

So what you need to do is check if a BAPI worked successfully, do a

READ TABLE lt_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
   " The BAPI returned at least one error message
ENDIF.

Why doesn't this BAPI work in your particular case? There could be a million reasons. And because BAPIs usually also perform any customer events that are supposed to be called for a specific action, the reason might be some custom code that can only be found in your system. But the error message in the return table might provide you some insight on what the problem could be.

Philipp
  • 67,764
  • 9
  • 118
  • 153