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_DOCUMENT_POST & generated document number

Former Member
0 Likes
6,465

Hi,

I am using BAPI function BAPI_ACC_DOCUMENT_POST to post financial documents in the system. My question is, how properly retrieve generated document number (BKPF-BELNR). We are using internal document number generation so the function generates document number. But, function itself, does not return generated document number. Currently, after commit I try to locate a record of generated document using reference key ... Isn't there any better way how to get generated document number?

Tkank you.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,542

You can check the return structure RETURN for the document number or the OBJ_KEY.

Thanks

Romit

14 REPLIES 14
Read only

Former Member
0 Likes
3,543

You can check the return structure RETURN for the document number or the OBJ_KEY.

Thanks

Romit

Read only

0 Likes
3,542

I tried, but I have found out that RETURN structure does not store generated document number. OBJ_KEY holds the value of reference key field (BKPF-AWKEY), not generated document number (BKPF-BELNR).

Read only

0 Likes
3,542

Hi

It's very strange I've always got out the document number from message table (RETURN) of thar BAPI, this is an extract of my old program:

IF WA_RESULT-ID     = 'RW' AND
           WA_RESULT-NUMBER = '605'.

          SELECT SINGLE TEXT INTO TEXT FROM T100
                                        WHERE SPRSL = SY-LANGU
                                          AND ARBGB = WA_RESULT-ID
                                          AND MSGNR = WA_RESULT-NUMBER.
          IF SY-SUBRC = 0.
            SEARCH TEXT FOR '&1'.
            IF SY-SUBRC = 0.
              OFFSET = SY-FDPOS + 6.
              LT_BELNR = WA_RESULT-MESSAGE+OFFSET(10).
              OFFSET = OFFSET + 10.
              LT_BUKRS = WA_RESULT-MESSAGE+OFFSET(4).
              OFFSET = OFFSET + 4.
              LT_GJAHR = WA_RESULT-MESSAGE+OFFSET(4).
            ENDIF.
          ENDIF.

Max

Edited by: max bianchi on Jul 8, 2008 7:14 PM

Read only

0 Likes
3,542

Yes Max you are right. Same thing can be done on OBJ_KEY

belnr = OBJ_KEY(10).

bukrs = OBJ_KEY+10(4).

gjahr = OBJ_KEY+14(4).

Thanks

Romit

Read only

0 Likes
3,542

Yes, it is strange.

To be sure, I checked RETURN structure again, but no ... MESSAGE field stores the text:

Document posted successfully: IDOC INV00000000010000004 A00CLNT203

where IDOC is a value of OBJ_TYPE field, INV00000000010000004 is OBJ_KEY and A00CLNT203 is OBJ_SYS.

Maybe there is a problem, how I call BAPI_ACC_DOCUMENT_POST function. Can you please give me an example (document header should be enough) how you call this function? How do you set values for OBJ_TYPE, OBJ_KEY, OBJ_SYS, BUS_ACT?

I use following:

doc_header-obj_type = 'IDOC'.

doc_header-obj_key = ref_key "dynamically generated in external system, ...stored in BKPF-AWKEY key

doc_header-obj_sys = value obtained from OWN_LOGICAL_SYSTEM_GET function call

doc_header-bus_act = 'RFBU'.

Thank you.

Read only

0 Likes
3,542

Can you tell us how you are populating the header. For your reference here is a small sample code for using this BAPI

wa_docheader-BUS_ACT          =              'RFBU'.
wa_docheader-USERNAME          =             'SHARMAN1'.
wa_docheader-COMP_CODE           =           '2001'.
wa_docheader-DOC_DATE             =          '20070726'.
wa_docheader-PSTNG_DATE            =         '20080708'.

wa_docheader-DOC_TYPE                 =      'SA'.
wa_docheader-REF_DOC_NO                =     'UNASSIGNED'.


