BAPI Posting

How Do Everyone!
I am writing a program to post documents held in an internal table using the BAPI
'BAPI_ACC_GL_POSTING_POST'.
For each row in the internal table I call the above BAPI followed by BAPI_TRANSACTION_COMMIT.
Everything is working fine for the first row only. i.e. There are 10 rows in the table and only 9
documents are being posted.
Is there anything I need to do after the BAPI_TRANSACTION_COMMIT?
Should I be calling BAPI_TRANSACTION_COMMIT after every row ? or just the once
at the end of the program?
Any help much appreciated
Thanks
Andy

Many thanks Arun for replying. Sorry I have taken a few days to reply.
Here is my code:
    CLEAR: documentheader,
           accountgl,
           currencyamount.
    documentheader-obj_type     = 'BKPFF'.
    documentheader-obj_key      = '$'.
    documentheader-obj_sys      = sy-host.
    documentheader-username     = sy-uname.
    documentheader-header_txt   = invoice_wa-header_text.
    documentheader-comp_code    = invoice_wa-company_code.
    documentheader-doc_date     = invoice_wa-document_date.
    documentheader-pstng_date   = sy-datum.
    documentheader-doc_type     = pa_type.    " Select Screen Document Type
    documentheader-ref_doc_no   = invoice_wa-reference.
For some reason we have to enter line 2 before line 1 ??
Credit - Posting Key 50
    accountgl-itemno_acc      = '2'.
    accountgl-gl_account      = pa_gl.
    accountgl-pstng_date      = sy-datum.
    APPEND accountgl.
Debit - Posting Key 40
    accountgl-itemno_acc      = '1'.
    accountgl-gl_account      = invoice_wa-gl_code.
    accountgl-costcenter      = invoice_wa-cost_centre.
    accountgl-item_text       = invoice_wa-text.
    accountgl-pstng_date      = sy-datum.
    APPEND accountgl.
Debit - Posting Key 40
    currencyamount-itemno_acc = '1'.
    currencyamount-currency   = 'GBP'.
    currencyamount-amt_doccur = invoice_wa-net_trans_amount.
    APPEND currencyamount.
Credit - Posting Key 50
    currencyamount-itemno_acc = '2'.
    currencyamount-currency   = 'GBP'.
    currencyamount-amt_doccur = invoice_wa-net_trans_amount.
    MULTIPLY currencyamount-amt_doccur BY -1.
    APPEND currencyamount.
  Call BAPI-function to Posty the Document
    CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
         EXPORTING
              documentheader = documentheader
    importing
         obj_type       = obj_type
         obj_key        = obj_key
         obj_sys        = obj_sys
         TABLES
              accountgl      = accountgl
              currencyamount = currencyamount
              return         = return
              extension1     = extension1
         EXCEPTIONS
              OTHERS         = 1.
    IF sy-subrc =  0.
      CONCATENATE 'Document Posted Successfully : ' return-message_v2(+10)
          INTO invoice_wa-line.
      invoice_wa-document_no = return-message_v2(+10).
      wa_num_of_posted_documents = wa_num_of_posted_documents + 1.
      wa_total_net_amount        = wa_total_net_amount + invoice_wa-net_trans_amount.
      CLEAR return.
      REFRESH return.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        IMPORTING
          return = return.
    ENDIF.
  Update Internal Table
    MODIFY invoice_tab FROM invoice_wa.
  ENDLOOP.
  IF sy-subrc <> 0.
    MOVE-CORRESPONDING return TO bapi_retn_info.
    invoice_wa-error_ind   = 'Y'.
    invoice_wa-line        = bapi_retn_info-message.
    invoice_wa-document_no = bapi_retn_info-message_v2.
    ROLLBACK WORK.
  ELSE.
    COMMIT WORK.
  ENDIF.

