Skip to Content
avatar image
Former Member

Change Document-Status in BADI --> Short Dump

Hi,

is there any solution for changing the Documentstatus in BADI?

I try this:

METHOD if_ex_document_main01~after_save.

   BREAK-POINT.

   DATA: dokexistiert TYPE bapi_doc_aux-flag.

   CALL FUNCTION 'BAPI_DOCUMENT_EXISTENCECHECK'

     EXPORTING

       documenttype            = draw-dokar

       documentnumber          = draw-doknr

       documentpart            = draw-doktl

       documentversion         = draw-dokvr

    IMPORTING

*   DOCUMENTISDELETED       =

      documentexists          = dokexistiert

*   RETURN                  =

             .

   IF dokexistiert = 'X'.

     DATA: ls_return_commit TYPE bapiret2.

     IF draw-dokst = 'IA'.

       DATA: lf_doctype TYPE bapi_doc_draw-documenttype,

             lf_docnumber TYPE bapi_doc_draw-documentnumber,

             lf_docpart TYPE bapi_doc_draw-documentpart,

             lf_docversion TYPE bapi_doc_draw-documentversion,

             lf_statusextern TYPE bapi_doc_draw-statusextern,

             lf_statusintern TYPE bapi_doc_draw-statusintern,

             lf_statuslog TYPE bapi_doc_draw-statuslog,

             ls_return TYPE bapiret2.

       lf_docnumber = draw-doknr. "'Documentnumber'.

       lf_doctype = draw-dokar." 'DRW'.

       lf_docversion = draw-dokvr." '00'.

       lf_docpart = draw-doktl." '000'.

       lf_statusintern = 'FR'.

       CALL FUNCTION 'BAPI_DOCUMENT_SETSTATUS'

       EXPORTING:

         documenttype = lf_doctype

         documentnumber = lf_docnumber

         documentpart = lf_docpart

         documentversion = lf_docversion

         statusextern = lf_statusextern

         statusintern = lf_statusintern

         statuslog = lf_statuslog

       IMPORTING:

         return = ls_return.

*    Errors occurred ??

***  IF ls_return-TYPE CA 'EA'.

***    ROLLBACK WORK.

***    MESSAGE ID '26' TYPE 'I' NUMBER '000'

***    WITH ls_return-MESSAGE.

***  ELSE.

***    COMMIT WORK.

***  ENDIF.

     ENDIF.

   ENDIF. "dokument existiert

ENDMETHOD.

When i activate the badi, i get a dump... (file attached).

Thankfull for every solution.

Regards

Sebastian

DMS_dump.jpg (411.1 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Nov 10, 2015 at 02:27 PM

    Hi Sebastian,

    BAdI AFTER_SAVE is executed in update task. So if you call the BAPI_DOCUMENT_SETSTATUS directly within the BAdI you get the shortdump because you will start another update in the update task.

    So you have to start the status-processing asynchronously. The execution must happen after the original update task has finished.

    There are following possible solutions

    • raise batch event using  cl_batch_event=>raise and start an event-periodic batch job. you can transfer the document key as parameter. This will take the most time and should ensure that document is updated.
    • call function in separate task/background task.

    Hope this helps.

    Regards,

    Benedikt

    Add comment
    10|10000 characters needed characters exceeded