wa_accgl-ITEMNO_ACC          =           '0000000001'.
wa_accgl-GL_ACCOUNT           =          '0001999998'.
wa_accgl-ITEM_TEXT             =         'POSTING TO GL'.
APPEND wa_accgl to it_accgl.

wa_accpay-ITEMNO_ACC      =               '0000000002'.
wa_accpay-GL_ACCOUNT       =               '0001999998'.
APPEND wa_accpay to it_accpay.

*wa_accpay-ITEMNO_ACC      =               '0000000003'.
*wa_accpay-VENDOR_NO       =               '0000600001'.
*APPEND wa_accpay to it_accpay.

wa_curr-ITEMNO_ACC               =      '0000000002'.
wa_curr-CURRENCY               =        'USD'.
wa_curr-AMT_DOCCUR             =                            - 200 .
APPEND wa_curr to it_curr.




wa_curr-ITEMNO_ACC               =      '0000000001'.
wa_curr-CURRENCY               =        'USD'.
wa_curr-AMT_DOCCUR             =                             200.
APPEND wa_curr to it_curr.



CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
  EXPORTING
    documentheader          = wa_docheader
 IMPORTING
*   OBJ_TYPE                =
   OBJ_KEY                 = OBJ_KEY
*   OBJ_SYS                 =
  tables
    ACCOUNTGL               = it_accgl
*   ACCOUNTRECEIVABLE       =
    ACCOUNTPAYABLE          = it_accpay
*   ACCOUNTTAX              =
    currencyamount          = it_curr
*   CRITERIA                =
*   VALUEFIELD              =
*   EXTENSION1              =
    return                  = it_ret
*   PAYMENTCARD             =
*   CONTRACTITEM            =
    EXTENSION2              = it_ext2
*   REALESTATE              =
*   ACCOUNTWT               =

.

Read only

0 Likes
3,542

Here is my document header initialization:

CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'

IMPORTING

own_logical_system = docHeader-obj_sys.

docHeader-bus_act = 'RFBU'.

docHeader-obj_type = 'IDOC'.

docHeader-OBJ_KEY = ref_key.

docHeader-username = sy-uname.

docHeader-header_txt = fin_data-text.

docHeader-comp_code = header-company_code.

docHeader-doc_date = header-document_date.

docHeader-pstng_date = fin_data-posting_date.

docHeader-ref_doc_no = header-id_sale.

docHeader-doc_type = params-doc_type.

If I initialize the header this way, I got successfully posted document, but system does not return document number. I have tried to leave obj_sys, obj_type and obj_key blank, but in this case, function returns the error "Foreign currency translation not supported for tax calculation" (???) ... company code currency is EUR and document currency is also EUR, ... account amount record (BAPIACCR09) for tax is also in EUR so I do not understand that error message ... and with the same values, as I wrote, document is posted successfully, if I initialize fields obj_sys, obj_type and obj_key ...

Read only

0 Likes
3,542

Try adding Ac_doc_No on header as below.

docHeader-AC_DOC_NO = '$000000001'

if doesnt work the above try '$000000000' , I didnt remember exactly which one i used earlier.

and do let me know if one of the above works.

Edited by: Sweety Shetty on Jul 8, 2008 8:28 PM

Read only

0 Likes
3,542

I think you should keep the obj_sys, obj_type and obj_key blank. And try to concentrate on the error 'Foreign currency translation not supported for tax calculation'. I did a little research, try setting the CURRENCYAMOUNT-CURR_TYPE = '10' and check.

Thanks

Romit

Read only

0 Likes
3,542

OK, both methods works ... it is possible to call function FM_DOCUMENT_NUMBER_INTERNAL to get generated document number, but I prefer a solution with blank obj_sys, obj_key and obj_type fields ... but now, I have another problem this solution works only when I'am posting a document in EUR currency ... when I tried to post a document in USD currency, I got error "Inconsistent currency information" (EUR, USD) ... this is not good ... when I used obj_sys, obj_key and obj_type as wrote before, this worked without problems and the function automatically translated the currency ... i.e. I had such document in two currencies ... in local currency and in document currency ... I am afraid that curr_type = '10' stands for "use EUR currency" ... Am I right?

