Application Development 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: 

Problem with bapi "BAPI_ACC_DOCUMENT_POST"

Former Member
0 Kudos

Hello Experts,

I am using the bapi BAPI_ACC_DOCUMENT_POST for posting the document. In that I am passing the value to DOCUMENTHEADER-VATDAT from program this is a header field. After execution of this BAPI. document get posted. but DOCUMENTHEADER-VATDAT field is not updates in BKPF table in BKPF-VATDATE field, and other fields are updating in BKPF table.

Can anyone guide me....why this is happening?

Thanks

Chetan

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Chetan,

There is no field in Documentheader and BKPF named VATDAT/VATDATE.

If its the document date, pass it in DOCUMENTHEADER-DOC_Date and it should be updated in BKPF-BFDAT.

Regards,

Ashish

4 REPLIES 4

Former Member
0 Kudos

Hi Chetan,

There is no field in Documentheader and BKPF named VATDAT/VATDATE.

If its the document date, pass it in DOCUMENTHEADER-DOC_Date and it should be updated in BKPF-BFDAT.

Regards,

Ashish

Former Member
0 Kudos

hi,

see the sample code and correct where u did mistake..


*&---------------------------------------------------------------------*
*& Report  Z_BAPI_1_NVK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report  z_bapi_1_nvk.
data : st_header type bapiache09,
       it_account_gl type  table of bapiacgl09
                     with header line,
       it_account_payable type  table of bapiacap09
                     with header line,
       it_currency_amount type  table of bapiaccr09
                     with header line,
       it_return type table of bapiret2 with header line,
*&---------------------------------------------------------------------*
*&                    INTERNAL TABLE TO READ THE FILE
*&---------------------------------------------------------------------*
      begin of it_getfile occurs 0,
        strng type string,
      end of it_getfile,
      begin of it_downfile occurs 0,
       strng2 type string,
      end of it_downfile,
*&---------------------------------------------------------------------*
*&                    INTERNAL TABLE TO HOLD THE DATA
*&---------------------------------------------------------------------*
     begin of it_head occurs 0,
         reccount(2),
         identifier(4),
         compcod(10),
         accnt(10),
         bldat like sy-datum,
         budat like sy-datum,
         wrbtr(15),
     end of it_head,
     begin of it_item occurs 0,
         reccount(2),
         identifier(4),
         hkont(10),
         wrbtr(15),
         kostl(10),
     end of it_item,
*     INTERNAL TABLES TO HOLD ERRORS IN HEADER LEVER/ ITEM LEVEL.
    begin of it_head_er occurs 0,
         reccount(2),
         identifier(4),
         accnt(30),
         bldat like sy-datum,
         budat like sy-datum,
         wrbtr(30),
     end of it_head_er,
     begin of it_item_er occurs 0,
         reccount(2),
         identifier(4),
         hkont(30),
         wrbtr(30),
         kostl(30),
     end of it_item_er,
     v_file_name   type string,
     v_defile type string,
     counter type i,
     credit type c,
     credit1 like it_head-wrbtr.
selection-screen begin of block b1 with frame title text-001.
parameters:p_tstdt as checkbox default 'X'.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters:p_get  like  ibipparms-path obligatory.
selection-screen end of block b2.
selection-screen begin of block b3 with frame title text-003.
parameters: p_give like  ibipparms-path obligatory.
selection-screen end of block b3.

at selection-screen on value-request for p_get.
  perform f4_filename using 'P_GET'
                      changing p_get.

at selection-screen on value-request for p_give.
  perform f4_filename using 'P_GIVE'
                      changing p_give.



start-of-selection.
  v_file_name = p_get.
    perform  upload.
  perform splitstring.
  perform build_bapi.

*&---------------------------------------------------------------------*
*&      Form  F4_FILENAME
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0290   text
*      <--P_P_GET  text
*----------------------------------------------------------------------*
form f4_filename  using    p_name
                  changing p_value.
*CALLING F4_FILENAME FUNCTION MODULE TO GET THE F4 HELP.
  call function 'F4_FILENAME'
    exporting
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = p_name
    importing
      file_name     = p_value.
endform.                    " F4_FILENAME


