Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI_ACC_GL_POSTING_POST Document Already exist

mrahhaoui
Participant
0 Likes
1,252

Hi,

I have an ALV grid which contains some amount that I have to post. When I post a first time with function BAPI_ACC_GL_POSTING_POST, the posting and the reversal do correctly. After that I do a refresh of the ALV. But when I try a second time to post another document, I receive the internal message "Document XXXXXX already exist". I think my problem comes from the OBJ_KEY because It takes the old reference.

My posting is in a loop and I think maybe that I would have to increment my OBJ_KEY. Is it possible to do that?

Anybody would have an idea?

Regards,

Mohamed.

Edited by: rahhaoui mohamed on Aug 24, 2009 7:59 PM

9 REPLIES 9
Read only

former_member156446
Active Contributor
0 Likes
1,200

try clearing the Object key and re assign in the loop. Or if the doc already exists you might have to use a doc change bapi

You should not increment just like that... there would be a number range assigned to Object key.. which will give you the next number to use.

Read only

0 Likes
1,200

Thks for your quick answer but how to clearing the OBJect key and re assign it. What BAPI are you talking?

DO you have an example maybe?

Thank you .

Read only

0 Likes
1,200

I receive the internal message "Document XXXXXX already exist". I think my problem comes from the OBJ_KEY because It takes the old reference.

already exists means the document already posted so with that OBject key you cannot force the system to create again....

loop at itab...

call bapi and send obj_key..

clear obj_key.

endloop.

Read only

0 Likes
1,200

Hi,

Thats an exporting parameter for the BAPI that you are using i think you should clear that variable before you call the BAPI second time in the loop.

Regards,

Himanshu

Read only

0 Likes
1,200

Hi Thanks a lot for your response but I always meet the same problem. I refresh the tables and I do before a commit.


LOOP AT l_seltab INTO wa_seltab.
* Call BAPI to post the document
        CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
          EXPORTING
            documentheader       = i_docheader
          IMPORTING
            obj_type             = i_docheader-obj_type
            obj_key              = i_docheader-obj_key
            obj_sys              = i_docheader-obj_sys
          TABLES
            accountgl            = i_accountgl
            currencyamount       = i_curramunt
            return               = i_return
*   EXTENSION1           = .
          CLEAR i_return.
        REFRESH i_return.

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait   = 'X'
          IMPORTING
            return = i_return.
commit WORK AND WAIT.

        CLEAR i_return.
        REFRESH i_return.

        i_reversal-obj_type        = 'BKPFF'.
        i_reversal-obj_key         = i_docheader-obj_key.
        i_reversal-obj_key_r       = i_docheader-obj_key.
        i_reversal-reason_rev      = '06'.
        i_reversal-pstng_date      = p_budt3.
        i_reversal-fis_period      = p_budt3+4(2).
        i_reversal-comp_code       = s_bukrs-low.

        APPEND i_reversal.
* Reversal posting
        CALL FUNCTION 'BAPI_ACC_GL_POSTING_REV_POST'
          EXPORTING
            reversal = i_reversal
          IMPORTING
            obj_type = i_reversal-obj_type
            obj_key  = i_reversal-obj_key
            obj_sys  = i_reversal-obj_sys
          TABLES
            return   = i_return.
        CLEAR i_return.
        REFRESH i_return.

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait   = 'X'
          IMPORTING
            return = i_return.

        commit WORK AND WAIT.

refresh: i_docheader, i_accountgl, i_curramunt, i_reversal.
      ENDLOOP.

I don't see where is the problem.

Regards,

Mohamed.

Read only

0 Likes
1,200

Hi,


* Reversal posting
        CALL FUNCTION 'BAPI_ACC_GL_POSTING_REV_POST'
          EXPORTING
            reversal = i_reversal
          IMPORTING
            obj_type = i_reversal-obj_type   <<<< This is an importinging parameter
            obj_key  = i_reversal-obj_key    <<<< This is an importinging parameter
            obj_sys  = i_reversal-obj_sys   <<<< This is an importinging parameter
          TABLES
            return   = i_return.
        CLEAR i_return.
        REFRESH i_return.

do not use the same values as returnurned above you can declare new variables like obj_type,obj_key and obj_sys here and then every time you call the FM for postings clear these variables these variables would ahve values returned by the FM and we dont need to pass any values to them we can also comment the importing lines and that should work.

Regards,

HImanshu

Read only

0 Likes
1,200

Hi HImanshu,

I did what you told me but always the same issue:

* Reversal posting
        CALL FUNCTION 'BAPI_ACC_GL_POSTING_REV_POST'
          EXPORTING
            reversal = i_reversal
          IMPORTING
            obj_type = lw_obj_type
            obj_key  = lw_obj_key
            obj_sys  = lw_obj_sys
          TABLES
            return   = i_return.

        IF i_return-type = 'E'.                          "If error Document not posted
          EXIT.
        ENDIF.

        CLEAR i_return.
        REFRESH i_return.

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait   = 'X'
          IMPORTING
            return = i_return.

        IF i_return-type = 'E'.                   "If error Document not posted
          MESSAGE s040(zst1).
          EXIT.
        ENDIF.
        COMMIT WORK AND WAIT.
        CLEAR: lw_obj_key, lw_obj_type, lw_obj_sys.
        REFRESH: i_docheader, i_accountgl, i_curramunt, i_reversal.
      ENDLOOP.

Read only

0 Likes
1,200

What should I have to pass in i_reversal-obj_key and i_reversal-obj_key_r fields?

Thank you.

Read only

0 Likes
1,200

I resolved the problem.

Thx.