‎2009 Jun 19 3:33 PM
hwo can i generate automaticly docheader-obj_key = 'test1'. using BAPI without fill it in the code program ? ( i use this BAPI in BDC for FB60 transaction)
*************************************************************************************
docheader-obj_type = 'BKPFF'.
docheader-obj_key = 'test1'.
docheader-username = sy-uname.
docheader-comp_code = '0050'. " Company Code
docheader-fisc_year = '2006'. " Fiscal Year
CALL FUNCTION 'BAPI_ACC_INVOICE_RECEIPT_POST'
EXPORTING
DOCUMENTHEADER = GD_DOCUMENTHEADER
CUSTOMERCPD = GD_CUSTOMERCPD
IMPORTING
OBJ_TYPE = obj_type
OBJ_KEY = obj_key
OBJ_SYS = obj_sys
TABLES
ACCOUNTPAYABLE = IT_ACCOUNTPAYABLE
ACCOUNTGL = IT_ACCOUNTGL
ACCOUNTTAX = IT_ACCOUNTTAX
CURRENCYAMOUNT = IT_CURRENCYAMOUNT
PURCHASEORDER = IT_PURCHASEORDER
PURCHASEAMOUNT = IT_PURCHASEAMOUNT
RETURN = IT_RETURN
CRITERIA = IT_CRITERIA
VALUEFIELD = IT_VALUEFIELD
‎2009 Jun 22 10:20 AM
object _key is nothing but document number+ year + Company Code which is created by the BAPI ? so y u want to assign TEST1 to it ?
regards
Prabhu
‎2009 Jun 22 10:26 AM
Hi,
When a business transaction is updated in Accounting, it may be that several documents are updated at the same time (FI document, CO document, etc). If the business transaction is not initiated in Accounting, a source document must exist outside Accounting. The information from this document must be transferred when the FI/CO interface is called up. The source information is updated in all accounting documents, and is made up of the following fields:
AWTYP (OBJ_TYPE) Reference transaction
Sender ID
AWKEY (OBJ_KEY) Reference key
Source document number
The reference key is made up of:
AWREF Reference document number (10 digits)
Source document number
AWORG Reference organizational unit (10 digits)
Number range ID (if required)
So if you are calling this BAPi to post invoice reciept with some reference you have to pass the above.
Regards,
Himanshu Verma
‎2009 Jun 22 11:09 AM
Hi,
{
lwa_exceptions-zinv_id = i_documentheader-zinv_id.
lwa_exceptions-zlineid = lv_lineid.
lwa_exceptions-zstep_id = i_stepid.
lwa_exceptions-zuser = sy-uname.
lwa_exceptions-zdate = sy-datum.
lwa_exceptions-ztime = sy-uzeit.
lwa_exceptions-zexception = t_return-zmessage.
MODIFY zbw_wi_exception FROM lwa_exceptions.
EXIT.
ENDIF.
IF lwa_posting-zcurrentdate = 'X'.
Todays date as posting date
lwa_documentheader-pstng_date = sy-datum.
ELSE.
lv_today = sy-datum.
CLEAR: lv_days,
lv_months,
lv_years,
lv_calcdt.
Calculate last day of previous month as posting date
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = lv_today
days = lv_days
months = lv_months
signum = '-'
years = lv_years
IMPORTING
calc_date = lv_calcdt.
IF sy-subrc <> 0.
CLEAR t_return.
t_return-ztype = 'E'.
CONCATENATE 'Error while calculating the'
'Last day of previous month'
INTO t_return-zmessage SEPARATED BY space.
APPEND t_return.
lv_lineid = lv_lineid + 1.
CLEAR lwa_exceptions.
lwa_exceptions-zinv_id = i_documentheader-zinv_id.
lwa_exceptions-zlineid = lv_lineid.
lwa_exceptions-zstep_id = i_stepid.
lwa_exceptions-zuser = sy-uname.
lwa_exceptions-zdate = sy-datum.
lwa_exceptions-ztime = sy-uzeit.
lwa_exceptions-zexception = t_return-zmessage.
MODIFY zbw_wi_exception FROM lwa_exceptions.
EXIT.
ENDIF.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = lv_calcdt
IMPORTING
last_day_of_month = lwa_documentheader-pstng_date
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.
ENDIF.
Populate the header data
lwa_documentheader-obj_type = 'IBKPF'.
CONCATENATE sy-datum sy-uzeit lwa_documentheader-comp_code
INTO lwa_documentheader-obj_key.
lwa_documentheader-obj_sys = sy-sysid.
lwa_documentheader-username = sy-uname.
lwa_documentheader-header_txt = 'HD BAPI Test'.
lwa_documentheader-comp_code = i_documentheader-comp_code.
lwa_documentheader-fisc_year = i_documentheader-zfisc_year.
lwa_documentheader-doc_date = i_documentheader-doc_date.
lwa_documentheader-trans_date = sy-datum.
lwa_documentheader-fis_period = i_documentheader-zfisc_period.
lwa_documentheader-doc_type = lv_doc_type.
----
ALL ITEM DATA *
----
............. *
----
Populate Account payble data
CLEAR lt_accountpayable.
lt_accountpayable-itemno_acc = 1.
lt_accountpayable-vendor_no = i_documentheader-zvendor.
lt_accountpayable-item_text = 'Webdesk invoice posting'.
APPEND lt_accountpayable.
clear lt_accountpayable.
Populate the currency for Account payble
CLEAR lt_currencyamount.
lt_currencyamount-itemno_acc = 1.
lt_currencyamount-currency = i_documentheader-currency.
lt_currencyamount-amt_doccur = i_documentheader-gross_amount * -1.
APPEND lt_currencyamount.
clear lt_currencyamount.
Loop the GL table
CLEAR lv_errfl.
LOOP AT t_glacc.
CONCATENATE i_documentheader-supcountry t_glacc-tax_code
INTO lv_vakey SEPARATED BY space.
SELECT knumh INTO lv_knumh
UP TO 1 ROWS
FROM konh
WHERE vakey = lv_vakey.
ENDSELECT.
IF sy-subrc = 0.
SELECT SINGLE kbetr INTO lv_kbetr
FROM konp
WHERE knumh = lv_knumh.
IF sy-subrc <> 0.
lv_errfl = 'X'.
ENDIF.
ELSE.
lv_errfl = 'X'.
ENDIF.
lv_kbetr = lv_kbetr / 10.
IF t_glacc-tax_base_amount IS INITIAL.
lv_taxamt = ( i_documentheader-gross_amount * lv_kbetr ) / 100.
ELSE.
lv_taxamt = ( t_glacc-tax_base_amount * lv_kbetr ) / 100.
ENDIF.
Populate the GL data
lt_accountgl-itemno_acc = 2.
lt_accountgl-gl_account = t_glacc-gl_account.
lt_accountgl-tax_code = t_glacc-tax_code.
lt_accountgl-acct_key = t_glacc-zacct_key.
lt_accountgl-item_text = 'Webdesk invoice posting'.
APPEND lt_accountgl.
clear lt_accountgl.
CLEAR lt_currencyamount.
lt_currencyamount-itemno_acc = 2.
lt_currencyamount-currency = i_documentheader-currency.
lt_currencyamount-amt_doccur = t_glacc-item_amount - lv_taxamt.
APPEND lt_currencyamount.
clear lt_currencyamount.
IF NOT t_glacc-tax_code IS INITIAL.
Populate the Tax data
lt_accounttax-itemno_acc = 3.
lt_accounttax-gl_account = t_glacc-ztaxgl_account.
lt_accounttax-tax_code = t_glacc-tax_code.
lt_accounttax-acct_key = t_glacc-zacct_key.
APPEND lt_accounttax.
clear lt_accounttax.
CLEAR lt_currencyamount.
lt_currencyamount-itemno_acc = 3.
lt_currencyamount-currency = i_documentheader-currency.
lt_currencyamount-amt_doccur = lv_taxamt.
IF t_glacc-tax_base_amount IS INITIAL.
lt_currencyamount-amt_base = i_documentheader-gross_amount.
ELSE.
lt_currencyamount-amt_base = t_glacc-tax_base_amount.
ENDIF.
APPEND lt_currencyamount.
clear lt_currencyamount.
ENDIF.
ENDLOOP.
IF lv_errfl = 'X'.
CLEAR t_return.
t_return-ztype = 'E'.
CONCATENATE 'Error while calculating the'
'Tax amount'
INTO t_return-zmessage SEPARATED BY space.
APPEND t_return.
lv_lineid = lv_lineid + 1.
CLEAR lwa_exceptions.
lwa_exceptions-zinv_id = i_documentheader-zinv_id.
lwa_exceptions-zlineid = lv_lineid.
lwa_exceptions-zstep_id = i_stepid.
lwa_exceptions-zuser = sy-uname.
lwa_exceptions-zdate = sy-datum.
lwa_exceptions-ztime = sy-uzeit.
lwa_exceptions-zexception = t_return-zmessage.
MODIFY zbw_wi_exception FROM lwa_exceptions.
EXIT.
ENDIF.
CLEAR lwa_wi_history.
lwa_wi_history-zinv_id = i_documentheader-zinv_id.
lwa_wi_history-zlineid = lv_hist_lineid.
lwa_wi_history-zstep_id = i_stepid.
lwa_wi_history-zuser = sy-uname.
lwa_wi_history-zdate = sy-datum.
lwa_wi_history-ztime = sy-uzeit.
CLEAR: lt_return[].
CALL FUNCTION 'BAPI_ACC_INVOICE_RECEIPT_POST'
EXPORTING
documentheader = lwa_documentheader
IMPORTING
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
TABLES
accountpayable = lt_accountpayable
accountgl = lt_accountgl
accounttax = lt_accounttax
currencyamount = lt_currencyamount
return = lt_return.
}
Thnaks & Regards,
Sateesh.
Edited by: sateesh kumar on Jun 22, 2009 12:11 PM
‎2009 Jun 23 10:34 AM
OBJ_KEY must be transfered in th BAPI it'is not generate by th BAPI.
i have this idea. i don't know if it's good idea ?
CALL FUNCTION 'RF_GET_DOCUMENT_NUMBER'
EXPORTING
COMPANY = 'SO01'
RANGE = '43'
YEAR = GD_DOCUMENTHEADER-FISC_YEAR
IMPORTING
DOCUMENT_NUMBER = wl_belnr
EXCEPTIONS
DUPLICATE_NUMBER = 1
RANGE_MISSING = 2
ERROR_IN_OPEN_FI = 3
OTHERS = 4
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CONCATENATE WL_BELNR GD_DOCUMENTHEADER-COMP_CODE GD_DOCUMENTHEADER-FISC_YEAR INTO WL_REF_KEY.
GD_DOCUMENTHEADER-OBJ_KEY = WL_REF_KEY.
‎2009 Jul 20 3:03 PM