Read only

0 Likes
3,542

Please tell me how you are populating your line items? Specially ACCOUNTGL and CURRENCYAMOUNT.

The error 'Foreign currency translation not supported for tax calculation' is related to any tax item in your data. Just have a look at the std code from where the error is generated. Might be helpful.

FORM CHECK_TXKRS.

*Status prüfen.
  CASE ACCHD_FI-STATUS_NEW.
    WHEN 2.
      EXIT.
    WHEN OTHERS.
  ENDCASE.
*

*
  LOOP AT ACCHD_FI WHERE GLVOR EQ 'RFBU'
* only postings with Direct Input
                   AND   AWTYP EQ 'BKPFF'
* not for the new item interest calculation
                   AND   TCODE NE 'FINT'                   "note 694310
                   AND   TCODE NE 'FINTAP'.                "note 735114
    LOOP AT ACCIT_FI WHERE     AWTYP EQ ACCHD_FI-AWTYP
                     AND       AWREF EQ ACCHD_FI-AWREF
                     AND       AWORG EQ ACCHD_FI-AWORG
                     AND   NOT MWSKZ IS INITIAL
                     AND   NOT XTXKRS IS INITIAL
                     AND   NOT TAXIT IS INITIAL.
      CHECK ACCIT_FI-ADISC EQ SPACE.   "argent. Skontobeleg
      LOOP AT ACCCR_FI WHERE     AWTYP EQ ACCIT_FI-AWTYP
                       AND       AWREF EQ ACCIT_FI-AWREF
                       AND       AWORG EQ ACCIT_FI-AWORG
                       AND       POSNR EQ ACCIT_FI-POSNR
                       AND       CURTP EQ '10'.
      ENDLOOP.
      CHECK NOT SY-SUBRC IS INITIAL.
*
      MESSAGE E681.
    ENDLOOP.
  ENDLOOP.
ENDFORM.

Read only

0 Likes
3,542

Yes, I found this code ... as I wrote, there is not problem if I set curtp = '10'. BUT, there is another problem, with different currencies. Then, when I try to post document in different currency that the currency of company code is, function raises error "Inconsistent currency information" ...

here is an example, how I fill tax information, as requested:



DATA:   docHeader     TYPE BAPIACHE09,
        accGL         LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
        accReceivable LIKE BAPIACAR09 OCCURS 0 WITH HEADER LINE,
        accAmnt       LIKE BAPIACCR09 OCCURS 0 WITH HEADER LINE,
        accTax        LIKE BAPIACTX09 OCCURS 0 WITH HEADER LINE,
        extension     LIKE BAPIACEXTC OCCURS 0 WITH HEADER LINE,
        tax_account   TYPE STRING,
        tax_code      TYPE STRING,
        tax_trans     TYPE STRING,
        tax_spec      LIKE ZIFPRMS-VALUE,
        itemno        TYPE N LENGTH 10.

* initialize document header
  docHeader-bus_act    = 'RFBU'.
  docHeader-username   = sy-uname.
  docHeader-header_txt = fin_data-text.
  docHeader-comp_code  = header-company_code.
  docHeader-doc_date   = header-document_date.
  docHeader-pstng_date = fin_data-posting_date.
  docHeader-ref_doc_no = header-id_sale.
  docHeader-doc_type = params-doc_type.
* process document items, in loop
  LOOP AT fin_items INTO fin_item.
* initialize AR (line 1)
     accReceivable-itemno_acc = itemno.
     accReceivable-customer   = cus_data-id_contact.
     accReceivable-comp_code = header-company_code.
     CONCATENATE fin_item-text ' (receivable)' INTO accReceivable-item_text.
     accReceivable-pmnttrms = params-payment_term.
     accReceivable-pmnt_block = params-payment_block.
     IF doc_type = 'APR'.
        accReceivable-sp_gl_ind = 'F'.
     ENDIF.
     APPEND accReceivable.

