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

Tax data with BAPI_ACC_DOCUMENT_POST

Former Member
0 Likes
1,978


Hi All,

I am facing problem in passing tax data to BAPI BAPI_ACC_DOCUMENT_POST.

below is my code:

   *fill header
gd_documentheader-username   =  sy-uname.
gd_documentheader-header_txt = 'Test'.
gd_documentheader-comp_code  = p_ccode.   "SQ
gd_documentheader-doc_date   =  sy-datum.
gd_documentheader-pstng_date =  sy-datum.
gd_documentheader-doc_type   = 'KR'.
gd_documentheader-ref_doc_no = p_xblnr. "SQ
gd_documentheader-bus_act = 'RMWE'.

city = p_city.
state = p_state.
zipcode = p_zip.
*get tax juridisction code
IF NOT ( city     IS INITIAL ) AND
   NOT ( state    IS INITIAL ) AND
   NOT ( zipcode IS INITIAL ).
  SELECT SINGLE rfcdest INTO ttxd-rfcdest FROM ttxd
   WHERE kalsm = 'TAXUSX'.
  CLEAR x_com_jur.
  REFRESH t_com_jur.
  x_com_jur-city     =  city.
  x_com_jur-state    =  state.
  IF zipcode+5(4) EQ space.
    zipcode+5(4) = '0000'.
  ENDIF.
  CONCATENATE zipcode+0(5) '-' zipcode+5(4)
         INTO x_com_jur-zipcode.
  x_com_jur-country  = 'US'.

  CALL FUNCTION 'RFC_DETERMINE_JURISDICTION'
    DESTINATION ttxd-rfcdest
    EXPORTING
      location_data    = x_com_jur
    IMPORTING
      location_err     = x_com_err
    TABLES
      location_results = t_com_jur.
  IF sy-subrc = 0.
    READ TABLE t_com_jur INTO x_com_jur INDEX 1.
    it_accountgl-taxjurcode =  x_com_jur-txjcd.
  ENDIF.
ENDIF.
*---------------------------------
*fill AP (line 1) - vendor related data
SELECT SINGLE zterm FROM lfb1 INTO p_zterm WHERE lifnr = p_lifnr.
it_accountpayable-itemno_acc = 1.
it_accountpayable-pmnttrms   = p_zterm. "SQ
it_accountpayable-vendor_no  = p_lifnr. "SQ
*it_accountpayable-item_text = 'S2P Testing in UDR1'. - SQ
it_accountpayable-pymt_meth = p_pmet. "- SQ
APPEND it_accountpayable.

*fill GL (line 2)
it_accountgl-itemno_acc      =  2.
*item_text - sq
IF p_asset IS NOT INITIAL.
  TABLES : anlz,
           anla.
  SELECT SINGLE * FROM anlz  WHERE anln1 = p_asset.
  SELECT SINGLE * FROM anla WHERE anln1 = p_asset.
*concatenate '00' anla-KTOGR into it_accountgl-gl_account .
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = anla-ktogr
    IMPORTING
      output = it_accountgl-gl_account.
  it_accountgl-asset_no = p_asset.
  it_accountgl-sub_number = '0000'.
  it_accountgl-cs_trans_t = '105'.
  it_accountgl-acct_type = 'A'.
ELSE.
  it_accountgl-gl_account      = p_gl.
  it_accountgl-costcenter      = p_cc.
  it_accountgl-wbs_element     = p_posid.
ENDIF.
it_accountgl-comp_code       = p_ccode.
it_accountgl-tax_code = p_txcd.  "SQ
it_accountgl-pstng_date      =  sy-datum.
it_accountgl-fisc_year       =  sy-datum(4).
APPEND it_accountgl.
*fill currency ammounts for lines 1 & 2
it_currencyamount-currency    = p_waers.  "SQ
it_currencyamount-itemno_acc  = 1.
it_currencyamount-amt_doccur  = - p_totamt.  "SQ
APPEND it_currencyamount.
CLEAR  it_currencyamount. .
it_currencyamount-itemno_acc  = 2.
it_currencyamount-currency    = p_waers.  "SQ
it_currencyamount-amt_base    =  P_lamt.
it_currencyamount-TAX_AMT  = p_ttax.  "SQ
APPEND it_currencyamount.
*tax data
it_accounttax-itemno_acc = 2.
it_accounttax-tax_code = p_txcd.
it_accounttax-GL_ACCOUNT = p_gl.
APPEND it_accounttax.

   CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
  EXPORTING
    documentheader          = gd_documentheader
IMPORTING
   obj_key                 = wa_obj_key
  TABLES
   accountgl               = it_accountgl
*   ACCOUNTRECEIVABLE       =
   accountpayable          = it_accountpayable
   ACCOUNTTAX              = it_accounttax
    currencyamount          = it_currencyamount
*   CRITERIA                =
*   VALUEFIELD              =
*   EXTENSION1              =
    return                  =  it_return

          .


COMMIT WORK.

I am getting folowwing error.

Message Type:    E

Message Class:   RW

Message Number:  609

Message:         Error in document: BKPFF $ UDRCLNT200

Message Type:    E

Message Class:   RW

Message Number:  602

Message:         Required field ACCT_KEY was not transferred in parameter ACCOUNTTAX

Message Type:    E

Message Class:   FF

Message Number:  765

Message:         Transaction key  does not exist

Message Type:    E

Message Class:   ZVAL1

Message Number:  021

Message:         Cost Center US00000012 is closed.

Message Type:    E

Message Class:   KI

Message Number:  235

Message:         Account 54010011 requires an assignment to a CO object

Can anyone help me on this.

Regards,

Priyaranjan

2 REPLIES 2
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
1,057

