2010 Feb 25 9:13 AM
Hello Friends,
Im using Bapi>> Bapi_acc_document_post to post vendor and customer invoices, im not getting mapping field for the "calculate tax item(checkbox)" technical name is xmwst in any of the bapi strucuture.
please tell me in which bapi structure we have to pass this field so that the tax amount should get calculated automatically.
regards,
Sunny
2010 Feb 25 12:08 PM
You can try the Financial Posting Interface (FIPI).
*=======================================================================
CONSTANTS:
*=======================================================================
c_typehead TYPE stype_pi VALUE 'K',
c_typepos TYPE stype_pi VALUE 'P',
c_waers TYPE waers VALUE 'EUR',
c_blart TYPE blart VALUE 'ZN',
c_debit TYPE bschl VALUE '40',
c_credit TYPE bschl VALUE '50',
c_inddebit TYPE shkzg VALUE 'S',
c_indcredit TYPE shkzg VALUE 'H'.
*===================================================================
FORM append_ftpost
*===================================================================
USING p_stype TYPE stype_pi
p_count TYPE count_pi
p_fnam TYPE bdc_fnam
p_fval TYPE any
CHANGING pt_ftpost TYPE tt_ftpost.
DATA: ls_ftpost LIKE LINE OF pt_ftpost.
CLEAR ls_ftpost.
ls_ftpost-stype = p_stype.
ls_ftpost-count = p_count.
ls_ftpost-fnam = p_fnam.
ls_ftpost-fval = p_fval.
APPEND ls_ftpost TO pt_ftpost.
ENDFORM. "append_ftpost
*===================================================================
FORM post_document
*===================================================================
USING p_bukrs TYPE bukrs
p_gjahr TYPE gjahr
p_monat TYPE monat
p_tip TYPE zga_nomtipcont
p_saknr TYPE saknr
p_bktxt TYPE bktxt
pt_pos TYPE tt_pos.
DATA: lt_blntab TYPE tt_blntab,
lt_ftpost TYPE tt_ftpost,
lt_fttax TYPE tt_fttax,
ls_blntab LIKE LINE OF lt_blntab.
REFRESH: lt_blntab,
lt_ftpost,
lt_fttax.
CALL FUNCTION 'ENQUEUE_EZGA_NOMLOG'
EXPORTING
bukrs = p_bukrs
gjahr = p_gjahr
monat = p_monat
tipcont = p_tip
_wait = 'X'
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc IS NOT INITIAL.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
PERFORM fill_bkpf USING p_bukrs p_gjahr
p_monat p_bktxt
CHANGING lt_ftpost.
PERFORM fill_bseg USING p_saknr p_bktxt
CHANGING pt_pos lt_ftpost.
CALL FUNCTION 'POSTING_INTERFACE_START'
EXPORTING
i_function = 'C'
i_mode = 'N'
i_update = 'S'.
CALL FUNCTION 'POSTING_INTERFACE_DOCUMENT'
EXPORTING
i_tcode = 'FB01'
IMPORTING
e_msgid = sy-msgid
e_msgno = sy-msgno
e_msgty = sy-msgty
e_msgv1 = sy-msgv1
e_msgv2 = sy-msgv2
e_msgv3 = sy-msgv3
e_msgv4 = sy-msgv4
e_subrc = sy-subrc
TABLES
t_blntab = lt_blntab
t_ftpost = lt_ftpost
t_fttax = lt_fttax.
IF sy-subrc IS NOT INITIAL.
MESSAGE i021(zga_nom).
ELSE.
* Grabación en tabla de log y mensaje
READ TABLE lt_blntab INTO ls_blntab INDEX 1.
IF sy-subrc IS INITIAL AND
ls_blntab-belnr IS NOT INITIAL.
PERFORM insert_log USING p_bukrs
p_gjahr
p_monat
p_tip
ls_blntab-belnr.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
CALL FUNCTION 'POSTING_INTERFACE_END'
EXCEPTIONS
session_not_processable = 1
OTHERS = 2.
CALL FUNCTION 'DEQUEUE_EZGA_NOMLOG'
EXPORTING
bukrs = p_bukrs
gjahr = p_gjahr
monat = p_monat
tipcont = p_tip.
ENDFORM. " post_document
*===================================================================
FORM insert_log
*===================================================================
USING p_bukrs TYPE bukrs
p_gjahr TYPE gjahr
p_monat TYPE monat
p_tip TYPE zga_nomtipcont
p_belnr TYPE belnr_d.
DATA: lv_belnr TYPE belnr_d,
ls_log TYPE zga_nomlog.
CLEAR: lv_belnr, ls_log.
ls_log-bukrs = p_bukrs.
ls_log-gjahr = p_gjahr.
ls_log-monat = p_monat.
ls_log-tipcont = p_tip.
ls_log-belnr = p_belnr.
SELECT SINGLE belnr INTO lv_belnr
FROM zga_nomlog
WHERE bukrs = p_bukrs AND
gjahr = p_gjahr AND
monat = p_monat AND
tipcont = p_tip.
IF sy-subrc IS INITIAL.
UPDATE zga_nomlog FROM ls_log.
ELSE.
INSERT zga_nomlog FROM ls_log.
ENDIF.
ENDFORM. "insert_log
*===================================================================
FORM get_posting_date
*===================================================================
USING p_gjahr TYPE gjahr
p_monat TYPE monat
CHANGING p_date TYPE dats.
DATA: lv_date TYPE dats,
lv_month TYPE tfmatage.
IF p_monat <= '12'.
CONCATENATE p_gjahr p_monat '01' INTO lv_date.
CALL FUNCTION 'FIMA_END_OF_PERIOD_DETERMINE'
EXPORTING
i_date = lv_date
i_months = '1'
IMPORTING
e_date_end_of_period = p_date.
ELSE.
CONCATENATE p_gjahr '1231' INTO p_date.
ENDIF.
ENDFORM. "get_posting_date
*======================================================================
FORM fill_bkpf
*======================================================================
USING p_bukrs TYPE bukrs
p_gjahr TYPE gjahr
p_monat TYPE monat
p_bktxt TYPE bktxt
CHANGING pt_ftpost TYPE tt_ftpost.
DATA: lv_posting_date TYPE dats,
lv_dats TYPE char10.
PERFORM get_posting_date USING p_gjahr p_monat
CHANGING lv_posting_date.
WRITE lv_posting_date TO lv_dats.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-BUKRS' p_bukrs
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-MONAT' p_monat
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-BLART' c_blart
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-BUDAT' lv_dats
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-BLDAT' lv_dats
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-WAERS' c_waers
CHANGING pt_ftpost.
*PERFORM append_ftpost USING c_typehead '1'*
*'BKPF-XMWST' 'X'*
*CHANGING pt_ftpost.*
PERFORM append_ftpost USING c_typehead '1'
'BKPF-BKTXT' p_bktxt
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typehead '1'
'BKPF-XBLNR' p_bktxt+0(16)
CHANGING pt_ftpost.
ENDFORM. "fill_bkpf
*===================================================================
FORM fill_bseg
*===================================================================
USING p_saknr TYPE saknr
p_bktxt TYPE bktxt
CHANGING pt_pos TYPE tt_pos
pt_ftpost TYPE tt_ftpost.
DATA: ls_pos LIKE LINE OF pt_pos,
ls_ftpost LIKE LINE OF pt_ftpost,
lv_item TYPE buzei,
lv_wrbtr TYPE wrbtr,
lv_saknr TYPE saknr,
lv_bschl TYPE bschl,
lt_poscont TYPE TABLE OF zga_nompospost,
ls_poscont LIKE LINE OF lt_poscont,
ls_poscontaux LIKE LINE OF lt_poscont.
CLEAR: ls_pos, ls_ftpost.
REFRESH lt_poscont.
LOOP AT pt_pos INTO ls_pos.
MOVE-CORRESPONDING ls_pos TO ls_poscont.
APPEND ls_poscont TO lt_poscont.
ENDLOOP.
SORT lt_poscont BY saknr.
lv_item = '002'.
LOOP AT lt_poscont INTO ls_poscontaux.
ls_poscont = ls_poscontaux.
AT NEW saknr.
CLEAR: lv_wrbtr,
lv_saknr,
lv_bschl.
ENDAT.
CASE ls_poscont-shkzg.
WHEN c_inddebit.
lv_bschl = c_debit.
WHEN c_indcredit.
lv_bschl = c_credit.
ENDCASE.
IF ls_poscont-saknr IS INITIAL.
lv_saknr = p_saknr.
ELSE.
lv_saknr = ls_poscont-saknr.
ENDIF.
IF ls_poscont-indhkont = abap_true.
lv_wrbtr = lv_wrbtr + ls_poscont-wrbtr.
ELSE.
PERFORM fill_bsegpos USING lv_bschl lv_saknr
ls_poscont-wrbtr p_bktxt
ls_poscont-kostl ls_poscont-prctr
lv_item
CHANGING pt_ftpost.
CLEAR: lv_wrbtr,
lv_saknr,
lv_bschl.
lv_item = lv_item + 1.
ENDIF.
AT END OF saknr.
IF ls_poscont-indhkont = abap_true.
PERFORM fill_bsegpos USING lv_bschl lv_saknr
lv_wrbtr p_bktxt
ls_poscont-kostl ls_poscont-prctr
lv_item
CHANGING pt_ftpost.
lv_item = lv_item + 1.
ENDIF.
ENDAT.
ENDLOOP.
ENDFORM. "fill_bseg
*===================================================================
FORM fill_bsegpos
*===================================================================
USING p_bschl TYPE bschl
p_saknr TYPE saknr
p_wrbtr TYPE wrbtr
p_bktxt TYPE bktxt
p_kostl TYPE kostl
p_prctr TYPE prctr
p_pos TYPE buzei
CHANGING pt_ftpost TYPE tt_ftpost.
DATA: lv_wrbtrstr TYPE char16.
WRITE p_wrbtr TO lv_wrbtrstr
CURRENCY c_waers NO-SIGN.
PERFORM append_ftpost USING c_typepos p_pos
'BSEG-BSCHL' p_bschl
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typepos p_pos
'BSEG-HKONT' p_saknr
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typepos p_pos
'BSEG-WRBTR' lv_wrbtrstr
CHANGING pt_ftpost.
PERFORM append_ftpost USING c_typepos p_pos
'BSEG-SGTXT' p_bktxt
CHANGING pt_ftpost.
IF p_kostl IS NOT INITIAL.
PERFORM append_ftpost USING c_typepos p_pos
'COBL-KOSTL' p_kostl
CHANGING pt_ftpost.
ENDIF.
IF p_prctr IS NOT INITIAL.
PERFORM append_ftpost USING c_typepos p_pos
'COBL-PRCTR' p_prctr
CHANGING pt_ftpost.
ENDIF.
ENDFORM. "fill_bsegpos
Edited by: Javier Meavilla Olivas on Feb 25, 2010 1:25 PM
2010 Feb 25 2:23 PM
2011 Dec 07 9:20 AM
Hi Sunny,
I am facing the same problem as you faced in the BAPI_ACC_DOCUMENT_POST to find out the field xmwst in bapi structure. Can you help how you resolved your problem. Thanks in advance.
Regards,
Anvesh.N