*&---------------------------------------------------------------------*
*&      Form  UPLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form upload .
  call function 'GUI_UPLOAD'
    exporting
      filename                      = v_file_name
*     FILETYPE                      = 'ASC'
*     HAS_FIELD_SEPARATOR           = ' '
*     HEADER_LENGTH                 = 0
*     READ_BY_LINE                  = 'X'
*     DAT_MODE                      = ' '
*     CODEPAGE                      = ' '
*     IGNORE_CERR                   = ABAP_TRUE
*     REPLACEMENT                   = '#'
*     CHECK_BOM                     = ' '
*     VIRUS_SCAN_PROFILE            = VIRUS_SCAN_PROFILE
*     NO_AUTH_CHECK                 = ' '
*   IMPORTING
*     FILELENGTH                    = FILELENGTH
*     HEADER                        = HEADER
    tables
      data_tab                      = it_getfile
   exceptions
     file_open_error               = 1
     file_read_error               = 2
     no_batch                      = 3
     gui_refuse_filetransfer       = 4
     invalid_type                  = 5
     no_authority                  = 6
     unknown_error                 = 7
     bad_data_format               = 8
     header_not_allowed            = 9
     separator_not_allowed         = 10
     header_too_long               = 11
     unknown_dp_error              = 12
     access_denied                 = 13
     dp_out_of_memory              = 14
     disk_full                     = 15
     dp_timeout                    = 16
     others                        = 17
            .
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.



endform.                    " UPLOAD

*&---------------------------------------------------------------------*
*&      Form  splitstring
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form splitstring .
  loop at it_getfile.
    if it_getfile-strng+0(1)  = '1'.
      split it_getfile-strng at cl_abap_char_utilities=>horizontal_tab
                                  into
                                  it_head-reccount
                                  it_head-identifier
                                  it_head-compcod
                                  it_head-accnt
                                  it_head-bldat
                                  it_head-budat
                                  it_head-wrbtr.
      append it_head.
      clear it_head.
    else.
      split it_getfile-strng at cl_abap_char_utilities=>horizontal_tab
                                into
                                it_item-reccount
                                it_item-identifier
                                it_item-hkont
                                it_item-wrbtr
                                it_item-kostl.
      append it_item.
      clear it_item.

    endif.
  endloop.
endform.                    " splitstring
*&---------------------------------------------------------------------*
*&      Form  build_bapi
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form build_bapi .

  loop at it_head.
    counter = 1.

    it_head-wrbtr = it_head-wrbtr * -1.

    st_header-comp_code = it_head-compcod.
    st_header-doc_date = it_head-bldat.
    st_header-pstng_date = it_head-budat.
    st_header-username = sy-uname.
    st_header-bus_act = 'RFBU'.
    st_header-doc_type = 'KR'.

    it_account_payable-itemno_acc  = counter.
    it_account_payable-vendor_no    = it_head-accnt.
    append it_account_payable.
    clear it_account_payable.

    it_currency_amount-itemno_acc = counter.
    it_currency_amount-currency = 'INR'.
    it_currency_amount-amt_doccur = it_head-wrbtr.
    append it_currency_amount.
    clear it_currency_amount.



    loop at it_item where identifier = it_head-identifier.
      counter = counter + 1.


      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = it_item-hkont
        importing
          output = it_item-hkont.
      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = it_item-kostl
        importing
          output = it_item-kostl.
      it_account_gl-itemno_acc  = counter.
      it_account_gl-gl_account    = it_item-hkont.
      it_account_gl-costcenter    = it_item-kostl.
      append it_account_gl.
      clear it_account_gl.

      it_currency_amount-itemno_acc = counter.
      it_currency_amount-currency = 'INR'.
      it_currency_amount-amt_doccur = it_item-wrbtr.
      append it_currency_amount.
      clear it_currency_amount.

    endloop.
    call function 'BAPI_ACC_DOCUMENT_POST'
       exporting
         documentheader          = st_header
*           CUSTOMERCPD             = CUSTOMERCPD
*           CONTRACTHEADER          = CONTRACTHEADER
*         IMPORTING
*           OBJ_TYPE                = OBJ_TYPE
*           OBJ_KEY                 = OBJ_KEY
*           OBJ_SYS                 = OBJ_SYS
       tables
             accountgl               = it_account_gl
