‎2005 Jun 21 5:44 PM
Hi,
I'm using a Bapi:
BAPI_ACC_DOCUMENT_POST
to successfully post a new invoice document. This works fine. What is the simplest method of getting the document number of the newly created document in code?
Is there a function, or something in the BAPI I'm missing?
Many thanks
Sam
‎2005 Jun 24 9:29 PM
Hi,
There is a much cleaner and I think easier way to get the document number. Use function module FI_ACCBELNR_GET immediately after calling 'BAPI_ACC_DOCUMENT_POST'. See below for an example.
Best Regards,
James Gaddis
Post an FI document
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = p_header
IMPORTING
obj_type = l_obj_type
obj_key = l_obj_key
obj_sys = l_obj_sys
TABLES
accountgl = i_glacct
currencyamount = i_amount
return = return2.
Move the object key to the FI doc parameter
CALL FUNCTION 'FI_ACCBELNR_GET'
TABLES
t_belnr = it_belnr.
READ TABLE it_belnr INDEX 1.
p_fidoc = it_belnr-belnr_e.
You can optionally add a BAPI message with the FI document number if you want to include the document number in your own message:
IF NOT p_fidoc IS INITIAL.
PERFORM fill_bapireturn_message
TABLES return2
USING 'S' 'Zxxx' 'nnn'
p_fidoc
space space space.
ENDIF.
‎2005 Jun 21 6:14 PM
Hi Sam,
Don't have access to a SAP box right now but;
Did you look into the export parameter OBJ_KEY.
Doesn't it give you the doc number created?
Thanks, Debasish
‎2005 Jun 21 6:17 PM
I would assume that this new document number would come back to you via the RETURN table of the BAPI. In the RETURN table there will be messages. example... "Document Number 123456 was saved successfully". In that case, your document number will be in the MESSAGE_V1, MESSAGE_V2, MESSAGE_V3, or MESSAGE_V4 field of the RETURN table.
I would suggest to read that table for the specific message and get the document number from there.
READ TABLE RETURN WITH KEY ID = MESSID
NUMBER = MESSNUMBER.
if sy-subrc = 0.
document_number = return-MESSAGE_V1.
endif.
Regards,
Rich Heilman
‎2005 Jun 21 6:20 PM
‎2005 Jun 21 6:21 PM
Hi Sims
The document number is in the OBJ_KEY field that is returned when calling the function module BAPI_ACC_DOCUMENT_POST. The OBJ_KEY is a concatenation of Document number, Company Code and Fiscal Year. To get just the Document Number, you'll need to get the first 10 characters of OBJ_KEY. (example: wa_belnr = WA_OBK_KET(10).)
I hope this helps.
Mike Vondran.
‎2005 Jun 21 6:31 PM
Hi,
in the OBJ_KEY I get a unique value, which I can see in table BKPF , but this is not the same as the Document Number. The return structure, does not contain this number either. The way I am working out the Document Number , is by getting the all the records in BKPF, and then sorting them. But what I really need is just the document number.
Regards Sims
‎2005 Jun 21 6:33 PM
hi,
don't know if this may help?
REPORT Z_ST_POST_NO_PO .
PARAMETERS:
ref_key LIKE bapiache01-obj_key DEFAULT 'TEST000001BAPICALL',
dest LIKE bdi_logsys-logsys DEFAULT 'R3ICLNT800'.
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 bapiackecr WITH HEADER LINE,
it_valuefield LIKE TABLE OF bapiackeva 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 bapiextc WITH HEADER LINE,
it_re LIKE TABLE OF bapiacre09 WITH HEADER LINE,
it_ext2 LIKE TABLE OF bapiparex WITH HEADER LINE.
PERFORM fill_internal_tables.
DATA: l_type LIKE gd_documentheader-obj_type,
l_key LIKE gd_documentheader-obj_key,
l_sys LIKE gd_documentheader-obj_sys.
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.
.
data myret like bapiret2.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN = myret
.
WRITE: / 'Result of post:'. "#EC NOTEXT
PERFORM show_messages.
----
Form fill_internal_tables
----
FORM fill_internal_tables.
PERFORM fill_header.
PERFORM fill_accountgl.
PERFORM fill_accountar.
PERFORM fill_accountap.
PERFORM fill_accounttax.
PERFORM fill_currencyamount.
PERFORM fill_criteria.
PERFORM fill_valuefield.
PERFORM fill_re.
PERFORM fill_cpd.
PERFORM fill_contractitem.
PERFORM fill_contractheader.
PERFORM fill_paymentcard.
PERFORM fill_extension.
ENDFORM. " fill_internal_tables
----
Form Show_messages
----
FORM show_messages.
IF it_return[] IS INITIAL.
WRITE: / 'no messages'.
ELSE.
SKIP 1.
LOOP AT it_return.
WRITE: / it_return-type,
(2) it_return-id,
it_return-number,
(80) it_return-message,
IT_RETURN-LOG_NO
IT_RETURN-LOG_MSG_NO
IT_RETURN-MESSAGE_V1
IT_RETURN-MESSAGE_V2
IT_RETURN-MESSAGE_V3
IT_RETURN-MESSAGE_V4
(20) it_return-parameter,
(3) it_return-row,
it_return-field.
IT_RETURN-SYSTEM
ENDLOOP.
ENDIF.
ULINE.
ENDFORM. " Show_messages
----
FORM fill_accountgl *
----
FORM fill_accountgl.
CLEAR it_accountgl.
it_accountgl-itemno_acc = '01'.
it_accountgl-gl_account = '0000476900'.
IT_ACCOUNTGL-STAT_CON =
IT_ACCOUNTGL-REF_KEY_1 =
IT_ACCOUNTGL-REF_KEY_2 =
IT_ACCOUNTGL-REF_KEY_3 =
it_accountgl-tax_code = 'V0'.
IT_ACCOUNTGL-ACCT_KEY =
IT_ACCOUNTGL-TAXJURCODE =
IT_ACCOUNTGL-CSHDIS_IND =
IT_ACCOUNTGL-ALLOC_NMBR =
it_accountgl-item_text = 'Line 1'.
IT_ACCOUNTGL-BUS_AREA =
it_accountgl-costcenter = '0000001000'.
IT_ACCOUNTGL-ORDERID =
it_accountgl-ext_object_id =
it_accountgl-bus_scenario =
IT_ACCOUNTGL-MATERIAL =
IT_ACCOUNTGL-QUANTITY =
IT_ACCOUNTGL-BASE_UOM =
IT_ACCOUNTGL-BASE_UOM_ISO =
IT_ACCOUNTGL-PLANT =
it_accountgl-profit_ctr =
IT_ACCOUNTGL-PART_PRCTR =
IT_ACCOUNTGL-WBS_ELEMENT =
IT_ACCOUNTGL-NETWORK =
IT_ACCOUNTGL-CMMT_ITEM =
IT_ACCOUNTGL-FUNDS_CTR =
IT_ACCOUNTGL-FUND =
IT_ACCOUNTGL-SALES_ORD =
IT_ACCOUNTGL-S_ORD_ITEM =
IT_ACCOUNTGL-P_EL_PRCTR =
IT_ACCOUNTGL-BILL_TYPE =
IT_ACCOUNTGL-DISTR_CHAN =
IT_ACCOUNTGL-SOLD_TO =
IT_ACCOUNTGL-DIVISION =
IT_ACCOUNTGL-SALESORG =
IT_ACCOUNTGL-SALES_OFF =
IT_ACCOUNTGL-SALES_GRP =
IT_ACCOUNTGL-INV_QTY =
IT_ACCOUNTGL-SALES_UNIT =
IT_ACCOUNTGL-SALES_UNIT_ISO =
IT_ACCOUNTGL-INV_QTY_SU =
IT_ACCOUNTGL-NET_WEIGHT =
IT_ACCOUNTGL-GROSS_WT =
IT_ACCOUNTGL-UNIT_OF_WT =
IT_ACCOUNTGL-UNIT_OF_WT_ISO =
IT_ACCOUNTGL-VOLUME =
IT_ACCOUNTGL-VOLUMEUNIT =
IT_ACCOUNTGL-VOLUMEUNIT_ISO =
it_accountgl-fm_area =
it_accountgl-log_proc =
it_accountgl-ac_doc_no =
it_accountgl-acct_type =
it_accountgl-doc_type =
it_accountgl-comp_code =
it_accountgl-func_area =
it_accountgl-plant =
it_accountgl-fis_period =
it_accountgl-fisc_year =
it_accountgl-pstng_date =
it_accountgl-value_date =
it_accountgl-customer =
it_accountgl-vendor_no =
it_accountgl-costobject =
it_accountgl-acttype =
it_accountgl-order_itno =
it_accountgl-routing_no =
it_accountgl-activity =
it_accountgl-cond_type =
it_accountgl-cond_count =
it_accountgl-cond_st_no =
it_accountgl-co_busproc =
it_accountgl-asset_no =
it_accountgl-sub_number =
it_accountgl-de_cre_ind =
it_accountgl-p_el_prctr =
it_accountgl-xmfrw =
it_accountgl-po_pr_qnt =
it_accountgl-po_pr_uom =
it_accountgl-po_pr_uom_iso =
it_accountgl-entry_qnt =
it_accountgl-entry_uom =
it_accountgl-entry_uom_iso =
it_accountgl-item_cat =
it_accountgl-matl_type =
it_accountgl-mvt_ind =
it_accountgl-reval_ind =
it_accountgl-orig_group =
it_accountgl-orig_mat =
it_accountgl-serial_no =
it_accountgl-part_acct =
it_accountgl-tr_part_ba =
it_accountgl-trade_id =
it_accountgl-val_area =
it_accountgl-val_type =
it_accountgl-asval_date =
it_accountgl-po_number =
it_accountgl-po_item =
APPEND it_accountgl.
it_accountgl-itemno_acc = '02'.
it_accountgl-gl_account = '0000476900'.
IT_ACCOUNTGL-STAT_CON =
IT_ACCOUNTGL-REF_KEY_1 =
IT_ACCOUNTGL-REF_KEY_2 =
IT_ACCOUNTGL-REF_KEY_3 =
it_accountgl-tax_code = 'V0'.
IT_ACCOUNTGL-ACCT_KEY =
IT_ACCOUNTGL-TAXJURCODE =
IT_ACCOUNTGL-CSHDIS_IND =
IT_ACCOUNTGL-ALLOC_NMBR =
it_accountgl-item_text = 'Line 1'.
IT_ACCOUNTGL-BUS_AREA =
it_accountgl-costcenter = '0000001000'.
IT_ACCOUNTGL-ORDERID =
it_accountgl-ext_object_id =
it_accountgl-bus_scenario =
IT_ACCOUNTGL-MATERIAL =
IT_ACCOUNTGL-QUANTITY =
IT_ACCOUNTGL-BASE_UOM =
IT_ACCOUNTGL-BASE_UOM_ISO =
IT_ACCOUNTGL-PLANT =
it_accountgl-profit_ctr =
IT_ACCOUNTGL-PART_PRCTR =
IT_ACCOUNTGL-WBS_ELEMENT =
IT_ACCOUNTGL-NETWORK =
IT_ACCOUNTGL-CMMT_ITEM =
IT_ACCOUNTGL-FUNDS_CTR =
IT_ACCOUNTGL-FUND =
IT_ACCOUNTGL-SALES_ORD =
IT_ACCOUNTGL-S_ORD_ITEM =
IT_ACCOUNTGL-P_EL_PRCTR =
IT_ACCOUNTGL-BILL_TYPE =
IT_ACCOUNTGL-DISTR_CHAN =
IT_ACCOUNTGL-SOLD_TO =
IT_ACCOUNTGL-DIVISION =
IT_ACCOUNTGL-SALESORG =
IT_ACCOUNTGL-SALES_OFF =
IT_ACCOUNTGL-SALES_GRP =
IT_ACCOUNTGL-INV_QTY =
IT_ACCOUNTGL-SALES_UNIT =
IT_ACCOUNTGL-SALES_UNIT_ISO =
IT_ACCOUNTGL-INV_QTY_SU =
IT_ACCOUNTGL-NET_WEIGHT =
IT_ACCOUNTGL-GROSS_WT =
IT_ACCOUNTGL-UNIT_OF_WT =
IT_ACCOUNTGL-UNIT_OF_WT_ISO =
IT_ACCOUNTGL-VOLUME =
IT_ACCOUNTGL-VOLUMEUNIT =
IT_ACCOUNTGL-VOLUMEUNIT_ISO =
it_accountgl-fm_area =
it_accountgl-log_proc =
it_accountgl-ac_doc_no =
it_accountgl-acct_type =
it_accountgl-doc_type =
it_accountgl-comp_code =
it_accountgl-func_area =
it_accountgl-plant =
it_accountgl-fis_period =
it_accountgl-fisc_year =
it_accountgl-pstng_date =
it_accountgl-value_date =
it_accountgl-customer =
it_accountgl-vendor_no =
it_accountgl-costobject =
it_accountgl-acttype =
it_accountgl-order_itno =
it_accountgl-routing_no =
it_accountgl-activity =
it_accountgl-cond_type =
it_accountgl-cond_count =
it_accountgl-cond_st_no =
it_accountgl-co_busproc =
it_accountgl-asset_no =
it_accountgl-sub_number =
it_accountgl-de_cre_ind =
it_accountgl-p_el_prctr =
it_accountgl-xmfrw =
it_accountgl-po_pr_qnt =
it_accountgl-po_pr_uom =
it_accountgl-po_pr_uom_iso =
it_accountgl-entry_qnt =
it_accountgl-entry_uom =
it_accountgl-entry_uom_iso =
it_accountgl-item_cat =
it_accountgl-matl_type =
it_accountgl-mvt_ind =
it_accountgl-reval_ind =
it_accountgl-orig_group =
it_accountgl-orig_mat =
it_accountgl-serial_no =
it_accountgl-part_acct =
it_accountgl-tr_part_ba =
it_accountgl-trade_id =
it_accountgl-val_area =
it_accountgl-val_type =
it_accountgl-asval_date =
it_accountgl-po_number =
it_accountgl-po_item =
APPEND it_accountgl.
ENDFORM. "fill_accountgl
----
FORM fill_header *
----
FORM fill_header.
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
own_logical_system = gd_documentheader-obj_sys.
OBJ_TYPE has to be replaced by customers object key (Y* or Z*)
gd_documentheader-obj_type = 'IDOC'.
gd_documentheader-obj_key = '999000002'.
gd_documentheader-obj_sys = 'R3ICLNT800'.
gd_documentheader-BUS_ACT = 'RFBU'.
gd_documentheader-username = sy-uname.
gd_documentheader-header_txt = 'BAPI Test'. "#EC NOTEXT
gd_documentheader-obj_key_r =
GD_DOCUMENTHEADER-reason_rev =
gd_documentheader-comp_code = '1000'.
GD_DOCUMENTHEADER-AC_DOC_NO =
gd_documentheader-fisc_year ='2001'.
gd_documentheader-doc_date = '20010127'.
gd_documentheader-pstng_date = '20010127'.
GD_DOCUMENTHEADER-TRANS_DATE =
GD_DOCUMENTHEADER-VALUE_DATE =
GD_DOCUMENTHEADER-FIS_PERIOD = '1'.
GD_DOCUMENTHEADER-DOC_TYPE =
GD_DOCUMENTHEADER-REF_DOC_NO = '999000001'.
GD_DOCUMENTHEADER-AC_DOC_NO = '999000001'.
GD_DOCUMENTHEADER-COMPO_ACC =
ENDFORM. "fill_header
----
FORM fill_contractheader *
----
FORM fill_contractheader.
gd_fica_hd-doc_no =
gd_fica_hd-doc_type_ca =
gd_fica_hd-res_key =
gd_fica_hd-fikey =
gd_fica_hd-payment_form_ref =
ENDFORM. "fill_contractheader
----
FORM fill_cpd *
----
FORM fill_cpd.
gd_customercpd-name
gd_customercpd-name_2
gd_customercpd-name_3
gd_customercpd-name_4
gd_customercpd-postl_code
gd_customercpd-city
gd_customercpd-country
gd_customercpd-country_iso
gd_customercpd-street
gd_customercpd-po_box
gd_customercpd-pobx_pcd
gd_customercpd-pobk_curac
gd_customercpd-bank_acct
gd_customercpd-bank_no
gd_customercpd-bank_ctry
gd_customercpd-bank_ctry_iso
gd_customercpd-tax_no_1
gd_customercpd-tax_no_2
gd_customercpd-tax
gd_customercpd-equal_tax
gd_customercpd-region
gd_customercpd-ctrl_key
gd_customercpd-instr_key
gd_customercpd-dme_ind
gd_customercpd-langu_iso
ENDFORM. "fill_cpd
----
FORM fill_ar *
----
FORM fill_accountar.
CLEAR it_accountreceivable.
it_accountreceivable-itemno_acc = '40'.
it_accountreceivable-customer = '1101'.
IT_ACCOUNTRECEIVABLE-REF_KEY_1 =
IT_ACCOUNTRECEIVABLE-REF_KEY_2 =
IT_ACCOUNTRECEIVABLE-REF_KEY_3 =
IT_ACCOUNTRECEIVABLE-PMNTTRMS =
IT_ACCOUNTRECEIVABLE-BLINE_DATE =
IT_ACCOUNTRECEIVABLE-DSCT_DAYS1 =
IT_ACCOUNTRECEIVABLE-DSCT_DAYS2 =
IT_ACCOUNTRECEIVABLE-NETTERMS =
IT_ACCOUNTRECEIVABLE-DSCT_PCT1 =
IT_ACCOUNTRECEIVABLE-DSCT_PCT2 =
IT_ACCOUNTRECEIVABLE-PYMT_METH =
IT_ACCOUNTRECEIVABLE-DUNN_KEY =
IT_ACCOUNTRECEIVABLE-DUNN_BLOCK =
IT_ACCOUNTRECEIVABLE-PMNT_BLOCK =
IT_ACCOUNTRECEIVABLE-VAT_REG_NO =
IT_ACCOUNTRECEIVABLE-ALLOC_NMBR =
it_accountreceivable-item_text =
IT_ACCOUNTRECEIVABLE-PARTNER_BK =
it_accountreceivable-gl_account = '40'.
it_accountreceivable-comp_code
it_accountreceivable-bus_area
it_accountreceivable-pmtmthsupl
it_accountreceivable-paymt_ref
it_accountreceivable-scbank_ind
it_accountreceivable-businessplace
it_accountreceivable-sectioncode
it_accountreceivable-branch
it_accountreceivable-pymt_cur
it_accountreceivable-pymt_cur_iso
it_accountreceivable-pymt_amt
it_accountreceivable-c_ctr_area
it_accountreceivable-bank_id
it_accountreceivable-supcountry
it_accountreceivable-supcountry_iso
it_accountreceivable-tax_code
it_accountreceivable-taxjurcode
it_accountreceivable-tax_date
it_accountreceivable-sp_gl_ind
it_accountreceivable-partner_guid = '1465464654'.
APPEND it_accountreceivable.
ENDFORM. "fill_accountar
----
FORM fill_ap *
----
FORM fill_accountap.
CLEAR it_accountpayable.
it_accountpayable-itemno_acc = 1.
it_accountpayable-vendor_no = '0000001000'.
it_accountpayable-gl_account
it_accountpayable-ref_key_1
it_accountpayable-ref_key_2
it_accountpayable-ref_key_3
it_accountpayable-comp_code
it_accountpayable-bus_area
it_accountpayable-pmnttrms
it_accountpayable-bline_date
it_accountpayable-dsct_days1
it_accountpayable-dsct_days2
it_accountpayable-netterms
it_accountpayable-dsct_pct1
it_accountpayable-dsct_pct2
it_accountpayable-pymt_meth
it_accountpayable-pmtmthsupl
it_accountpayable-pmnt_block
it_accountpayable-scbank_ind
it_accountpayable-supcountry
it_accountpayable-supcountry_iso
it_accountpayable-bllsrv_ind
it_accountpayable-alloc_nmbr
it_accountpayable-item_text = 'BAPI Test A/P line item'. "#EC
*NOTEXT
it_accountpayable-po_sub_no
it_accountpayable-po_checkdg
it_accountpayable-po_ref_no
it_accountpayable-w_tax_code
it_accountpayable-businessplace
it_accountpayable-sectioncode
it_accountpayable-instr1
it_accountpayable-instr2
it_accountpayable-instr3
it_accountpayable-instr4
it_accountpayable-branch
it_accountpayable-pymt_cur
it_accountpayable-pymt_amt
it_accountpayable-pymt_cur_iso
it_accountpayable-sp_gl_ind
APPEND it_accountpayable.
ENDFORM. "fill_accountap
----
FORM fill_tax *
----
FORM fill_accounttax.
CLEAR it_accounttax.
it_accounttax-itemno_acc = 3.
it_accounttax-gl_account = '0000154000'.
it_accounttax-tax_code = 'V1'.
it_accounttax-acct_key = 'VST'.
IT_ACCOUNTTAX-TAXJURCODE =
it_accounttax-cond_key =
IT_ACCOUNTTAX-TAX_RATE =
IT_ACCOUNTTAX-TAX_DATE =
IT_ACCOUNTTAX-STAT_CON =
IT_ACCOUNTTAX-taxjurcode_deep
IT_ACCOUNTTAX-taxjurcode_level
APPEND it_accounttax.
ENDFORM. "fill_accounttax
----
FORM fill_currencyamount *
----
FORM fill_currencyamount.
CLEAR it_currencyamount.
it_currencyamount-itemno_acc = 1.
it_currencyamount-curr_type = '00'.
it_currencyamount-currency = 'GBP'.
IT_CURRENCYAMOUNT-CURRENCY_ISO = 'GBP'.
it_currencyamount-amt_doccur = -1.
IT_CURRENCYAMOUNT-EXCH_RATE = .
it_currencyamount-amt_base = 1.
IT_CURRENCYAMOUNT-DISC_BASE =
it_currencyamount-exch_rate_v =
it_currencyamount-disc_amt =
APPEND it_currencyamount.
CLEAR it_currencyamount.
it_currencyamount-itemno_acc = 2.
it_currencyamount-curr_type = '00'.
it_currencyamount-currency = 'GBP'.
IT_CURRENCYAMOUNT-CURRENCY_ISO = 'GBP'.
it_currencyamount-amt_doccur = 1.
IT_CURRENCYAMOUNT-EXCH_RATE =
it_currencyamount-amt_base = 1.
IT_CURRENCYAMOUNT-DISC_BASE =
it_currencyamount-exch_rate_v =
it_currencyamount-disc_amt =
APPEND it_currencyamount.
ENDFORM. "fill_currencyamount
----
FORM fill_criteria *
----
FORM fill_criteria.
CLEAR it_criteria.
it_criteria-itemno_acc = 2.
it_criteria-fieldname = 'BZIRK'.
it_criteria-character = '000001'.
append it_criteria.
ENDFORM. "fill_criteria
----
FORM fill_valuefield *
----
FORM fill_valuefield.
CLEAR it_valuefield.
it_valuefield-itemno_acc = 2.
it_valuefield-fieldname = 'VV010'.
it_valuefield-curr_type
it_valuefield-currency = 'EUR'.
it_valuefield-currency_iso
it_valuefield-amt_valcom
it_valuefield-base_uom
it_valuefield-base_uom_iso
it_valuefield-qua_valcom
append it_valuefield.
ENDFORM. "fill_valuefield
----
FORM fill_extension *
----
FORM fill_extension.
CLEAR it_ext.
it_ext-field1
it_ext-field2
it_ext-field3
it_ext-field4
APPEND it_ext.
DATA: ls_zzz TYPE ZZZ_ACCIT.
CLEAR it_ext2.
it_ext2-structure = 'ZZZ_ACCIT'.
ls_zzz-posnr = 2.
ls_zzz-awref_reb = '123654'.
ls_zzz-aworg_reb = '654654'.
ls_zzz-grant_nbr = '0022002'.
MOVE ls_zzz TO it_ext2-valuepart1.
APPEND it_ext2.
ENDFORM. "fill_extension
----
FORM fill_paymentcard *
----
FORM fill_paymentcard.
CLEAR it_paymentcard.
it_paymentcard-itemno_acc = 1.
it_paymentcard-cc_glaccount
it_paymentcard-cc_type
it_paymentcard-cc_number
it_paymentcard-cc_seq_no
it_paymentcard-cc_valid_f
it_paymentcard-cc_valid_t
it_paymentcard-cc_name
it_paymentcard-dataorigin
it_paymentcard-authamount = '100'.
it_paymentcard-currency = 'EUR'.
it_paymentcard-currency_iso
it_paymentcard-cc_autth_no
it_paymentcard-auth_refno
it_paymentcard-auth_date
it_paymentcard-auth_time
it_paymentcard-merchidcl
it_paymentcard-point_of_receipt
it_paymentcard-terminal
it_paymentcard-cctyp = '1'.
APPEND it_paymentcard.
ENDFORM. "fill_paymentcard
----
FORM fill_contractitem *
----
FORM fill_contractitem.
CLEAR it_fica_it.
it_fica_it-itemno_acc
it_fica_it-cont_acct
it_fica_it-main_trans
it_fica_it-sub_trans
it_fica_it-func_area
it_fica_it-fm_area
it_fica_it-cmmt_item
it_fica_it-funds_ctr
it_fica_it-fund
append it_fica_it.
ENDFORM. "fill_contractitem
&----
*& Form fill_re
&----
FORM fill_re .
CLEAR it_re.
it_re-itemno_acc =
it_re-business_entity =
it_re-building =
it_re-property =
it_re-rental_object =
it_re-serv_charge_key =
it_re-settlement_unit =
it_re-contract_no =
APPEND it_re.
*
ENDFORM. "fill_re
‎2005 Jun 21 6:48 PM
Hi Sam,
Well what you get in the BKPF happens to be the document number. I don't get your exact requirements.
Debasish
‎2005 Jun 21 6:54 PM
Hi,
if you look at the table BKPF, there two different fields: one is the Document Number, the other is the Object Key. what I am after is the Document Number, after I have commited the Bapi. The I can use FB03 to look at the actual invoice - which requires the document number, and not the key.
Thanks
Regards Sims
‎2005 Jun 21 6:56 PM
Hi,
you could return the attached prog, if you have an ides system, and you will notice that the object key and the Document number are different.
Regards Sims
‎2005 Jun 21 7:53 PM
Hi,
The object key is not unique either. Any Ideas anyone?
Regards Sims
‎2005 Jun 22 5:18 AM
Did you check Rich's suggestion to get the document number using msgid msgno and msg variables.
In case of BDCs we only use this option , so I guess if BAPI is not passing back the created document then there is no harm in trying this option.
I am sure there will be one consistent message in return for successful cases.
Check Rich's posting :
<<
READ TABLE RETURN
WITH KEY ID = MESSID
NUMBER = MESSNUMBER.
if sy-subrc = 0.
document_number = return-MESSAGE_V1.
endif.
>>
‎2005 Jun 22 11:59 PM
Hi,
Not really sure what you mean.
This is my call to the BAPI:
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = gd_documentheader2
customercpd = gd_customercpd
contractheader = gd_fica_hd
IMPORTING
obj_type = l_type
obj_key = l_key
obj_sys = l_sys
TABLES
accountgl = it_accountgl2
accountreceivable = it_accountreceivable
accountpayable = it_accountpayable
accounttax = it_accounttax
currencyamount = it_currencyamount2
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.
When I look at the contents of it_return, it does not have the Document number in any of the fields
After commiting the BAPI with
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
return = myret
myret still does not have the Document Number.
I'm I missing something basic here?
Thanks
‎2005 Jun 23 5:15 AM
Are you not getting any message in the return table in the BAPI call?
It should have some message like Accounting document &1 posted and msgv1 as <accounting doc number>.
did you check all the fields if it_return?
what is the success message ?
Cheers,
Ram
‎2005 Jun 23 11:01 AM
Hi,
the message I get back in the return Parameter is as below:
TYPE C 1 S
ID C 20 RW
NUMBER N 3 605
MESSAGE C 220 Document posted successfully: IDOC 999000002 R3ICLNT800
LOG_NO C 20
LOG_MSG_NO N 6 000000
MESSAGE_V1 C 50 IDOC
MESSAGE_V2 C 50 999000002
MESSAGE_V3 C 50 R3ICLNT800
MESSAGE_V4 C 50
PARAMETER C 32
ROW I 4 0
FIELD C 30
SYSTEM C 10 R3ICLNT800
the message which says Document posted successfully: IDOC 999000002 R3ICLNT800
is not the document number for the invoice though.
Any ideas?
Thanks
‎2005 Jun 23 5:22 PM
‎2005 Jun 23 9:23 PM
Hi,
Some time ago I use this FM and solve this problem in such a way that before FM call I assigned my own number in DOCUMENTHEADER-OBJ_KEY and after BAPI commit I used SELECT to find accountig document in BKPF using field AWKEY which contained number from DOCUMENTHEADER-OBJ_KEY.
Krzys
‎2005 Jun 23 9:43 PM
Hi ,
I totally agree with you. My scenario is if i pass '$' as an OBJ_KEY it generates the number and returns it in the export parameter in OBJ_KEY which is the actual accounting document number. Now i want to know is this the right way to do... it's urgent please suggest ASAP.
Regrards ,
Vivek.
‎2005 Jun 23 11:10 PM
Hi Viveksagar,
I tried your '$' method, but it still did not return the Document number, I get another number which is not unique
what are you using for the parameter
gd_documentheader-obj_type
If you are getting the document number in BKPF , I would be interested in looking at the code.
Otherwise , I think the idea of generating a unique number each time and looking up the document number in BKPF is the only option. I find it strange though, that this would have to be done.
thanks.
‎2005 Jun 24 5:27 AM
From where this IDOC number is coming in the message ...
Did you check in WE02, if there is any IDOC generated with the number 999000002 ?
That will bring some more fun !!
Also, I think in BKPF there should be having a field called IDOC number ..check if it's there and then see the doc against the IDOC 999000002 .
Cheers,
Ram
Message was edited by: Ram Manohar Tiwari
‎2005 Jun 24 8:40 AM
Hi,
I think you shouldn't use 'BKPF' in field OBJ_TYPE. I defined my own id for that purpose.
Krzys
‎2005 Jun 24 12:34 PM
Hi,
but does $ really give you the document number? I could not get it to do that.
‎2005 Jun 24 1:01 PM
Hi,
Have you try to read parameter BLN ? May be this BAPI set it after execution...
Krzys
‎2005 Jun 24 7:09 PM
Hi ,
Enter the following for running the BAPI BAPI_ACC_DOCUMENT_POST
In Document header
OBJ_type = BKPFF
OBJ_KEY = $ .
and rest other field as it is the way you are already filling.
and fill your data for Account recievable and Currency amount
Once you run this BAPI in SE 37 the first 10 characters OBJ_KEY will give you the generated document number .... need any further help let me know...
Regards ,
Vivek.
‎2005 Jun 24 9:29 PM
Hi,
There is a much cleaner and I think easier way to get the document number. Use function module FI_ACCBELNR_GET immediately after calling 'BAPI_ACC_DOCUMENT_POST'. See below for an example.
Best Regards,
James Gaddis
Post an FI document
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = p_header
IMPORTING
obj_type = l_obj_type
obj_key = l_obj_key
obj_sys = l_obj_sys
TABLES
accountgl = i_glacct
currencyamount = i_amount
return = return2.
Move the object key to the FI doc parameter
CALL FUNCTION 'FI_ACCBELNR_GET'
TABLES
t_belnr = it_belnr.
READ TABLE it_belnr INDEX 1.
p_fidoc = it_belnr-belnr_e.
You can optionally add a BAPI message with the FI document number if you want to include the document number in your own message:
IF NOT p_fidoc IS INITIAL.
PERFORM fill_bapireturn_message
TABLES return2
USING 'S' 'Zxxx' 'nnn'
p_fidoc
space space space.
ENDIF.
‎2005 Jun 24 10:25 PM
James Gaddis you are a Star - This Fixed the problem,
and is the best way of doing this !!!
Many Thanks
‎2005 Jun 25 12:16 AM
Hi Sims,
Can i know what is the value you are passing for the
field DOCUMENTHEADER-OBJ_KEY before calling the
function module BAPI_ACC_DOCUMENT_POST. It will be
grateful if you send the piece of code how you are
using this function module.
Regards,
Bhanu
‎2009 Dec 02 9:50 PM
A little better solution (May be little late)
When filling the BAPI interface, leave the following fields empty if the FI document number is to be the reference document number for the posting:
o DOCUMENTHEADER: OBJ_TYPE, OBJ_KEY and OBJ_SYS
o DOCUMENTHEADER and ACCOUNTGL: AC_DOC_NO
o ACCOUNT_GL: STAT_CON, AC_DOC_NO
In the importing paramters
IMPORTING
obj_type = l_type
obj_key = l_key
obj_sys = l_sys
The first 10 character of l_key will contain the FI document number