* initialize receivable amount
     accAmnt-itemno_acc = itemno.
     accAmnt-currency = fin_data-currency.
     accAmnt-curr_type = '10'.
     accAmnt-amt_doccur = fin_item-vat_base + fin_item-vat.
     IF doc_type(2) = 'CR'.
        accAmnt-amt_doccur = accAmnt-amt_doccur * ( -1 ).
     ENDIF.
     APPEND accAmnt.
     itemno = itemno + 1.
* do not continue when posting a down payment request
     CHECK doc_type < > 'APR'.

* initialize GL account line item
     accGL-itemno_acc = itemno.
     accGL-gl_account = params-doc_gl_account.
     CONCATENATE fin_item-text ' (revenue)' INTO accGL-item_text.
     accGL-pstng_date = fin_data-posting_date.
     accGL-tax_code = tax_code.
     accGL-doc_type = params-doc_type.
     accGL-costcenter = fin_item-cost_centre.
     APPEND accGL.

* initialize GL amount
     accAmnt-itemno_acc = itemno.
     accAmnt-currency = fin_data-currency.
     accAmnt-curr_type = '10'.
     accAmnt-amt_doccur = - ( fin_item-vat_base ).
     IF doc_type(2) = 'CR'.
        accAmnt-amt_doccur = accAmnt-amt_doccur * ( -1 ).
     ENDIF.
     APPEND accAmnt.

     itemno = itemno + 1.

* initialize TAX account line item
     IF STRLEN( tax_code ) > 0.
        accTax-itemno_acc = itemno.
        accTax-gl_account = tax_account.
        accTax-tax_code   = tax_code.
        accTax-cond_key   = 'MWAS'.
        APPEND accTax.

* initialize tax amount
        accAmnt-itemno_acc = itemno.
        accAmnt-currency = fin_data-currency.
        accAmnt-curr_type = '10'.
        accAmnt-amt_doccur = - ( fin_item-vat ).
        accAmnt-amt_base = - ( fin_item-vat_base ).
        IF doc_type(2) = 'CR'.
           accAmnt-amt_doccur = accAmnt-amt_doccur * ( -1 ).
           accAmnt-amt_base = accAmnt-amt_base * ( -1 ).
        ENDIF.
        APPEND accAmnt.
        itemno = itemno + 1.
     ENDIF.
  ENDLOOP.

* translate customer field to BAPI format
  CALL FUNCTION 'MAP2E_BAPICOBL_CI_TO_BAPIEXTC'
     TABLES    INTERNAL_CI_COBL      = cust_ext
               EXTENSION_CODINGBLOCK = extension.
* call BAPI function to create customer invoice
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
     EXPORTING DOCUMENTHEADER = docHeader
     IMPORTING OBJ_TYPE = obj_type
               OBJ_KEY  = obj_key
               OBJ_SYS  = obj_sys
     TABLES    ACCOUNTGL = accGL
               ACCOUNTRECEIVABLE = accReceivable
               ACCOUNTTAX = accTax
               CURRENCYAMOUNT = accAmnt
               EXTENSION1 = extension
               RETURN = returnTab.

Edited by: Rastislav Mojzis on Jul 9, 2008 7:18 AM

Read only

Former Member
0 Likes
3,542

Hi,

I tried putting a whereused for the bapi...It is used in the method POST_EX of the class CL_REEX_DOC_FI...in that method..the function module FI_DOCUMENT_NUMBER_INTERNAL was called to get the belnr after the BAPI...please check the method code on what needs to be passed to that function module FI_DOCUMENT_NUMBER_INTERNAL to get the belnr..

hope this helps..

THanks

Naren

Read only

Former Member
0 Likes
3,542

... marking as 'unanswerred'.

Edited by: Rastislav Mojzis on Jul 8, 2008 9:08 PM