Skip to Content
author's profile photo Former Member
Former Member

What is wrong in this code?

This code, has to set the status of the document as 'AD' , then change some data save it and again set the status to RE. WHen i run this in debug mode , it actually updates everything , but when i dont go in the debug mode , it just updates the first status set to 'AD' and then doesnt do anything ...any insights why ?

CALL FUNCTION 'BAPI_DOCUMENT_SETSTATUS'

EXPORTING

DOCUMENTTYPE = 'SWD'

DOCUMENTNUMBER = ITAB-DOKNR

DOCUMENTPART = ITAB-DOKAR

DOCUMENTVERSION = ITAB-DOKVR

  • STATUSEXTERN = ' '

STATUSINTERN = 'AD'

  • STATUSLOG = ' '

IMPORTING

RETURN = RETURN

.

*

  • CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

  • .

  • IF SY-SUBRC = 0.

    COMMIT WORK.

    BAPI_DATA-AUTHORITYGROUP = 'VIEW'.

    BAPI_DATA_X-AUTHORITYGROUP = 'X'.

    CALL FUNCTION 'BAPI_DOCUMENT_CHANGE2'

    EXPORTING

    DOCUMENTTYPE = 'SWD'

    DOCUMENTNUMBER = itab-doknr

    DOCUMENTPART = itab-dokar

    DOCUMENTVERSION = itab-dokvr

    DOCUMENTDATA = BAPI_DATA

    DOCUMENTDATAX = BAPI_DATA_X

    • HOSTNAME =

    • DOCBOMCHANGENUMBER =

    • DOCBOMVALIDFROM =

    • DOCBOMREVISIONLEVEL =

    • SENDCOMPLETEBOM = ' '

    • PF_FTP_DEST = ' '

    • PF_HTTP_DEST = ' '

    • CAD_MODE = ' '

    IMPORTING

    RETURN = RETURN.

    • TABLES

    • CHARACTERISTICVALUES =

    • CLASSALLOCATIONS =

    • DOCUMENTDESCRIPTIONS =

    • OBJECTLINKS =

    • DOCUMENTSTRUCTURE =

    • DOCUMENTFILES =

    • LONGTEXTS =

    • COMPONENTS =

    .

    IF SY-SUBRC = 0.

    COMMIT WORK.

    ELSE.

    ROLLBACK WORK.

    ENDIF.

    CALL FUNCTION 'BAPI_DOCUMENT_SETSTATUS'

    EXPORTING

    DOCUMENTTYPE = 'SWD'

    DOCUMENTNUMBER = ITAB-DOKNR

    DOCUMENTPART = ITAB-DOKAR

    DOCUMENTVERSION = ITAB-DOKVR

    • STATUSEXTERN = ' '

    STATUSINTERN = 'RE'

    • STATUSLOG = ' '

    IMPORTING

    RETURN = RETURN

    .

    if sy-subrc = 0 .

    commit work.

    else.

    rollback work.

    endif.

    ELSE.

    ROLLBACK WORK.

    ENDIF.

    ENDLOOP.

    Add comment
    10|10000 characters needed characters exceeded

    2 Answers

    • Best Answer
      Posted on Aug 03, 2006 at 07:58 PM

      Use the BAPI_TRANSACTION_COMMIT which you commented out and pass 'X' to the WAIT parameter. Alternatively, use COMMIT WORK AND WAIT. Your problem seems to be with not waiting long enough until the previous commits are done.

      Also, do not check for sy-subrc = 0 after the BAPI calls. All errors are returned to you in the RETURN parameter. So you have to see if RETURN contains a message of type 'E' and then commit or rollback accordingly.

      CALL FUNCTION 'BAPI_DOCUMENT_SETSTATUS'
        EXPORTING
          documenttype = 'SWD'
          documentnumber = itab-doknr
          documentpart = itab-dokar
          documentversion = itab-dokvr
      *   STATUSEXTERN = ' '
          statusintern = 'AD'
      *   STATUSLOG = ' '
        IMPORTING
          return = return.
      
      IF return-type <> 'E' AND
         return-type <> 'A'.
      *-- successful
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait   = 'X'
          IMPORTING
            return = return.
      
      *-- call the next BAPI
        bapi_data-authoritygroup = 'VIEW'.
        bapi_data_x-authoritygroup = 'X'.
      
        CALL FUNCTION 'BAPI_DOCUMENT_CHANGE2'
          EXPORTING
            documenttype = 'SWD'
            documentnumber = itab-doknr
            documentpart = itab-dokar
            documentversion = itab-dokvr
            documentdata = bapi_data
            documentdatax = bapi_data_x
      *     HOSTNAME =
      *     DOCBOMCHANGENUMBER =
      *     DOCBOMVALIDFROM =
      *     DOCBOMREVISIONLEVEL =
      *     SENDCOMPLETEBOM = ' '
      *     PF_FTP_DEST = ' '
      *     PF_HTTP_DEST = ' '
      *     CAD_MODE = ' '
          IMPORTING
            return = return.
      *   TABLES
      *     CHARACTERISTICVALUES =
      *     CLASSALLOCATIONS =
      *     DOCUMENTDESCRIPTIONS =
      *     OBJECTLINKS =
      *     DOCUMENTSTRUCTURE =
      *     DOCUMENTFILES =
      *     LONGTEXTS =
      *     COMPONENTS =
        .
      
        IF return-type <> 'E' AND
           return-type <> 'A'.
      *-- successful
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait   = 'X'
            IMPORTING
              return = return.
        ELSE.
      *-- fail
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
            IMPORTING
              return = return.
          EXIT.
        ENDIF.
        CALL FUNCTION 'BAPI_DOCUMENT_SETSTATUS'
          EXPORTING
            documenttype = 'SWD'
            documentnumber = itab-doknr
            documentpart = itab-dokar
            documentversion = itab-dokvr
      *     STATUSEXTERN = ' '
            statusintern = 'RE'
      *     STATUSLOG = ' '
          IMPORTING
            return = return.
        IF return-type <> 'E' AND
           return-type <> 'A'.
      *-- successful
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait   = 'X'
            IMPORTING
              return = return.
        ELSE.
      *-- failed
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
            IMPORTING
              return = return.
          EXIT.
        ENDIF.
      ELSE.
      *-- failed
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
          IMPORTING
            return = return.
        EXIT.
      ENDIF.

      Add comment
      10|10000 characters needed characters exceeded

    • Posted on Aug 03, 2006 at 07:39 PM

      Oh, I guess you would have to commit at each step since it appears that you are changing the same object.

      Regards,

      Rich Heilman

      Message was edited by: Rich Heilman

      Add comment
      10|10000 characters needed characters exceeded