*           ACCOUNTRECEIVABLE       = ACCOUNTRECEIVABLE
             accountpayable          = it_account_payable
*           ACCOUNTTAX              = ACCOUNTTAX
             currencyamount          = it_currency_amount
*           CRITERIA                = CRITERIA
*           VALUEFIELD              = VALUEFIELD
*           EXTENSION1              = EXTENSION1
         return                  = it_return
*           PAYMENTCARD             = PAYMENTCARD
*           CONTRACTITEM            = CONTRACTITEM
*           EXTENSION2              = EXTENSION2
*           REALESTATE              = REALESTATE
       .
    if p_tstdt is initial.
      call function 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
                .
    endif.
break-point.
    loop at it_return.
    write: /1(2) it_head-identifier,3(1) '|', 4(50) it_return-message.
    endloop.
  refresh:it_account_gl,
          it_account_payable,
          it_currency_amount,
          it_return.
  endloop.

endform.                    " build_bapi

Regards,

Prabhudas

Former Member
0 Kudos

hi ,

Sorry for above post..

See the sample code and correct the you r code.


*&---------------------------------------------------------------------*
*& Report  Z_BAPI_1_NVK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report  z_bapi_1_nvk.
data : st_header type bapiache09,
       it_account_gl type  table of bapiacgl09
                     with header line,
       it_account_payable type  table of bapiacap09
                     with header line,
       it_currency_amount type  table of bapiaccr09
                     with header line,
       it_return type table of bapiret2 with header line,
*&---------------------------------------------------------------------*
*&                    INTERNAL TABLE TO READ THE FILE
*&---------------------------------------------------------------------*
      begin of it_getfile occurs 0,
        strng type string,
      end of it_getfile,
      begin of it_downfile occurs 0,
       strng2 type string,
      end of it_downfile,
*&---------------------------------------------------------------------*
*&                    INTERNAL TABLE TO HOLD THE DATA
*&---------------------------------------------------------------------*
     begin of it_head occurs 0,
         reccount(2),
         identifier(4),
         compcod(10),
         accnt(10),
         bldat like sy-datum,
         budat like sy-datum,
         wrbtr(15),
     end of it_head,
     begin of it_item occurs 0,
         reccount(2),
         identifier(4),
         hkont(10),
         wrbtr(15),
         kostl(10),
     end of it_item,
*     INTERNAL TABLES TO HOLD ERRORS IN HEADER LEVER/ ITEM LEVEL.
    begin of it_head_er occurs 0,
         reccount(2),
         identifier(4),
         accnt(30),
         bldat like sy-datum,
         budat like sy-datum,
         wrbtr(30),
     end of it_head_er,
     begin of it_item_er occurs 0,
         reccount(2),
         identifier(4),
         hkont(30),
         wrbtr(30),
         kostl(30),
     end of it_item_er,
     v_file_name   type string,
     v_defile type string,
     counter type i,
     credit type c,
     credit1 like it_head-wrbtr.
selection-screen begin of block b1 with frame title text-001.
parameters:p_tstdt as checkbox default 'X'.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters:p_get  like  ibipparms-path obligatory.
selection-screen end of block b2.
selection-screen begin of block b3 with frame title text-003.
parameters: p_give like  ibipparms-path obligatory.
selection-screen end of block b3.

at selection-screen on value-request for p_get.
  perform f4_filename using 'P_GET'
                      changing p_get.

at selection-screen on value-request for p_give.
  perform f4_filename using 'P_GIVE'
                      changing p_give.



start-of-selection.
  v_file_name = p_get.
    perform  upload.
  perform splitstring.
  perform build_bapi.

*&---------------------------------------------------------------------*
*&      Form  F4_FILENAME
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0290   text
*      <--P_P_GET  text
*----------------------------------------------------------------------*
form f4_filename  using    p_name
                  changing p_value.
*CALLING F4_FILENAME FUNCTION MODULE TO GET THE F4 HELP.
  call function 'F4_FILENAME'
    exporting
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = p_name
    importing
      file_name     = p_value.
endform.                    " F4_FILENAME


*&---------------------------------------------------------------------*
*&      Form  UPLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form upload .
  call function 'GUI_UPLOAD'
    exporting
      filename                      = v_file_name