Hi Priyaranjan

The error log clearly mentions the reason.. One of the message is custom one check your enhancement which are thoriwng this message. Pass account key and assign a cost center/wbs/internal order(better ask your functional) to the GL account line item.

Message Type:    E

Message Class:   ZVAL1

Message Number:  021

Message:         Cost Center US00000012 is closed.

Nabheet

Read only

0 Likes
1,057

Hi Nabheet,

I have passed these required data.

Now erros is :

Message Type:    E

Message Class:   RW

Message Number:  609

Message:         Error in document: BKPFF $ UDRCLNT200

Message Type:    E

Message Class:   RW

Message Number:  008

Message:         FI/CO interface: Inconsistent currency information

Below is the code

   *fill header
gd_documentheader-username   =  sy-uname.
gd_documentheader-header_txt = 'Test'.
gd_documentheader-comp_code  = p_ccode. gd_documentheader-doc_date   =  sy-datum.
gd_documentheader-pstng_date =  sy-datum.
gd_documentheader-doc_type   = 'KR'.
gd_documentheader-ref_doc_no = p_xblnr.

city = p_city.
state = p_state.
zipcode = p_zip.
*get tax juridisction code
IF NOT ( city     IS INITIAL ) AND
   NOT ( state    IS INITIAL ) AND
   NOT ( zipcode IS INITIAL ).
  SELECT SINGLE rfcdest INTO ttxd-rfcdest FROM ttxd
   WHERE kalsm = 'TAXUSX'.
  CLEAR x_com_jur.
  REFRESH t_com_jur.
  x_com_jur-city     =  city.
  x_com_jur-state    =  state.
  IF zipcode+5(4) EQ space.
    zipcode+5(4) = '0000'.
  ENDIF.
  CONCATENATE zipcode+0(5) '-' zipcode+5(4)
         INTO x_com_jur-zipcode.
  x_com_jur-country  = 'US'.

  CALL FUNCTION 'RFC_DETERMINE_JURISDICTION'
    DESTINATION ttxd-rfcdest
    EXPORTING
      location_data    = x_com_jur
    IMPORTING
      location_err     = x_com_err
    TABLES
      location_results = t_com_jur.
  IF sy-subrc = 0.
    READ TABLE t_com_jur INTO x_com_jur INDEX 1.
    it_accountgl-taxjurcode =  x_com_jur-txjcd.
  ENDIF.
ENDIF.
*---------------------------------
*fill AP (line 1) - vendor related data
SELECT SINGLE zterm FROM lfb1 INTO p_zterm WHERE lifnr = p_lifnr.
it_accountpayable-itemno_acc = 1.
it_accountpayable-tax_code = p_txcd.
it_accountpayable-pmnttrms   = p_zterm. "SQ
it_accountpayable-vendor_no  = p_lifnr. "SQ
*it_accountpayable-item_text =

it_accountpayable-pymt_meth = p_pmet. "- SQ
APPEND it_accountpayable.

*fill GL (line 2)
it_accountgl-itemno_acc      =  2.
*item_text - sq
IF p_asset IS NOT INITIAL.
  TABLES : anlz,
           anla.
  SELECT SINGLE * FROM anlz  WHERE anln1 = p_asset.
  SELECT SINGLE * FROM anla WHERE anln1 = p_asset.
*concatenate '00' anla-KTOGR into it_accountgl-gl_account .
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = anla-ktogr
    IMPORTING
      output = it_accountgl-gl_account.
  it_accountgl-asset_no = p_asset.
  it_accountgl-sub_number = '0000'.
  it_accountgl-cs_trans_t = '105'.
  it_accountgl-acct_type = 'A'.
ELSE.
  it_accountgl-gl_account      = p_gl.
  it_accountgl-costcenter      = p_cc.
  it_accountgl-wbs_element     = p_posid.
ENDIF.

it_accountgl-comp_code       = p_ccode.
it_accountgl-tax_code = p_txcd.  "SQ
it_accountgl-pstng_date      =  sy-datum.
it_accountgl-fisc_year       =  sy-datum(4).
APPEND it_accountgl.

CLEAR it_currencyamount.
*fill currency ammounts for lines 1 & 2
it_currencyamount-currency    = p_waers.  "SQ
it_currencyamount-curr_type = '00'.
it_currencyamount-itemno_acc  = 1.
it_currencyamount-amt_base = - '1000'.
it_currencyamount-amt_doccur  = '200'. "p_totamt.
*it_currencyamount-tax_amt  = p_ttax.
APPEND it_currencyamount.

CLEAR it_currencyamount.
it_currencyamount-itemno_acc  = 2.
it_currencyamount-currency    = p_waers.  "SQ
it_currencyamount-amt_doccur  = '800'.
APPEND it_currencyamount.

*tax data
it_accounttax-itemno_acc = 1.
it_accounttax-tax_code = p_txcd.
**it_accounttax-tax_rate = p_ttax.
it_accounttax-gl_account = p_gl.
it_accounttax-acct_key = 'NVV'.
it_accounttax-cond_key = 'XP2I'.
*it_accounttax-direct_tax = 'X'.
APPEND it_accounttax.

   CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
  EXPORTING
    documentheader          = gd_documentheader
IMPORTING
   obj_key                 = wa_obj_key
  TABLES
   accountgl               = it_accountgl
*   ACCOUNTRECEIVABLE       =
   accountpayable          = it_accountpayable
   accounttax              = it_accounttax
    currencyamount          = it_currencyamount
*   CRITERIA                =
*   VALUEFIELD              =
*   EXTENSION1              =
    return                  =  it_return

          .


COMMIT WORK.

Regards,

Priyaranjan