Similar Messages

  • Verifying BAPI posting in SAP R/3

    Hi experts,
                    I am using async RFC (BAPI)  in my scenario. The message has left XI sucessfully, but I do not know whether my BAPI has been posted in SAP.
    Is there any way to find out whether a RFC call has been made in SAP R/3.
    Thanks in Advance.

    Check Comm Channel Monitoring in XI. If no error,then from a XI perspective things look good.
    To check if the BAPI got processed in R3, you will have to check ST22 for any dumps from your BAPI call. Also check the functionality of the BAPI and check if the end result is done. Normally this will be done by the Application Team / Functional Consultant.
    Regards
    Bhavesh

  • Adding new object type (field BKPF-AWKEY) for BAPI posting

    Hi everyone,
    I am posting to SAP GL using an input file to read the data and transfer it to BKPF and BSEG tables.
    The problem is I have to use BAPI_ACC_DOCUMENT_POST, and it expects values for OBJ_KEY and OBJ_TYPE.. For now, OBJ_TYPE creates a problem, because if I use BKPF, it says it cannot post using this object type, as it is for SAP internal use only.
    Does anyone know how to add a new object type for the customer namespace, which can be manually used for this kind of posting? I know that the new entry must be made in tables TTYP, TTYPT, and possibly TTYPV, for which the maintainence view exists: V_TTYPV.
    How to add an entry here, or where can I find it in customizing?
    All helpful answers will be awarded.
    Thank you very much
    Srdjan

    perform fill_internal_tables.
    if check_l = 'X'.
      call function 'BAPI_ACC_DOCUMENT_CHECK'
           destination dest
           exporting
                documentheader    = gd_documentheader
                customercpd       = gd_customercpd
                contractheader    = gd_fica_hd
           tables
                accountgl         = it_accountgl
                accountreceivable = it_accountreceivable
                accountpayable    = it_accountpayable
                accounttax        = it_accounttax
               currencyamount    = it_currencyamount
                criteria          = it_criteria
                valuefield        = it_valuefield
                extension1        = it_ext
                return            = it_return
                paymentcard       = it_paymentcard
                contractitem      = it_fica_it.
               extension2        = it_ext2
               realestate        = it_re.
      write: / 'Result of check lines:'.                        "#EC NOTEXT
      perform show_messages.
    endif.
    if check_a = 'X'.
      call function 'BAPI_ACC_DOCUMENT_CHECK'
        destination dest
        exporting
          documentheader    = gd_documentheader
          customercpd       = gd_customercpd
          contractheader    = gd_fica_hd
        tables
          accountgl         = it_accountgl
          accountreceivable = it_accountreceivable
          accountpayable    = it_accountpayable
          accounttax        = it_accounttax
          currencyamount    = it_currencyamount
          criteria          = it_criteria
          valuefield        = it_valuefield
          extension1        = it_ext
          return            = it_return
          paymentcard       = it_paymentcard
          contractitem      = it_fica_it.
         extension2        = it_ext2
         realestate        = it_re.
      write: / 'Result of check all:'.                          "#EC NOTEXT
      perform show_messages.
    endif.
    if post = 'X'.
      data: l_type like gd_documentheader-obj_type,
            l_key  like gd_documentheader-obj_key,
            l_sys  like gd_documentheader-obj_sys.
      if dest = space or
         dest = gd_documentheader-obj_sys.
       post synchron
        call function 'BAPI_ACC_DOCUMENT_POST'
          exporting
            documentheader    = gd_documentheader
            customercpd       = gd_customercpd
            contractheader    = gd_fica_hd
          importing
            obj_type          = l_type
            obj_key           = l_key
            obj_sys           = l_sys
          tables
            accountgl         = it_accountgl
            accountreceivable = it_accountreceivable
            accountpayable    = it_accountpayable
            accounttax        = it_accounttax
            currencyamount    = it_currencyamount
            criteria          = it_criteria
            valuefield        = it_valuefield
            extension1        = it_ext
            return            = it_return
            paymentcard       = it_paymentcard
            contractitem      = it_fica_it.
           extension2        = it_ext2
           realestate        = it_re.
        write: / 'Result of post:'.                             "#EC NOTEXT
        perform show_messages.
      else.
      create Idoc
        it_receivers-logsys = dest.
        append it_receivers.
        call function 'ALE_ACC_DOCUMENT_POST'
          exporting
            documentheader    = gd_documentheader
            customercpd       = gd_customercpd
            contractheader    = gd_fica_hd
          tables
            accountgl         = it_accountgl
            accountreceivable = it_accountreceivable
            accountpayable    = it_accountpayable
            accounttax        = it_accounttax
            currencyamount    = it_currencyamount
            criteria          = it_criteria
            valuefield        = it_valuefield
            extension1        = it_ext
            paymentcard       = it_paymentcard
            contractitem      = it_fica_it
           extension2        = it_ext2
           realestate        = it_re
            receivers         = it_receivers
          COMMUNICATION_DOCUMENTS =
          APPLICATION_OBJECTS     =
          exceptions
            error_creating_idocs    = 1
            others                  = 2  .
        if sy-subrc = 0.
          write: / 'IDoc created'.                              "#EC NOTEXT
        else.
          write: sy-msgid.
        endif.
      endif.
    endif.
    if rev_p = 'X' or rev_c = 'X'.
      data: rev like bapiacrev,
            rev_key like ref_key.
      rev_key       = ref_key.
      rev_key(1)    = 'R'.
      rev-obj_type  = gd_documentheader-obj_type.
      rev-obj_key   = rev_key.
      rev-obj_sys   = gd_documentheader-obj_sys.
      rev-obj_key_r = ref_key.
      if rev_c is initial.
        if dest = space or
           dest = gd_documentheader-obj_sys.
          call function 'BAPI_ACC_DOCUMENT_REV_POST'
            exporting
              reversal = rev
              bus_act  = gd_documentheader-bus_act
            tables
              return   = it_return.
        else.
          it_receivers-logsys = dest.
          append it_receivers.
          call function 'ALE_ACC_DOCUMENT_REV_POST'
            exporting
              reversal                      = rev
              busact                        = gd_documentheader-bus_act
            OBJ_TYPE                      = 'BUS6035'
            SERIAL_ID                     = '0'
            tables
              receivers                     = it_receivers
            COMMUNICATION_DOCUMENTS       =
            APPLICATION_OBJECTS           =
            exceptions
              error_creating_idocs          = 1
              others                        = 2
          if sy-subrc <> 0.
            message id sy-msgid type sy-msgty number sy-msgno
                    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          else.
            write: / 'IDoc created'.                            "#EC NOTEXT
          endif.
        endif.
      else.
        call function 'BAPI_ACC_DOCUMENT_REV_CHECK'
          exporting
            reversal = rev
            bus_act  = gd_documentheader-bus_act
          tables
            return   = it_return.
      endif.
      write: / 'Result of Reversal Posting:'.                   "#EC NOTEXT
      perform show_messages.
    endif.
    commit work.
    chk this
    Give points if useful

  • BAPI - Posting Multiple Material Number

    Hi
    I am using BAPI_GOODSMVT_CREATE in my JCO Action. I have more than one material number to get updated at a time. Can someone plz tell me is there anyway we can pass more than one material number at a time to JCO.
    Thanks in Advance
    Regards
    Muzammil

    Muzammil,
    Have you downloaded and studied the BLS transactions from the Manufacturing section of the SDN site:  <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/downloads">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/downloads</a>
    I don't believe a version of the BAPI you are using is published yet, but the approach for using a JCO action block with the "Execute Function ?" unchecked, a local xml property and another JCO action block to receive the RequestXML document should be demonstrated in the examples (like WorkOrderCreate in PM).  Using a local xml property and the Append XML links to the Reference version of the JCO block will allow you to feed multiple items into the RequestXML, then assign it to the JCO block that performs the function call.
    Regards,
    Jeremy Good

  • BAPI FUNCTION MODULE  BAPI_ACC_DOCUMENT_POST : How to give posting keys?

    Hi ,
    i am using BAPI_ACC_DOCUMENT_POST to post accounting document. This accounting document is used to post amount from reconcilation account to bank GL account.the table parameter am using is ACCOUNTGL (in the function module)Now i want to give posting keys to the function module parameter. can anyone please guide me how to give posting keys?
    Edited by: Santhosh Kumar  Cheekoti on Dec 18, 2008 7:48 AM

    Hi,
    As pointed out in one of the previous post, posting key will be decided by the BAPI depending on the sign of the amount. Have a look at bthe following code:-
    DATA: doc_header LIKE BAPIACHE09,
          criteria   LIKE BAPIACKEC9 OCCURS 0 WITH HEADER LINE,
          doc_item   LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
          doc_ar     LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
          doc_values LIKE BAPIACCR09 OCCURS 0 WITH HEADER LINE,
          return     LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
          extension1 like BAPIACEXTC occurs 0 with header line,
          obj_type   LIKE bapiache08-obj_type,
          obj_key    LIKE bapiache02-obj_key,
          obj_sys    LIKE bapiache02-obj_sys,
          docnum     LIKE bkpf-belnr.
    *DATA:
    *       ITEMNO_ACC     POSNR_ACC
    *       FIELDNAME     FIELDNAME
    *       CHARACTER     ACPI_RKE_CRIGEN
    * Fill Document Header
    doc_header-bus_act = 'RFBU'.
    doc_header-bus_act = 'RMRP'.
    *doc_header-bus_act = 'SD00'.
    doc_header-username = sy-uname.
    doc_header-header_txt = 'TEST BOC BAPI POSTING'.
    doc_header-comp_code = 'IN10'.
    doc_header-compo_acc = 'FICA'.
    doc_header-doc_date = '20060127'.
    doc_header-pstng_date = sy-datlo.
    doc_header-doc_type = 'SA'.
    ** Fill Line 1 of Document Item
    *doc_item-itemno_acc = '1'.
    *doc_item-gl_account = '0000500001'.
    *doc_item-pstng_date = sy-datum.
    *doc_item-item_text = 'TEST POSTING DEBIT ITEM'.
    *doc_item-costcenter = ''.
    *doc_item-quantity = '1'.
    *doc_item-base_uom = 'ST'.
    *APPEND doc_item.
    *CLEAR doc_item.
    ** Fill Line 2 of Document Item
    *doc_item-itemno_acc = '2'.
    *doc_item-customer = '0000000016'.
    *doc_item-gl_account = '0000000016'.
    *doc_item-pstng_date = sy-datlo.
    *doc_item-item_text = 'TEST POSTING CREDIT ITEM'.
    *APPEND doc_item.
    *CLEAR doc_item.
    doc_ar-itemno_acc = '1'.
    doc_ar-gl_account = '0000500001'.
    doc_ar-pstng_date = sy-datum.
    doc_ar-item_text = 'TEST POSTING DEBIT ITEM'.
    doc_ar-costcenter = ''.
    doc_ar-quantity = '1'.
    doc_ar-base_uom = 'ST'.
    APPEND doc_ar.
    CLEAR doc_ar.
    * Fill Line 2 of Document Item
    doc_ar-itemno_acc = '2'.
    doc_ar-customer = '0000000016'.
    doc_ar-gl_account = '0000000016'.
    doc_ar-pstng_date = sy-datlo.
    doc_ar-item_text = 'TEST POSTING CREDIT ITEM'.
    doc_ar-stat_con = ' '.
    doc_ar-costcenter = '0000201681'.
    APPEND doc_ar.
    CLEAR doc_ar.
    * Fill Line 1 of Document Value.
    doc_values-itemno_acc = '1'.
    doc_values-currency_iso = 'INR'.
    doc_values-amt_doccur = '200.00'.
    doc_values-currency = 'INR'.
    doc_values-CURR_TYPE = '00'.  "Doc currency
    APPEND doc_values.
    CLEAR doc_values.
    * Fill Line 2 of Document Value
    doc_values-itemno_acc = '2'.
    doc_values-currency_iso = 'INR'.
    doc_values-amt_doccur = '200.00-'.
    doc_values-currency = 'INR'.
    doc_values-curr_type = '00'.  "Doc currency
    APPEND doc_values.
    CLEAR doc_values.
    * Add tax code in extension1 table.
    extension1-field1 = 'BAPI CALL'.
    APPEND EXTENSION1.
    * Fill CRITERIA for CO-PA
    *refresh criteria.
    *criteria-ITEMNO_ACC = '1'.
    *criteria-FIELDNAME     = 'ARTNR'.
    *criteria-CHARACTER     = '000000000001312251'.
    *Append criteria.
    *criteria-ITEMNO_ACC = '1'.
    *criteria-FIELDNAME     = 'WERKS'.
    *criteria-CHARACTER     = 'IN91'.
    *Append criteria.
    *criteria-ITEMNO_ACC = '1'.
    *criteria-FIELDNAME     = 'KNDNR'.
    *criteria-CHARACTER     = '0000000016'.
    *Append criteria.
    *criteria-ITEMNO_ACC = '1'.
    *criteria-FIELDNAME     = 'FKART'.
    *criteria-CHARACTER     = 'ZIN2'.
    *Append criteria.
    *criteria-ITEMNO_ACC = '1'.
    *criteria-FIELDNAME     = 'KAUFN'.
    *criteria-CHARACTER     = '0000000633'.
    *Append criteria.
    *criteria-ITEMNO_ACC = '1'.
    *criteria-FIELDNAME     = 'KDPOS'.
    *criteria-CHARACTER     = '000010'.
    *Append criteria.
    *criteria-ITEMNO_ACC = '1'.
    *criteria-FIELDNAME     = 'VKGRP'.
    *criteria-CHARACTER     = '009'.
    **Append criteria.
    * All tables filled - now call BAPI.
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
      EXPORTING
        documentheader       = doc_header
      IMPORTING
        OBJ_TYPE             = doc_header-obj_type
        OBJ_KEY              = doc_header-obj_key
        OBJ_SYS              = doc_header-obj_sys
      TABLES
    *    criteria             = criteria
        accountgl            = doc_item
        ACCOUNTRECEIVABLE    = doc_ar
        currencyamount       = doc_values
        return               = return
        EXTENSION1           = EXTENSION1.
    LOOP AT return WHERE type = 'E'.
      EXIT.
    ENDLOOP.
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
      EXPORTING
        documentheader       = doc_header
      IMPORTING
        OBJ_TYPE             = doc_header-obj_type
        OBJ_KEY              = doc_header-obj_key
        OBJ_SYS              = doc_header-obj_sys
      TABLES
    *    criteria             = criteria
        accountgl            = doc_item
        currencyamount       = doc_values
        return               = return
        EXTENSION1           = EXTENSION1.
    LOOP AT return WHERE type = 'E'.
      EXIT.
    ENDLOOP.
    IF sy-subrc EQ 0.
      WRITE: / 'BAPI call failed - debug and fix!'.
    ELSE.
      CLEAR return.
      REFRESH return.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    * EXPORTING
    *   WAIT          =
       IMPORTING
         return        = return.
      WRITE: / 'BAPI call worked!!'.
      WRITE: / doc_header-obj_key, ' posted'.
    ENDIF.
    Regards
    Raju Chitale
    Edited by: Raju Chitale on Dec 18, 2008 8:31 AM

  • BAPI to post GR based invoices in Held status

    Hello all, I was wondering if anyone was aware of a BAPI that can be used to post goods receipt based invoices in SAP with a held status. I have reviewed the available BAPIs for posting MM and FI documents in SAP and can't seem to find any information on how to make the available BAPIs post an invoice with a 'HELD' status.
    Thank you.

    Dear,
    Yes, Once MIR6 transaction data shown - click on Print icon.
    Once you click on print icon, data view format changed - you can easily download it to excel file.
    Regards,
    Syed Hussain.

  • MM Net invoice payment via BAPI

    Example: customer creates a purchase order with a cost line of £10.00 and a corresponding return line -£5.00.  The return line represents income contributed to the cost of the service from a third party.  In the MIRO transaction, the invoice is posted against both  purchase order lines for the net value of £5.00.  One accounting document is created.  We wish to permit this scenario with a custom version of the MIRO transaction but the BAPI treats the lines as individual transactions and posts two accounting docs in FI, an invoice for £10.00 and a credit memo for £5.00.  Can we make the BAPI post a single document for the net value?

    Hi experts,
    any suggestions?
    Regards,
    Elena

  • BAPI_COPAACTUALS_POSTCOSTDATA   Posting document number

    Hi,
    I am using BAPI  : BAPI_COPAACTUALS_POSTCOSTDATA  for posting documents of type 10, B0 , 12,B2(01,02,03,04 – Paledger no’s).
    My requirement is to post records with same document number  for all the 4 currency types in ce10100 table as in screen shot no :
    I tried below way
    For Paledger number 01 , Belnr is blank and posting document by calling BAPI ,now I am using this posted document number from ce10100 table for rest of the 3 types of documents since my requirement is that I need the same document number for all the 4 types of documents
    When I am using this method to post using test run from se37 I am able to post in required way .In my Z Program when i post one document each time by changing currency type(as 10, B0 , 12,B2  )and exit from Program I am able to achieve this functionality but  if I am using same method for multiple records from Internal table it s not working ,it is generating new document number each time when posted as below screen shot
    . I am using Transaction Commit also both when testing in Se37 as test run and also in Z Program.
    Please help me in this issue.

    There is in fact a workaround to this issue.  I see this question asked in lots of places so I figured I would post here:
    4) Although the BAPI does not return the resulting document number and the forums say you cannot do it, this is a workaround that is somewhat hardcoding and requires familiarity with the data. In this example, we expect that the ww106 field is a unique value. Indeed, we went so far as to index the CE table. By specifying the ORDER BY clause, we can make sure we grab the most recent entry first. This is captured immediately after calling the BAPI and doing the BAPI_TRANSACTION_COMMIT and WAIT.
    CALL FUNCTION 'BAPI...
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
         WAIT = 'X'
    SELECT paobjnr pasubnr FROM ce41010 UP TO 1 ROWS
    BYPASSING BUFFER
    INTO (wa-paobjnr, wa-pasubnr)
    WHERE ww100 = itab-key1
    AND ww109 = itab-key2
    AND ww106 = itab-key3
    ORDER BY PAOBJNR DESCENDING PASUBNR DESCENDING
    ENDSELECT.
    There are a few tips and tricks for working with this BAPI posted here:
    [http://raymannion.com/2011/bapi_copaactuals_postcostdata/|http://raymannion.com/2011/bapi_copaactuals_postcostdata/]

  • Bapi and Logical Unit of Work

    Hi all,
    I am using Bapi to post records in a loop on internal table itab. After posting records, I am again looping at itab and populating those records to my custom table.
    Does this scenario use 2 logical unit of work?
    If yes, then please tell me how do I use one logical unit of work.
    Thanks,
    Ridhima

    Hey,
    You should not post records to the custom table if the BAPI posting has failed.
    In order to maintain data consistency the logic in your program should be as below:
    LOOP AT itab.
    CALL BAPI.
    IF BAPI Call is successful
    Post data to Custom table.
    CALL BAPI_TRANSACTION_COMMIT.
    ELSE.
    CALL BAPI_TRANSACTION_ROLLBACK.
    ENDIF.
    ENDLOOP.
    Talking about LUW's, any program uses 1 SAP LUW and Multiple Database LUWs depending on the number times you COMMIT the data to the database.
    If in your program you were to use only one COMMIT statement or no COMMIT statement at all, your program would use 1 SAP LUW and 1 database LUW.
    -Kiran
    *Please mark useful answers

  • Commit work and wait after bapi execution not working

    Hi experts,
    I have a requirement from my client that consists on posting 2 documents and then clearing them.
    Right now Iu2019m posting the first 2 documents using BAPI_ACC_DOCUMENT_POST and for clearing both documents Iu2019m using Tcode F-51 but sometimes it's giving me an error clearing the documents because after the second bapi run, posting the second document, apparently all went right and a document number it's returned but the database doesnu2019t updated the doc number.
    Iu2019m using commit work and wait, and already tried BAPI_TRANSACTION_COMMIT,  but it doesnu2019t work sometimes, and the only solution that i found was the Wait up 1 second command , which it's slowing the program execution.
    i think the problem it's on the bapi posting execution, due to a lag on the database side, but Iu2019m not sure...
    Did anyone already had this problem? Has anyone has a solution for this?
    Thanks in advance
    Best Regards
    João Martins

    Hi,
    Normally every BAPI will work on Update task so that the data will be updated once the commit work is done. For the commit work, we will normally call the bapi function module - BAPI_TRANSACTION_COMMIT. It should work.
    In your case, just try the below option:
    Please call the bapi - BAPI_ACC_DOCUMENT_POST & BAPI_TRANSACTION_COMMIT in a seperate function module and call this function module in your program (just pass the import / export / table parameters accordingly).
    For the information, I had once a similar type of issue and it got solved once I did like the above.
    Regards,
    Selva K.

  • BAPI please help!

    Hi experts!
    Im new to BAPI, can someone help me to make a code? Right now, im using
    BAPI_SALESDOCU_CREATEDAT2 and i dont know were to start..Please provide sample
    code for this BAPI. One thing, this is with reference to quotation (VA23). Thank you very much! Reward points will be given to deserved reply.
    Regards,
    Mackoy

    BAPIs:
    - are designed as the methods of business objects in the business object repository (accessable using transaction BAPI or SWO1)
    - have non-technical parameter names (the technical field names in SAP are mapped)
    - have a fixed interface and functionality across all SAP releases (this is probably the key point as it means you can develop integrations with them which do not need to be changed when you upgrade)
    Generally, if you are trying to find a function for a particular requirement you should look for a BAPI first, then for a RFC function which has a released status (check the function attributes in SE37), and then just a normal RFC last.
    The benefit of an RFC function with released status means that it also has a fixed interface which will not change with new SAP releases
    RFC-
    http://help.sap.com/saphelp_47x200/helpdata/en/22/042860488911d189490000e829fbbd/frameset.htm.
    BAPI-
    Business application Prograaming Interface is nothing but the Method of a Business object.
    BAPI-step by step
    http://www.sapgenie.com/abap/bapi/example.htm
    list of all bapis
    http://www.planetsap.com/LIST_ALL_BAPIs.htm
    for BAPI's
    http://www.sappoint.com/abap/bapiintro.pdf
    http://www.sappoint.com/abap/bapiprg.pdf
    http://www.sappoint.com/abap/bapiactx.pdf
    http://www.sappoint.com/abap/bapilst.pdf
    http://www.sappoint.com/abap/bapiexer.pdf
    http://service.sap.com/ale
    http://service.sap.com/bapi
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCMIDAPII/CABFAAPIINTRO.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CABFABAPIREF/CABFABAPIPG.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCFESDE8/BCFESDE8.pdf
    http://www.planetsap.com/Bapi_main_page.htm
    http://www.topxml.com/sap/sap_idoc_xml.asp
    http://www.sapdevelopment.co.uk/
    http://www.sapdevelopment.co.uk/java/jco/bapi_jco.pdf
    also refer these threads
    What is the difference between RFC and BAPI?.
    whats difference between rfc and bapi?
    difference between rfc & bapi
    difference between RFC and BAPi
    Difference between BAPI and RFC?
    Regards
    Sudheer
    Priyanka Neelam
    Posts: 1,266
    Questions: 0
    Registered: 11/13/06
    Forum points: 1,854
    Re: difference bet rfc and bapi
    Posted: Jul 26, 2007 7:13 AM in response to: m.kanny d Reply
    Hi,
    RFC is a fun module similar to other fun modulkes with special Parameter as DESTINATIOn and in the attributes you have to make it as RFC ebnables
    where as BAPI is the API of the BUSINESS OBJECT which you see in SWo1 Tcode
    RFC (Remote Function Call) is similar to the general SAP fun module: except that in the attributes you click the radio button: RFC enabled;
    and you will be passing an Import parameter DESTINATION to it.
    Other code and usage will be similar to any fun module;
    Have a look at any fun module in SE37 to understand better about the different components of Fun modules;
    Refer this link:
    http://help.sap.com/saphelp_nw04/helpdata/en/22/042518488911d189490000e829fbbd/frameset.htm
    check out the following link it might help you
    http://help.sap.com/printdocu/core/Print46c/de/data/pdf/BCFESDE2/BCFESDE2.pdf
    BAPI stands for Business API(Application Program Interface).
    A BAPI is remotely enabled function module ie it can be invoked from remote programs like standalone JAVA programs, web interface etc..
    You can make your function module remotely enabled in attributes of Function module but
    A BAPI are standard SAP function modules provided by SAP for remote access. Also they are part of Businees Objest Repository(BOR).
    BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA. in this case u only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.
    The following standardized BAPIs are provided:
    Reading instances of SAP business objects
    GetList ( ) With the BAPI GetList you can select a range of object key values, for example, company codes and material numbers.
    The BAPI GetList() is a class method.
    GetDetail() With the BAPI GetDetail() the details of an instance of a business object type are retrieved and returned to the calling program. The instance is identified via its key. The BAPI GetDetail() is an instance method. BAPIs that can create, change or delete instances of a business object type
    The following BAPIs of the same object type have to be programmed so that they can be called several times within one transaction. For example, if, after sales order 1 has been created, a second sales order 2 is created in the same transaction, the second BAPI call must not affect the consistency of the sales order 2. After completing the transaction with a COMMIT WORK, both the orders are saved consistently in the database.
    Create( ) and CreateFromData! ( )
    The BAPIs Create() and CreateFromData() create an instance of an SAP business object type, for example, a purchase order. These BAPIs are class methods.
    Change( )
    The BAPI Change() changes an existing instance of an SAP business object type, for example, a purchase order. The BAPI Change () is an instance method.
    Delete( ) and Undelete( ) The BAPI Delete() deletes an instance of an SAP business object type from the database or sets a deletion flag.
    The BAPI Undelete() removes a deletion flag. These BAPIs are instance methods.
    Cancel ( ) Unlike the BAPI Delete(), the BAPI Cancel() cancels an instance of a business object type. The instance to be cancelled remains in the database and an additional instance is created and this is the one that is actually canceled. The Cancel() BAPI is an instance method.
    Add<subobject> ( ) and Remove<subobject> ( ) The BAPI Add<subobject> adds a subobject to an existing object inst! ance and the BAPI and Remove<subobject> removes a subobject from an object instance. These BAPIs are instance methods.
    BAPI-step by step
    http://www.sapgenie.com/abap/bapi/example.htm
    list of all bapis
    http://www.planetsap.com/LIST_ALL_BAPIs.htm
    for BAPI's
    http://www.sappoint.com/abap/bapiintro.pdf
    http://www.sappoint.com/abap/bapiprg.pdf
    http://www.sappoint.com/abap/bapiactx.pdf
    http://www.sappoint.com/abap/bapilst.pdf
    http://www.sappoint.com/abap/bapiexer.pdf
    http://service.sap.com/ale
    http://service.sap.com/bapi
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCMIDAPII/CABFAAPIINTRO.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CABFABAPIREF/CABFABAPIPG.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCFESDE8/BCFESDE8.pdf
    http://www.planetsap.com/Bapi_main_page.htm
    http://www.topxml.com/sap/sap_idoc_xml.asp
    http://www.sapdevelopment.co.uk/
    http://www.sapdevelopment.co.uk/java/jco/bapi_jco.pdf
    Also refer to the following links..
    www.sappoint.com/abap/bapiintro.pdf
    www.sap-img.com/bapi.htm
    www.sap-img.com/abap/bapi-conventions.htm
    www.planetsap.com/Bapi_main_page.htm
    www.sapgenie.com/abap/bapi/index.htm
    Checkout !!
    http://searchsap.techtarget.com/originalContent/0,289142,sid21_gci948835,00.html
    http://techrepublic.com.com/5100-6329-1051160.html#
    http://www.sap-img.com/bapi.htm
    http://www.sap-img.com/abap/bapi-conventions.htm
    http://www.sappoint.com/abap/bapiintro.pdf
    u can check the below the material also
    Example Code
    U need to give the step_nr, item_nr, cond_count and cond_type so the correct conditon will be updated. If no condition exists for the given parameters, a new condition will be created.
    U can find these parameters for a particular condition type in table KONV.
    *& Form saveTransactionJOCR
    text
    --> p1 text
    <-- p2 text
    FORM saveTransactionJOCR .
    data: salesdocument like BAPIVBELN-VBELN,
    order_header_inx like bapisdh1x,
    order_header_in like bapisdh1,
    return type standard table of bapiret2 with header line,
    conditions_in type standard table of bapicond with header line,
    conditions_inx type standard table of bapicondx with header line,
    logic_switch like BAPISDLS,
    step_nr like conditions_in-cond_st_no,
    item_nr like conditions_in-itm_number,
    cond_count like conditions_in-cond_count,
    cond_type like conditions_in-cond_type.
    salesdocument = wa_order_information-VBELN.
    LOGIC_SWITCH-COND_HANDL = 'X'.
    order_header_inx-updateflag = 'U'.
    conditions
    clear conditions_in[].
    clear conditions_inx[].
    clear: step_nr,
    item_nr,
    cond_count,
    cond_type.
    step_nr = '710'.
    item_nr = '000000'.
    cond_count = '01'.
    cond_type = 'ZCP2'.
    CONDITIONS_IN-ITM_NUMBER = item_nr.
    conditions_in-cond_st_no = step_nr.
    CONDITIONS_IN-COND_COUNT = cond_count.
    CONDITIONS_IN-COND_TYPE = cond_type.
    CONDITIONS_IN-COND_VALUE = 666.
    CONDITIONS_IN-CURRENCY = 'EUR'.
    append conditions_in.
    CONDITIONS_INX-ITM_NUMBER = item_nr.
    conditions_inx-cond_st_no = step_nr.
    CONDITIONS_INX-COND_COUNT = cond_count.
    CONDITIONS_INX-COND_TYPE = cond_type.
    CONDITIONS_INX-UPDATEFLAG = 'U'.
    CONDITIONS_INX-COND_VALUE = 'X'.
    CONDITIONS_INX-CURRENCY = 'X'.
    append conditions_inx.
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
    EXPORTING
    SALESDOCUMENT = salesdocument
    ORDER_HEADER_IN = order_header_in
    ORDER_HEADER_INX = order_header_inx
    LOGIC_SWITCH = logic_switch
    TABLES
    RETURN = return
    CONDITIONS_IN = conditions_in
    CONDITIONS_INX = conditions_inx
    if return-type ne 'E'.
    commit work and wait.
    endif.
    ENDFORM. " saveTransactionJOCR
    Bdc to Bapi
    The steps to be followed are :
    1. Find out the relevant BAPI (BAPI_SALESORDER_CHANGE for VA02).
    [for VA01 use BAPI_SALESORDER_CREATEFROMDAT2]
    2. Create a Z program and call the BAPi (same as a Funtion module call).
    2. Now, if you see this BAPi, it has
    -> Importing structures.
    eg: SALESDOCUMENT: this will take the Sales order header data as input.
    -> Tables parameters:
    eg: ORDER_ITEM_IN: this will take the line item data as input.
    Note :
    Only specify fields that should be changed
    Select these fields by entering an X in the checkboxes
    Enter a U in the UPDATEFLAG field
    Always specify key fields when changing the data, including in the checkboxes
    The configuration is an exception here. If this needs to be changed, you need to complete it again fully.
    Maintain quantities and dates in the schedule line data
    Possible UPDATEFLAGS:
    U = change
    D = delete
    I = add
    Example
    1. Delete the whole order
    2. Delete order items
    3. Change the order
    4. Change the configuration
    Notes
    1. Minimum entry:
    You must enter the order number in the SALESDOCUMENT structure.
    You must always enter key fields for changes.
    You must always specify the update indicator in the ORDER_HEADER_INX.
    2. Commit control:
    The BAPI does not run a database Commit, which means that the application must trigger the Commit so that the changes are read to the database. To do this, use the BAPI_TRANSACTION_COMMIT BAPI.
    For further details... refer to the Function Module documentation for the BAPi.
    Bapi to VB(Visual Basic)
    Long back I had used the following flow structure to acheive the same.
    Report -> SM59 RFC destination -> COM4ABAP -> VB.exe
    my report uses the rfc destination to create a COM session with com4abap. com4abap calls the vb.exe and manages the flow of data between sap and vb exe.
    You need to have com4abap.exe
    If com4abap is installed you will find it in sapgui installatin directory , C:\Program Files\SAPpc\sapgui\RFCSDK\com4abap.
    else refer OSS note 419822 for installation of com4abap
    after making the settings in com4abap to point to the vb program and setting up rfc destination in sm59 to point to com4abap session , you can use the following function modules to call the vb code.
    for setting up com4abap and rfc destination please refer to the documentation for com4abap.
    Invoke NEW DCOM session
    call function 'BEGIN_COM_SESSION'
    exporting
    service_dest = service_dest "(this will be a RFC destination created in SM59)
    importing
    worker_dest = worker_dest
    exceptions
    connect_to_dcom_service_failed = 1
    connect_to_dcom_worker_failed = 2
    others = 3.
    call function 'create_com_instance' destination worker_dest
    exporting
    clsid = g_c_clsid
    typelib = g_c_typelib
    importing
    instid = g_f_oid
    exceptions
    communication_failure = 1 message g_f_msg
    system_failure = 2 message g_f_msg
    invalid_instance_id = 3
    others = 4.
    call function 'com_invoke' destination worker_dest
    exporting
    %instid = g_f_oid
    %method = 'UpdatePDF'
    sntemp = g_v_const_filent
    snsysid = sy-sysid
    snflag = 'N'
    tables
    rssaptable = g_t_pdfdetail1
    %return = g_t_pdfdetail1 "t_test
    exceptions
    communication_failure = 1 message g_f_msg
    system_failure = 2 message g_f_msg
    invalid_instance_id = 3
    others = 4.
    then close the com session , using
    FM delete_com_instance
    FM END_COM_SESSION

  • Material Master Upload using BAPI_MATERIAL_SAVEREPLICA

    Hi All,
    I am using BAPI_MATERIAL_SAVEREPLICA for creating materials. I am facing an issue where BAPI is not doing the validations properly. In 'Work Scheduling' View, there are some fields which gives error in MM01 transaction. But BAPI posts successfully even with that data. Can anyone please help me in solving this issue. Below are the parmeters passed to the BAPI. Header data and other details are also passed.
    noappllog = 'X'
    nochangedoc = 'X'
    testrun = space
    inpfldcheck = space
    Thanks,
    Deepti

    Hi.
    Did you set
    'X'
    for
    HEADDATA-WORK_SCHED_VIEW
    parameter?

  • IDOC HRSM_D External System / Deletion of vacancies failed

    Hi,
    we are using IDOC HRSM_D01 Upload Time Data to send HR vacancy data from an external system to SAP HCM.
    It should update Infotype 2001 with vacancy type 0100.
    This works fine. Data are sent via PI / IDOC and inbound processing through code HRSM_D.
    After that, we can see it in tables PTEXDIR and PTEX2000. It is transferred to HR/PA30 with the report RPTEXPT.
    So far, so good.
    Now we want to delete it. We re-send the same record, same  AWTYPE, DOCNR etc and add the "X" for REVERSED.
    The IDOC WE02 shows green, BAPI POST successful, but nothing is in table PTEXDIR and PTEX2000.
    When I look at the function module IDOC_INPUT_HRSM_SCHEDULE, it only handles PA2002 (Time Attendance, not absences) for reversed data. Is this true?
    Can I only delete Attendancies?
    Thanks for deedback
    hs

    When I look at the function module IDOC_INPUT_HRSM_SCHEDULE, it only handles PA2002 (Time Attendance, not absences) for reversed data. Is this true?
    Can I only delete Attendancies?
    I copied the whole sender agreement etc. and created a zIDOC_INPUT_HRSM_SCHEDULE procedure.
    I found out, that Infotype 2002 was hardcoded and 2001 Deletion was not supported. Now it workes, when I deleted the hardcoded 2002-checkup.
    But is there any better way?
    thx
    Holger

  • Clear_document FM not working to clear customer open item.

    Hi Experts,
    1) I need to develop a report to clear the customer open items, the report has to display whether the Customer open items cleared or not?
         As we do f-30 transaction to clear documents.
       I have developed the report in this ways but its not clearing.
        a) First I have posted the document  through   'BAPI_ACC_DOCUMENT_POST
        I have filled the document in the below way. The Bapi returning OBJ_KEY value also.
    LOOP AT it_data INTO wa_data.
    ****Fill  DOCUMENTHEADER
        wa_docmentheader-doc_type     = 'DA'.   "doc type
        wa_docmentheader-doc_date    =  wa_data-bldat.   "doc. date
        wa_docmentheader-pstng_date  =  wa_data-budat.   "posting date
        wa_docmentheader-comp_code   =  wa_data-bukrs.   "company code
        wa_docmentheader-ref_doc_no  =  wa_data-belnr.   "Reference
        wa_docmentheader-header_txt  =  wa_data-bktxt .  "Header Text
        wa_docmentheader-username    =  sy-uname.        "user name
    ****Fill  ACCOUNTGL Table
        wa_gl-itemno_acc = l_no.
        wa_gl-gl_account = 2909509----" which i marked in the screen second red color(ACCount).
        wa_gl-alloc_nmbr = wa_data-xref2.
        APPEND wa_gl TO it_gl.
        CLEAR wa_gl.
    ****Fill  ACCOUNTRECEIVABLE
        wa_receivable-itemno_acc = l_no + 1.
        wa_receivable-customer = wa_data-kunnr.
        wa_receivable-gl_account = wa_data-saknr.
        wa_receivable-alloc_nmbr  = wa_data-xref2.
        APPEND wa_receivable TO it_receivable.
        CLEAR wa_receivable.
    ****Fill CURRENCYAMOUNT
        wa_currencyamount-itemno_acc = l_no.
        wa_currencyamount-currency = wa_data-waers.
        wa_currencyamount-amt_doccur = wa_data-dmbtr.
        APPEND wa_currencyamount TO it_currencyamount.
        CLEAR  wa_currencyamount.
        wa_currencyamount-itemno_acc = l_no + 1.
        wa_currencyamount-currency = wa_data-waers.
        wa_currencyamount-amt_doccur = wa_data-dmbtr.
        wa_currencyamount-amt_doccur = wa_currencyamount-amt_doccur * -1.
        APPEND wa_currencyamount TO it_currencyamount.
        CLEAR wa_currencyamount.
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
    documentheader
    = wa_docmentheader
    IMPORTING
    OBJ_TYPE     
    =
    obj_key      
    = lv_obj_key
    OBJ_SYS      
    =
    TABLES
    accountgl    
    = it_gl
    accountreceivable = it_receivable
    ACCOUNTPAYABLE
    =
    ACCOUNTTAX   
    =
    currencyamount
    = it_currencyamount
    return       
    = it_return.
    EXTENSION2   
    =
    endloop.
    2) After posting the document am using Clear_document to clear the document
       am filling the Clear_Document in the below way.
    1. a)get belnr, bukrs, gjahr & buzei from bsid table for invoice and append to T_AUSZ1
        b)T_AUSZ1-BUKRS, 'A', OBJ_KEY+0(10)(which you get from BAPI_ACC_DOCUMENT_POST bapi), posting date, posting date year pass it to T_AUSZ2-BUKRS, T_AUSZ2-AKTIO, T_AUSZ2-AUGBL, T_AUSZ2-AUGDT & T_AUSZ2-AUGGJ and append it.
    2. a)get BELNR, BUKRS, GJAHR, BLART & BUDAT  from bkpf where awkey = OBJ_KEY(which you get from BAPI_ACC_DOCUMENT_POST bapi)
    b) get belnr, bukrs, gjahr & buzei from bsid table where BELNR EQ bkpf-BELNR AND
                          ZUONR EQbkpf-BELNR AND
                          BLART EQ bkpf-BLART AND
                          GJAHR EQ bkpf-GJAHR AND
                          BUDAT EQ bkpf-BUDAT
    and append to T_AUSZ1
    c) T_AUSZ1-BUKRS, 'A', OBJ_KEY+0(10)(which you get from BAPI_ACC_DOCUMENT_POST bapi), posting date, posting date year pass it to T_AUSZ2-BUKRS, T_AUSZ2-AKTIO, T_AUSZ2-AUGBL, T_AUSZ2-AUGDT & T_AUSZ2-AUGGJ and append it.
    delete duplicates from T_AUSZ2.
    3) but am not able to clear the document using Clear_document Function Module
    4)I am able to post the document  through BAPI_ACC_DCUMENT_POST
    5)Please tell me how to clear the document.

    Hi Sunny,
    Please see the following :
    1. Down Payment Received (2500 INR.) F-29
    2. Customer Invoice Posted (2500 INR.) FB70
    3. Clear Down Payment (2500 INR) F-39
    4. Now Run Automatic Clearing (F.13)
    And then check the Customer line item report in FBL5N. It will clear both line items.
    Hope this helps.
    Kind Regards,
    Prakash Kumar

  • BAPI_ACC_DOCUMENT_POST not calculating TAX

    Hi,
    I am using BAPI_ACC_DOCUMENT_POST for posting the FI document for RC type. I tried posting it normally and it posted correctly. But when i give some ACCOUNT TAX information, it is not calculating.
    Here is how I am filling the details.
    Header:
    BUS_ACT = RFBU.
    USERNAME = SY_UNAME.
    HEADER_TEXT = TEXT.
    COMP_CODE = BUKRS.
    DOC_DATE = 12/12/2011
    PSTNG_DATE = 12/05/2011.
    FIS_PERIOD = 00
    REF_DOC_NO = 9700000036.
    AC_DOC_NO = 9700000036.
    Account GL Table:.
    ITEMNO_ACC = 10.
    GL_ACCOUNT = 412010.
    DOC_TYPE = RC.
    COMP_CODE = RECN.
    FIS_PERIOD = 00.
    PSTNG_DATE = 12/05/2011
    TAX_CODE = TN
    TAXJURCODE = TN3707600
    COST CENTER = 107
    Account Receivable:
    ITEMNO_ACC = 20.
    CUSTOMER = 1126045
    COMP_CODE = RECN
    BLINE_DATE = 12/12/2011.
    PYMT_METH = B
    CURRENCY AMOUNT : 2 LINE ITEMS
    1ST LINE ITEM
    ITEMNO_ACC = 10
    CURRENCY = USD
    AMT_DOCCUR = 500.00-
    DISC_BASE = 500.00-.
    2ND LINE ITEM
    ITEMNO_ACC = 20
    CURRENCY = USD
    AMT_DOCCUR = 500.00
    AMT_BASE = 500.00.
    I did not enter the account tax table as I am not sure how to enter the date. But I know that the tax rate is 9.25% and for 500 the tax would be 42.33. I need to make sure that the BAPI posts the document as it posts from FB01 when we check the check box 'calculate tax'. Right now, with these details it is posting the data but not calculating the tax.
    Please help.
    Regards
    Guru
    Edited by: GuruCharan on Dec 15, 2011 6:28 PM

    Raymond,
    Thanks for the reply. I did read the notes you have suggested. They are quite informative but unfortunately -
    Note 367175 is related to the other BAPI`s. My issue is with the BAPI_ACC_DOCUMENT_POST.
    Note 487064 is related to the error when the tax amount is greater than the base amount.
    Since I am using the Acc document post BAPI, please help me understand how to fill in the data for ACCOUNT TAX table or post the document from the BAPI along with the tax as it does in FB01.
    Thanks Again,
    Regards,
    Guru.

Maybe you are looking for