*     FILETYPE                      = 'ASC'
*     HAS_FIELD_SEPARATOR           = ' '
*     HEADER_LENGTH                 = 0
*     READ_BY_LINE                  = 'X'
*     DAT_MODE                      = ' '
*     CODEPAGE                      = ' '
*     IGNORE_CERR                   = ABAP_TRUE
*     REPLACEMENT                   = '#'
*     CHECK_BOM                     = ' '
*     VIRUS_SCAN_PROFILE            = VIRUS_SCAN_PROFILE
*     NO_AUTH_CHECK                 = ' '
*   IMPORTING
*     FILELENGTH                    = FILELENGTH
*     HEADER                        = HEADER
    tables
      data_tab                      = it_getfile
   exceptions
     file_open_error               = 1
     file_read_error               = 2
     no_batch                      = 3
     gui_refuse_filetransfer       = 4
     invalid_type                  = 5
     no_authority                  = 6
     unknown_error                 = 7
     bad_data_format               = 8
     header_not_allowed            = 9
     separator_not_allowed         = 10
     header_too_long               = 11
     unknown_dp_error              = 12
     access_denied                 = 13
     dp_out_of_memory              = 14
     disk_full                     = 15
     dp_timeout                    = 16
     others                        = 17
            .
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.



endform.                    " UPLOAD

*&---------------------------------------------------------------------*
*&      Form  splitstring
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form splitstring .
  loop at it_getfile.
    if it_getfile-strng+0(1)  = '1'.
      split it_getfile-strng at cl_abap_char_utilities=>horizontal_tab
                                  into
                                  it_head-reccount
                                  it_head-identifier
                                  it_head-compcod
                                  it_head-accnt
                                  it_head-bldat
                                  it_head-budat
                                  it_head-wrbtr.
      append it_head.
      clear it_head.
    else.
      split it_getfile-strng at cl_abap_char_utilities=>horizontal_tab
                                into
                                it_item-reccount
                                it_item-identifier
                                it_item-hkont
                                it_item-wrbtr
                                it_item-kostl.
      append it_item.
      clear it_item.

    endif.
  endloop.
endform.                    " splitstring
*&---------------------------------------------------------------------*
*&      Form  build_bapi
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form build_bapi .

  loop at it_head.
    counter = 1.

    it_head-wrbtr = it_head-wrbtr * -1.

    st_header-comp_code = it_head-compcod.
    st_header-doc_date = it_head-bldat.
    st_header-pstng_date = it_head-budat.
    st_header-username = sy-uname.
    st_header-bus_act = 'RFBU'.
    st_header-doc_type = 'KR'.

    it_account_payable-itemno_acc  = counter.
    it_account_payable-vendor_no    = it_head-accnt.
    append it_account_payable.
    clear it_account_payable.

    it_currency_amount-itemno_acc = counter.
    it_currency_amount-currency = 'INR'.
    it_currency_amount-amt_doccur = it_head-wrbtr.
    append it_currency_amount.
    clear it_currency_amount.



    loop at it_item where identifier = it_head-identifier.
      counter = counter + 1.


      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = it_item-hkont
        importing
          output = it_item-hkont.
      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = it_item-kostl
        importing
          output = it_item-kostl.
      it_account_gl-itemno_acc  = counter.
      it_account_gl-gl_account    = it_item-hkont.
      it_account_gl-costcenter    = it_item-kostl.
      append it_account_gl.
      clear it_account_gl.

      it_currency_amount-itemno_acc = counter.
      it_currency_amount-currency = 'INR'.
      it_currency_amount-amt_doccur = it_item-wrbtr.
      append it_currency_amount.
      clear it_currency_amount.

    endloop.
    call function 'BAPI_ACC_DOCUMENT_POST'
       exporting
         documentheader          = st_header
*           CUSTOMERCPD             = CUSTOMERCPD
*           CONTRACTHEADER          = CONTRACTHEADER
*         IMPORTING
*           OBJ_TYPE                = OBJ_TYPE
*           OBJ_KEY                 = OBJ_KEY
*           OBJ_SYS                 = OBJ_SYS
       tables
             accountgl               = it_account_gl
