Posted: Sun Feb 10, 2008 1:29 am Post subject: BAPI_ACC_DOCUMENT_POST
BAPI_ACC_DOCUMENT_POST - Accounting: Posting
Code:
REPORT acc_bapi_document .
selection-screen begin of block bl01 .
parameters:
check_l radiobutton group rb1,
check_a default 'X' radiobutton group rb1,
post radiobutton group rb1.
selection-screen uline.
parameters:
rev_c radiobutton group rb1,
rev_p radiobutton group rb1.
selection-screen uline.
parameters:
ref_key like bapiache01-obj_key default 'TEST000001BAPICALL',
dest like bdi_logsys-logsys default ' '.
selection-screen end of block bl01 .
data:
gd_documentheader like bapiache09,
gd_customercpd like bapiacpa09,
gd_fica_hd like bapiaccahd,
it_accountreceivable like table of bapiacar09 with header line,
it_accountgl like table of bapiacgl09 with header line,
it_accounttax like table of bapiactx09 with header line,
it_criteria like table of bapiackec9 with header line,
it_valuefield like table of bapiackev9 with header line,
it_currencyamount like table of bapiaccr09 with header line,
it_return like table of bapiret2 with header line,
it_receivers like table of bdi_logsys with header line,
it_fica_it like table of bapiaccait with header line,
it_accountpayable like table of bapiacap09 with header line,
it_paymentcard like table of bapiacpc09 with header line,
it_ext like table of bapiacextc with header line.
* it_re LIKE TABLE OF bapiacre09 WITH HEADER LINE,
* it_ext2 LIKE TABLE OF bapiparex WITH HEADER LINE.
write: / 'Result of Reversal Posting:'. "#EC NOTEXT
perform show_messages.
endif.
commit work.
*---------------------------------------------------------------------*
* Form fill_internal_tables
*---------------------------------------------------------------------*
form fill_internal_tables.
*---------------------------------------------------------------------*
* Form Show_messages
*---------------------------------------------------------------------*
form show_messages.
*---------------------------------------------------------------------*
* FORM fill_accountgl *
*---------------------------------------------------------------------*
form fill_accountgl.
*---------------------------------------------------------------------*
* FORM fill_header *
*---------------------------------------------------------------------*
form fill_header.
* CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
* IMPORTING
* own_logical_system = gd_documentheader-obj_sys.
*---------------------------------------------------------------------*
* FORM fill_contractheader *
*---------------------------------------------------------------------*
form fill_contractheader.
*---------------------------------------------------------------------*
* FORM fill_cpd *
*---------------------------------------------------------------------*
form fill_cpd.
*---------------------------------------------------------------------*
* FORM fill_ar *
*---------------------------------------------------------------------*
form fill_accountar.
*---------------------------------------------------------------------*
* FORM fill_ap *
*---------------------------------------------------------------------*
form fill_accountap.
*---------------------------------------------------------------------*
* FORM fill_tax *
*---------------------------------------------------------------------*
form fill_accounttax.
*---------------------------------------------------------------------*
* FORM fill_currencyamount *
*---------------------------------------------------------------------*
form fill_currencyamount.
*---------------------------------------------------------------------*
* FORM fill_criteria *
*---------------------------------------------------------------------*
form fill_criteria.
*---------------------------------------------------------------------*
* FORM fill_valuefield *
*---------------------------------------------------------------------*
form fill_valuefield.
*---------------------------------------------------------------------*
* FORM fill_extension *
*---------------------------------------------------------------------*
form fill_extension.
*---------------------------------------------------------------------*
* FORM fill_paymentcard *
*---------------------------------------------------------------------*
form fill_paymentcard.
*---------------------------------------------------------------------*
* FORM fill_contractitem *
*---------------------------------------------------------------------*
form fill_contractitem.
*&---------------------------------------------------------------------*
*& Form fill_re
*&---------------------------------------------------------------------*
form fill_re .
DATA: doc_header LIKE bapiache08,
doc_item LIKE bapiacgl08 OCCURS 0 WITH HEADER LINE,
doc_values LIKE bapiaccr08 OCCURS 0 WITH HEADER LINE,
return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
extension1 like BAPIEXTC 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.
* Fill Document Header
doc_header-username = sy-uname.
doc_header-header_txt = 'TEST BOC BAPI POSTING'.
doc_header-comp_code = '1500'.
doc_header-doc_date = '20040901'.
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 = '0000084600'.
doc_item-pstng_date = sy-datlo.
doc_item-item_text = 'TEST POSTING DEBIT ITEM'.
doc_item-costcenter = '0000006300'.
doc_item-orderid = 'M5253'.
APPEND doc_item.
CLEAR doc_item.
* Fill Line 2 of Document Item
doc_item-itemno_acc = '2'.
doc_item-gl_account = '0000021960'.
doc_item-pstng_date = sy-datlo.
doc_item-item_text = 'TEST POSTING CREDIT ITEM'.
APPEND doc_item.
CLEAR doc_item.
* Fill Line 1 of Document Value.
doc_values-itemno_acc = '1'.
doc_values-currency_iso = 'GBP'.
doc_values-amt_doccur = '0.02-'.
APPEND doc_values.
CLEAR doc_values.
* Fill Line 2 of Document Value
doc_values-itemno_acc = '2'.
doc_values-currency_iso = 'GBP'.
doc_values-amt_doccur = '0.02'.
APPEND doc_values.
CLEAR doc_values.
* Add tax code in extension1 table.
extension1-field1 = 'BAPI CALL'.
APPEND EXTENSION1.
* All tables filled - now call BAPI.
CALL FUNCTION 'BAPI_ACC_GL_POSTING_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
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.
FORM build_documentpositions
TABLES lt_currencyamount TYPE tt_currencyamount
lt_accountgl TYPE tt_acountlg
lt_accounttax TYPE tt_accounttax
USING ls_data LIKE LINE OF gt_data.
DATA: ls_accountgl LIKE LINE OF lt_accountgl,
ls_currencyamount LIKE LINE OF lt_currencyamount,
ls_accounttax LIKE LINE OF lt_accounttax,
ls_vbrp TYPE vbrp.
DATA: lv_debitor TYPE kunnr,
lv_akont TYPE knb1-akont,
lv_swap_vbeln TYPE char20,
lv_swap_posnr TYPE char20,
lv_swap_vbelv TYPE char20,
lv_swap_posnv TYPE char20,
lv_swap_vtrnr TYPE char20,
lv_lkz TYPE adrc-country,
lv_land TYPE t005t-landx,
lv_tax_code TYPE c LENGTH 2,
lv_tax_rate TYPE fwste.
CLEAR: lt_currencyamount, lt_accountgl.
SELECT SINGLE aubel aupos vbelv posnv prctr "ermittle Auftrag zur Faktura
FROM vbrp
INTO CORRESPONDING FIELDS OF ls_vbrp
WHERE vbeln = ls_data-vbeln
AND posnr = ls_data-posnr.
SELECT SINGLE akont
FROM knb1
INTO lv_akont
WHERE kunnr = ls_data-vtrnr
AND bukrs = ls_data-bukrs.
*
* 04.02.2008 FIS/pb
* Korrektur : Land steht schon in der KNA1
*
SELECT SINGLE land1
FROM kna1
INTO lv_lkz
WHERE kunnr = ls_data-vtrnr.
* break fis-kemmer.
IF ls_data-vtrnr EQ '0000900021' OR ls_data-vtrnr EQ '0000900008'.
lv_tax_code = '46'.
ls_accounttax-itemno_acc = '03'.
ls_accounttax-tax_code = lv_tax_code.
ls_accounttax-gl_account = '0000263110'.
ls_accounttax-direct_tax = 'X'.
ls_accounttax-cond_key = 'MWVS'.
ls_accounttax-acct_key = 'VST'.
APPEND ls_accounttax TO lt_accounttax.
CLEAR ls_accounttax.
ls_currencyamount-amt_base = ls_data-prov.
ELSE.
CASE lv_lkz.
WHEN 'DE'.
lv_tax_code = 'V1'.
WHEN OTHERS.
lv_tax_code = 'U7'.
ENDCASE.
ENDIF.
BAPI_ACC_DOCUMENT_POST and tax posting through the BAPI
By Nicolai marco.
I use this function in some program i try to give to u how to set the minimum value in the structure/tables of the bapi.
DOCUMENTHEADER
Code:
BUS_ACT = 'RFBU' "for FI document
USERNAME = sy-uname
HEADER_TXT = your text
COMP_CODE = Company code
DOC_DATE = Document date
PSTNG_DATE = Posting date
FISC_YEAR(1) = The year of posting date
FIS_PERIOD(1) = the period of posting date
DOC_TYPE = document type
if you set a different year or period from the value that you have in the posting date the bapi trigger an error
ACCOUNT GL
Code:
ITEMNO_ACC = progessive number
GL_ACCOUNT = G/L Account
ITEM_TEXT = item text
DOC_TYPE = document type (the same of the header for all item)
COMP_CODE = company code (the same of the header for all item)
BUS_AREA = business area
TAX_CODE = tax code
if you set a different doc_type or company code for each item the bapi trigger an error
ACCOUNTTAX
Code:
ITEMNO_ACC = progressive number
GL_ACCOUNT = G/L Account referred to TAX CODE
TAX_CODE = TAX CODE
TAX_RATE = TAX RATE
ITEMNO_TAX = progressive number which tax item is referred
CURRENCYAMOUNT
Code:
ITEMNO_ACC = progressive number
CURRENCY = currency
CURRENCY_ISO = iso currency that you find in TCURC-ISOCD table
AMT_DOCCUR = amount with sign the sign +/- identify Debit/Credit Indicator
this field only for tax record
AMT_BASE = is the AMT_DOCCUR of the line which ypu want to calculate the tax with sign
TAX_AMT = tax amount
usually for calculate the correct value i use these functions 'CALCULATE_TAX_FROM_GROSSAMOUNT' or 'CALCULATE_TAX_FROM_NET_AMOUNT' it depends if i have the net or gross amount.
DATA: it_acc_gl LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,
it_acc_ap LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,
it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
it_curr_amt LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
it_doc_header LIKE bapiache09 OCCURS 0 WITH HEADER LINE,
it_acc_tax LIKE bapiactx09 OCCURS 0 WITH HEADER LINE,
obj_type LIKE bapiache09-obj_type,
obj_key LIKE bapiache09-obj_key,
obj_sys LIKE bapiache09-obj_sys,
pstng_date LIKE it_doc_header-pstng_date,
doc_date LIKE it_doc_header-doc_date,
loop_cnt TYPE i VALUE 0,
gv_vendor(10) TYPE c,
gv_gl_acc(10) TYPE c.
LOOP AT bdc_source.
* First line of table is heading so don't do anything
IF bdc_layout IS INITIAL.
MOVE bdc_source TO bdc_layout.
TRANSLATE bdc_layout TO UPPER CASE.
CONTINUE.
ENDIF.
bdc_out = bdc_source.
CLEAR: obj_type, obj_sys, obj_key, pstng_date, doc_date, gv_vendor,
gv_gl_acc.
* Setup the dates in correct format
CONCATENATE bdc_source-col_c+6(4) bdc_source-col_c(2)
bdc_source-col_c+3(2) INTO pstng_date.
CONCATENATE bdc_source-col_b+6(4) bdc_source-col_b(2)
bdc_source-col_b+3(2) INTO doc_date.
* Padding zeros, very important otherwise bunch of stuff is missing
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = bdc_source-col_e
IMPORTING
output = gv_vendor.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = bdc_source-col_j
IMPORTING
output = gv_gl_acc.
* Header
REFRESH it_doc_header.
it_doc_header-bus_act = 'RFBU'.
it_doc_header-username = sy-uname.
it_doc_header-header_txt = bdc_source-col_h. " Invoice Text
it_doc_header-comp_code = bdc_source-col_a. " Company Code
it_doc_header-doc_date = doc_date. " Invoice Date
it_doc_header-pstng_date = pstng_date. " Posting Date
it_doc_header-doc_type = 'KR'. " Return Order...?
it_doc_header-ref_doc_no = bdc_source-col_d. " Invoice Number
APPEND it_doc_header.
* GL Account
REFRESH it_acc_gl.
it_acc_gl-itemno_acc = '1'.
it_acc_gl-gl_account = gv_gl_acc. " GL Account
it_acc_gl-item_text = bdc_source-col_o. " Line Item Text
it_acc_gl-doc_type = 'KR'. " Return Order...?
it_acc_gl-comp_code = bdc_source-col_a. " Company Code
it_acc_gl-pstng_date = pstng_date. " Posting Date
it_acc_gl-vendor_no = gv_vendor. " Vendor Number
it_acc_gl-costcenter = bdc_source-col_k. " Cost Center
it_acc_gl-wbs_element = bdc_source-col_q. " WBS Element
"it_acc_gl-tax_code = bdc_source-col_m. " Tax Code
it_acc_gl-network = bdc_source-col_p. " Internal Order
conv_s_amt = bdc_source-col_f. " Invoice Amount
REPLACE all occurrences of ',' in conv_s_amt WITH ''.
IF conv_s_amt < 0.
it_acc_gl-de_cre_ind = 'H'. " H-Credit
conv_s_amt = - conv_s_amt.
ELSE.
it_acc_gl-de_cre_ind = 'S'. " S-Debit
ENDIF.
CONDENSE conv_s_amt.
APPEND it_acc_gl.
* AP Account
REFRESH it_acc_ap.
it_acc_ap-itemno_acc = '2'. " Invoice Number
it_acc_ap-vendor_no = gv_vendor. " Vendor Number
it_acc_ap-comp_code = bdc_source-col_a. " Company Code
it_acc_ap-item_text = bdc_source-col_o. " Line Item Text
APPEND it_acc_ap.
* Currancy
REFRESH it_curr_amt.
it_curr_amt-itemno_acc = '1'. " Invoice Number
it_curr_amt-curr_type = '00'.
it_curr_amt-currency = bdc_source-col_g. " Currancy
it_curr_amt-amt_doccur = conv_s_amt. " Line Item Amount
APPEND it_curr_amt.
it_curr_amt-itemno_acc = '2'. " Invoice Number
it_curr_amt-curr_type = '00'.
it_curr_amt-currency = bdc_source-col_g. " Currancy
it_curr_amt-amt_doccur = conv_s_amt * -1. " Line Item Amount
APPEND it_curr_amt.
REFRESH it_return.
* Do the post to GL Account and AP
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = it_doc_header
IMPORTING
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
TABLES
accountgl = it_acc_gl
currencyamount = it_curr_amt
accountpayable = it_acc_ap
return = it_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
* Check for any errors
loop_cnt = 0.
LOOP AT it_return.
IF it_return-type = 'E'.
bdc_out-code = 'E'.
error_count = error_count + 1.
ELSE.
bdc_out-code = 'S'.
ENDIF.
loop_cnt = loop_cnt + 1.
IF loop_cnt = 1.
bdc_out-mesg1 = it_return-message.
ELSE.
IF loop_cnt = 2.
bdc_out-mesg2 = it_return-message.
ENDIF.
ENDIF.
ENDLOOP.
APPEND bdc_out.
cur_line = cur_line + 1.
ENDLOOP.
Age: 160 Joined: 04 Oct 2007 Posts: 1218 Location: Санкт-Петербург
Posted: Wed Apr 03, 2013 9:34 am Post subject:
Code:
*---------------------------------------------------------------------*
* FORM post_addition_acc_document *
*---------------------------------------------------------------------*
FORM post_addition_acc_document
TABLES pt_item STRUCTURE bapi_incinv_create_item
pt_mseg STRUCTURE mseg
USING ps_ekko TYPE ekko
CHANGING ps_header TYPE bapi_incinv_create_header.
CONSTANTS:
c_taklv_0 TYPE mara-taklv VALUE '0',
c_taklv_1 TYPE mara-taklv VALUE '1',
c_taklv_2 TYPE mara-taklv VALUE '2'.
DATA: ls_header TYPE bapiache09,
lt_return TYPE TABLE OF bapiret2,
ls_return TYPE bapiret2.
DATA: l_message TYPE text120.
DATA: l_itemno_acc TYPE posnr_acc,
l_itemno_tax TYPE taxps,
lt_glacc TYPE TABLE OF bapiacgl09,
ls_glacc TYPE bapiacgl09,
lt_extension TYPE TABLE OF bapiacextc,
ls_extension TYPE bapiacextc,
lt_accounttax TYPE TABLE OF bapiactx09,
ls_accounttax TYPE bapiactx09,
lt_accountpayable TYPE TABLE OF bapiacap09,
ls_accountpayable TYPE bapiacap09,
lt_currencyamount TYPE TABLE OF bapiaccr09,
ls_currencyamount TYPE bapiaccr09.
DATA: BEGIN OF ls_obj_key,
belnr TYPE bkpf-belnr,
bukrs TYPE bkpf-bukrs,
gjahr TYPE bkpf-gjahr,
END OF ls_obj_key.
DATA: l_flag TYPE as4flag,
l_obj_type TYPE bapiache09-obj_type,
l_obj_key TYPE bapiache09-obj_key,
l_obj_sys TYPE bapiache09-obj_sys.
TYPES: BEGIN OF ty_mwskz,
taklv TYPE mara-taklv,
mwskz TYPE ekpo-mwskz,
dmbtr TYPE mseg-dmbtr,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
lifn2 TYPE ekpa-lifn2,
bstmg TYPE mseg-bstmg,
bstme TYPE mseg-bstme,
bprme TYPE ekpo-bprme,
bpmng TYPE mseg-bpmng,
wmwst TYPE rtax1u15-wmwst,
kbetr TYPE rtax1u15-kbetr,
hkont TYPE rtax1u15-hkont,
kawrt TYPE rtax1u15-kawrt,
ktosl TYPE rtax1u15-ktosl,
kschl TYPE rtax1u15-kschl,
msatz TYPE rtax1u15-msatz,
END OF ty_mwskz.
DATA: lr_ebeln TYPE RANGE OF mseg-ebeln,
ls_ebeln LIKE LINE OF lr_ebeln.
DATA: lt_taklv TYPE TABLE OF mara-taklv,
l_taklv TYPE mara-taklv,
lt_lifn2 TYPE TABLE OF ekpa-lifn2,
l_lifn2 TYPE ekpa-lifn2,
lt_ekpo TYPE TABLE OF ekpo,
ls_ekpo TYPE ekpo,
lt_ekpa TYPE TABLE OF ekpa,
ls_ekpa TYPE ekpa,
ls_mseg TYPE mseg,
lt_mwskz TYPE TABLE OF ty_mwskz,
ls_mwskz TYPE ty_mwskz,
lt_mwdat TYPE TABLE OF rtax1u15,
ls_mwdat TYPE rtax1u15.
ls_ebeln-sign = 'I'.
ls_ebeln-option = 'EQ'.
LOOP AT pt_mseg.
ls_ebeln-low = pt_mseg-ebeln.
COLLECT ls_ebeln INTO lr_ebeln.
ENDLOOP.
CHECK NOT lr_ebeln IS INITIAL.
* Infosammlung aus EKPA (Partnerrollen im Einkauf)
SELECT *
INTO TABLE lt_ekpa
FROM ekpa
WHERE ebeln IN lr_ebeln.
* Infosammlung aus EKPO (Einkaufsbelegposition)
* Positionstab auslesen (Nettobetrag, Menge)
SELECT *
INTO TABLE lt_ekpo
FROM ekpo
WHERE ebeln IN lr_ebeln.
LOOP AT pt_mseg INTO ls_mseg.
READ TABLE lt_ekpo INTO ls_ekpo
WITH KEY ebeln = ls_mseg-ebeln
ebelp = ls_mseg-ebelp.
CHECK sy-subrc IS INITIAL.
CHECK NOT ls_ekpo-matnr IS INITIAL.
* обрабатывать только позиции, у которых роль партнера Z8
READ TABLE lt_ekpa INTO ls_ekpa
WITH KEY ebeln = ls_ekpo-ebeln
parvw = 'Z8'.
CHECK sy-subrc IS INITIAL.
LOOP AT lt_mwskz INTO ls_mwskz WHERE lifn2 = l_lifn2
AND taklv = l_taklv.
SUBTRACT ls_mwskz-wmwst FROM ls_currencyamount-amt_doccur.
* SUBTRACT ls_mwskz-kawrt FROM ls_currencyamount-amt_base.
* SUBTRACT ls_mwskz-wmwst FROM ls_currencyamount-tax_amt.
LOOP AT lt_return INTO ls_return WHERE type CA 'EAX'.
ENDLOOP.
IF sy-subrc IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.