*           ACCOUNTRECEIVABLE       = ACCOUNTRECEIVABLE
             accountpayable          = it_account_payable
*           ACCOUNTTAX              = ACCOUNTTAX
             currencyamount          = it_currency_amount
*           CRITERIA                = CRITERIA
*           VALUEFIELD              = VALUEFIELD
*           EXTENSION1              = EXTENSION1
         return                  = it_return
*           PAYMENTCARD             = PAYMENTCARD
*           CONTRACTITEM            = CONTRACTITEM
*           EXTENSION2              = EXTENSION2
*           REALESTATE              = REALESTATE
       .
    if p_tstdt is initial.
      call function 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
                .
    endif.
break-point.
    loop at it_return.
    write: /1(2) it_head-identifier,3(1) '|', 4(50) it_return-message.
    endloop.
  refresh:it_account_gl,
          it_account_payable,
          it_currency_amount,
          it_return.
  endloop.

endform.                    " build_bapi

Regards,

Prabhudas

Former Member
0 Kudos

Hi ,

See the sample code...

check you r entries and correct..


  loop at gt_header.
*    GT_HEADER-BUDAT = sy-datum - 5.
*    GT_HEADER-BLDAT = sy-datum.
    vcounter = 1.
    gt_header-wrbtr = gt_header-wrbtr  * -1.
*FILLING INPORTING PARAMETER STRUCTURE.
    wa_documentheader-comp_code = gt_header-bukrs.
    wa_documentheader-doc_date = gt_header-bldat.
    wa_documentheader-pstng_date = gt_header-budat.
    wa_documentheader-username = sy-uname.
    wa_documentheader-bus_act = 'RFBU'.
    wa_documentheader-doc_type = 'KR'.

    gt_accountpayable-itemno_acc = vcounter.
    gt_accountpayable-vendor_no =  gt_header-accnt.
    append gt_accountpayable.
    clear gt_accountpayable.

    gt_currencyamount-itemno_acc = vcounter.
    gt_currencyamount-currency = 'INR'.
    gt_currencyamount-amt_doccur = gt_header-wrbtr.
    append gt_currencyamount.
    clear gt_currencyamount.
    loop at gt_item where identifier = gt_header-identifier.
      vcounter = vcounter + 1.           .
      gt_accountgl-itemno_acc = vcounter.


      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = gt_item-hkont
        importing
          output = gt_item-hkont.
      gt_accountgl-gl_account = gt_item-hkont.


      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = gt_item-kostl
        importing
          output = gt_item-kostl.

      gt_accountgl-costcenter = gt_item-kostl.
      gt_accountgl-pstng_date = gt_header-budat.
      append gt_accountgl.
      clear gt_accountgl.
      gt_currencyamount-itemno_acc = vcounter.
      gt_currencyamount-currency = 'INR'.
      gt_currencyamount-amt_doccur = gt_item-wrbtr.
      append gt_currencyamount.
      clear gt_currencyamount.
    endloop.
    call function 'BAPI_ACC_DOCUMENT_POST'
      exporting
        documentheader          = wa_documentheader
*       CUSTOMERCPD             = CUSTOMERCPD
*       CONTRACTHEADER          = CONTRACTHEADER
     importing
*       OBJ_TYPE                = OBJ_TYPE
       obj_key                 =  v_refkey
*       OBJ_SYS                 = OBJ_SYS
      tables
       accountgl               = gt_accountgl
*       ACCOUNTRECEIVABLE       = ACCOUNTRECEIVABLE
       accountpayable          = gt_accountpayable
*       ACCOUNTTAX              = ACCOUNTTAX
        currencyamount          = gt_currencyamount
*       CRITERIA                = CRITERIA
*       VALUEFIELD              = VALUEFIELD
*       EXTENSION1              = EXTENSION1
        return                  = gt_return
*       PAYMENTCARD             = PAYMENTCARD
*       CONTRACTITEM            = CONTRACTITEM
*       EXTENSION2              = EXTENSION2
*       REALESTATE              = REALESTATE
.

    break-point.

    if p_test is initial.
      call function 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          = WAIT
* IMPORTING
*   RETURN        = RETURN
      .
    endif.         .


  endloop.

Regards,

Prabhudas