‎2006 Feb 09 5:41 AM
Hi friends,
I want to upload data to transaction FB60. I have found a BAPI 'BAPI_ACC_DOCUMENT_POST' for the same but I am not sure about it.
Can anybody help me or if anybody has used the BAPI for uploading data to Txn FB60.
Thanks in Advance,
Punit
‎2006 Feb 09 5:49 AM
‎2006 Feb 09 5:58 AM
Hi Kishan,
Its 'BAPI_ACC_DOCUMENT_POST'. Is it possible with 'BAPI_ACC_GL_POSTING_POST'.
Thanks,
Punit
‎2006 Feb 09 6:06 AM
Hi,
check this code..
REPORT Z_FI_GL_POSTING.
include <icon>.
*/ =================================================================== *
CONSTANTS: on VALUE 'X',
off VALUE ' ',
tabx TYPE X VALUE '09',
c_e1bpache08 TYPE edilsegtyp VALUE 'E1BPACHE08',
c_e1bpacgl08 TYPE edilsegtyp VALUE 'E1BPACGL08',
c_e1bpaccr08 TYPE edilsegtyp VALUE 'E1BPACCR08'.
TYPES: BEGIN OF t_tab_index,
from TYPE i,
to TYPE i,
END OF t_tab_index.
data : tab type c.
DATA:
e1bpache08 LIKE e1bpache08,
e1bpacgl08 LIKE e1bpacgl08,
e1bpaccr08 LIKE e1bpaccr08.
DATA: g_subrc TYPE subrc.
DATA: g_file TYPE string.
DATA: g_segname TYPE edilsegtyp.
DATA: g_sdata TYPE edi_sdata.
DATA: g_first_doc.
DATA: i_dataf TYPE char2000 OCCURS 900 WITH HEADER LINE,
i_dataf_doc TYPE char2000 OCCURS 50 WITH HEADER LINE.
DATA: g_tab_index TYPE t_tab_index OCCURS 100 WITH HEADER LINE.
DATA: i_accountgl TYPE bapiacgl08 OCCURS 100 WITH HEADER LINE,
i_curramnt TYPE bapiaccr08 OCCURS 100 WITH HEADER LINE,
i_return TYPE bapiret2 OCCURS 10 WITH HEADER LINE,
g_docheader TYPE bapiache08.
*/ ======================== SELECTION ================================ *
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
PARAMETERS: excelf TYPE file_name LOWER CASE
DEFAULT 'C:my_excel_file.txt'.
SELECTION-SCREEN END OF BLOCK b1.
*/ =========================== CORE ================================== *
START-OF-SELECTION.
*/ Call text File with GUI_UPLOAD
g_file = excelf.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = g_file
* FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR = ' '
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = i_dataf
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17
.
IF sy-subrc <> 0.
write: / Text-032.
stop.
ENDIF.
*/ Initialisation
write tabx to tab. " required as of ABAP 610 split cannot
*/ have mixed char and byte types
CLEAR g_tab_index.
REFRESH g_tab_index.
*/ how to process several doc : detecting docs in i_dataf
g_first_doc = on.
LOOP AT i_dataf.
CLEAR: g_segname, g_sdata.
SPLIT i_dataf AT tab INTO g_segname g_sdata.
CHECK: g_segname = c_e1bpache08,
sy-tabix > 1.
*/ 1st document
IF g_first_doc = on.
g_tab_index-from = 1.
g_tab_index-to = sy-tabix - 1.
APPEND g_tab_index.
*/ Next Documents
ELSE.
g_tab_index-from = g_tab_index-to + 1.
g_tab_index-to = sy-tabix - 1.
APPEND g_tab_index.
ENDIF.
g_first_doc = off.
ENDLOOP.
*/ Last doc.
g_tab_index-from = g_tab_index-to + 1.
g_tab_index-to = sy-tfill.
APPEND g_tab_index.
*/ Process documents.
loop at g_tab_index.
clear i_dataf_doc.
refresh i_dataf_doc.
append lines of i_dataf from g_tab_index-from
to g_tab_index-to
to i_dataf_doc.
perform process_document.
endloop.
END-OF-SELECTION.
*/ =========================== ROUTINES ============================== *
*---------------------------------------------------------------------*
* FORM process_document *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM process_document.
*/ Clearing Memory
CLEAR: g_docheader, i_accountgl, i_curramnt, i_return, g_subrc.
REFRESH: i_accountgl, i_curramnt, i_return.
*/ Checking i_dataf_doc
*/ Mapping dataf => Bapi structures & internal tables
CLEAR g_subrc.
CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
LOOP AT i_dataf_doc.
CLEAR g_sdata.
SPLIT i_dataf_doc AT tab INTO g_segname g_sdata.
CASE g_segname.
*/ HEADER
WHEN c_e1bpache08.
PERFORM do_split_ache08.
MOVE-CORRESPONDING e1bpache08 TO g_docheader.
IF e1bpache08-doc_date IS INITIAL.
CLEAR g_docheader-doc_date.
ENDIF.
IF e1bpache08-pstng_date IS INITIAL.
CLEAR g_docheader-pstng_date.
ENDIF.
IF e1bpache08-trans_date IS INITIAL.
CLEAR g_docheader-trans_date.
ENDIF.
*/ Account GL
WHEN c_e1bpacgl08.
PERFORM do_split_acgl08.
MOVE-CORRESPONDING e1bpacgl08 TO i_accountgl.
IF e1bpacgl08-pstng_date IS INITIAL.
CLEAR i_accountgl-pstng_date.
ENDIF.
APPEND i_accountgl.
*/ Account Currency & Amounts
WHEN c_e1bpaccr08.
PERFORM do_split_accr08.
MOVE-CORRESPONDING e1bpaccr08 TO i_curramnt.
APPEND i_curramnt.
*/ kick the line if segment name not filled
WHEN space.
*/ Other names => Bad file structure !
WHEN OTHERS.
g_subrc = 2.
ENDCASE.
ENDLOOP. " i_dataf_doc
ENDCATCH.
IF sy-subrc = 1 OR
NOT g_subrc IS INITIAL.
perform message_output using on.
exit.
ENDIF.
*/ Calling the BAPI
CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
EXPORTING
documentheader = g_docheader
TABLES
accountgl = i_accountgl
currencyamount = i_curramnt
return = i_return
* EXTENSION1 =
.
LOOP AT i_return WHERE type CA 'AE'.
g_subrc = 1.
EXIT.
ENDLOOP.
IF NOT g_subrc IS INITIAL.
perform message_output using on.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.
perform message_output using off.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form do_split_ACHE08
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM do_split_ache08.
CLEAR e1bpache08.
SPLIT g_sdata AT tab INTO
e1bpache08-obj_type
e1bpache08-obj_key
e1bpache08-obj_sys
e1bpache08-username
e1bpache08-header_txt
e1bpache08-obj_key_r
e1bpache08-comp_code
e1bpache08-ac_doc_no
e1bpache08-fisc_year
e1bpache08-doc_date
e1bpache08-pstng_date
e1bpache08-trans_date
e1bpache08-fis_period
e1bpache08-doc_type
e1bpache08-ref_doc_no
e1bpache08-compo_acc
e1bpache08-reason_rev
.
ENDFORM. " do_split_ACHE08
*&---------------------------------------------------------------------*
*& Form do_split_ACGL08
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM do_split_acgl08.
CLEAR e1bpacgl08.
SPLIT g_sdata AT tab INTO
e1bpacgl08-itemno_acc
e1bpacgl08-gl_account
e1bpacgl08-comp_code
e1bpacgl08-pstng_date
e1bpacgl08-doc_type
e1bpacgl08-ac_doc_no
e1bpacgl08-fisc_year
e1bpacgl08-fis_period
e1bpacgl08-stat_con
e1bpacgl08-ref_key_1
e1bpacgl08-ref_key_2
e1bpacgl08-ref_key_3
e1bpacgl08-customer
e1bpacgl08-vendor_no
e1bpacgl08-alloc_nmbr
e1bpacgl08-item_text
e1bpacgl08-bus_area
e1bpacgl08-costcenter
e1bpacgl08-acttype
e1bpacgl08-orderid
e1bpacgl08-orig_group
e1bpacgl08-cost_obj
e1bpacgl08-profit_ctr
e1bpacgl08-part_prctr
e1bpacgl08-wbs_element
e1bpacgl08-network
e1bpacgl08-routing_no
e1bpacgl08-order_itno
.
ENDFORM. " do_split_ACGL08
*&---------------------------------------------------------------------*
*& Form do_split_ACCR08
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM do_split_accr08.
data: l_filler(100).
CLEAR e1bpaccr08.
SPLIT g_sdata AT tab INTO
e1bpaccr08-itemno_acc
e1bpaccr08-curr_type
e1bpaccr08-currency
e1bpaccr08-currency_iso
e1bpaccr08-amt_doccur
e1bpaccr08-exch_rate
e1bpaccr08-exch_rate_v
l_filler
.
ENDFORM. " do_split_ACCR08
*&---------------------------------------------------------------------*
*& Form message_output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM message_output using if_error.
data: l_message(200),
l_return type i.
format color 1.
skip.
write: / text-020, g_tab_index-from,
text-021, g_tab_index-to.
skip.
if if_error = on.
write: / icon_red_light as icon, text-030 color 6.
else.
write: / icon_green_light as icon, text-031 color 5.
endif.
describe table i_return lines l_return.
if l_return is initial.
write: / text-032.
endif.
loop at i_return.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = i_return-id
LANG = sy-langu
NO = i_return-number
V1 = i_return-MESSAGE_V1
V2 = i_return-MESSAGE_V2
V3 = i_return-MESSAGE_V3
V4 = i_return-MESSAGE_V4
IMPORTING
MSG = l_message
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
check sy-subrc = 0.
write: / l_message.
endloop.
ENDFORM. " message_outputregards
vijay
‎2009 Apr 02 10:50 AM
Hi Vijay,
It would be gr8 if you could provide the excel file format that is required for upload.
Awiating replies..
‎2006 Feb 09 6:03 AM
Hi,
You can also use the BAPI_ACC_INVOICE_RECEIPT_POST which is specifically for invoice posting.
try this out.
‎2020 Mar 19 11:33 PM
This BAPI worked well: BAPI_ACC_INVOICE_RECEIPT_POST
You can check sample program in SAP:
ACC_BAPI_TEST_INVOICE_RECEIPT
Here's my sample code:
*&---------------------------------------------------------------------*
*& Form F_CREATE_DOC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LS_DATA text
* <--P_LV_ERROR text
*----------------------------------------------------------------------*
FORM f_create_doc CHANGING p_ls_data LIKE LINE OF gt_data
p_lv_error TYPE c.
DATA: ls_documentheader TYPE bapiache03,
ls_customercpd TYPE bapiacpa00,
lt_accountpayable TYPE TABLE OF bapiacap03,
ls_accountpayable LIKE LINE OF lt_accountpayable,
lt_accountgl TYPE TABLE OF bapiacgl03,
ls_accountgl LIKE LINE OF lt_accountgl,
lt_accounttax TYPE TABLE OF bapiactx01,
ls_accounttax LIKE LINE OF lt_accounttax,
lt_currencyamount TYPE TABLE OF bapiaccr01,
ls_currencyamount LIKE LINE OF lt_currencyamount,
lt_return TYPE TABLE OF bapiret2,
ls_return LIKE LINE OF lt_return,
ls_message TYPE string.
DATA: lv_hdr_txt(25) TYPE c,
lv_dt(8) TYPE c,
lv_ref_doc(16) TYPE c,
lv_rec_count(10) TYPE c,
ev_error TYPE c.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_ls_data-vendor
IMPORTING
output = p_ls_data-vendor.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_ls_data-gl_acct
IMPORTING
output = p_ls_data-gl_acct.
CLEAR: ls_documentheader, ls_customercpd, ls_accountpayable, lv_hdr_txt.
REFRESH: lt_accountpayable, lt_accountgl, lt_accounttax, lt_currencyamount, lt_return.
CONCATENATE 'CNCLD ACCT' p_ls_data-acct_num INTO lv_hdr_txt SEPARATED BY space.
CONCATENATE 'CANCEL' space sy-datum+6(2) sy-datum+4(2) sy-datum(4) INTO lv_ref_doc.
ls_documentheader-username = sy-uname.
ls_documentheader-header_txt = lv_hdr_txt.
ls_documentheader-comp_code = p_bukrs.
ls_documentheader-fisc_year = sy-datum(4).
ls_documentheader-doc_date = sy-datum.
ls_documentheader-pstng_date = sy-datum.
ls_documentheader-fis_period = sy-datum+4(2).
ls_documentheader-doc_type = c_blart.
ls_documentheader-ref_doc_no = lv_ref_doc.
ls_customercpd-name = p_ls_data-name.
ls_customercpd-name_2 = p_ls_data-address2.
ls_customercpd-postl_code = p_ls_data-postalcode.
ls_customercpd-city = p_ls_data-city.
ls_customercpd-country = p_ls_data-country.
ls_customercpd-street = p_ls_data-address1.
ls_customercpd-region = p_ls_data-province.
ls_customercpd-langu_iso = 'EN'.
ls_accountpayable-itemno_acc = 1.
ls_accountpayable-vendor_no = p_ls_data-vendor.
*ls_ACCOUNTPAYABLE-GL_ACCOUNT = '0000211000'.
ls_accountpayable-pmnttrms = c_pmt_trms.
ls_accountpayable-bline_date = sy-datum.
ls_accountpayable-alloc_nmbr = p_ls_data-name.
ls_accountpayable-item_text = lv_hdr_txt.
APPEND ls_accountpayable TO lt_accountpayable.
*Currency line item 1
ls_currencyamount-itemno_acc = 1.
ls_currencyamount-currency = c_waers.
ls_currencyamount-amt_doccur = p_ls_data-amount * -1.
APPEND ls_currencyamount TO lt_currencyamount.
*GL line item 2
ls_accountgl-itemno_acc = 2.
ls_accountgl-gl_account = p_ls_data-gl_acct.
ls_accountgl-comp_code = p_bukrs.
ls_accountgl-pstng_date = sy-datum.
ls_accountgl-doc_type = c_blart.
ls_accountgl-fisc_year = sy-datum(4).
ls_accountgl-fis_period = sy-datum+4(2).
ls_accountgl-profit_ctr = p_ls_data-profit_center.
ls_accountgl-alloc_nmbr = sy-datum.
ls_accountgl-de_cre_ind = 'S'.
APPEND ls_accountgl TO lt_accountgl.
*Currency line item 2
ls_currencyamount-itemno_acc = 2.
ls_currencyamount-currency = c_waers.
ls_currencyamount-amt_doccur = p_ls_data-amount.
APPEND ls_currencyamount TO lt_currencyamount.
CALL FUNCTION 'BAPI_ACC_INVOICE_RECEIPT_POST'
EXPORTING
documentheader = ls_documentheader
customercpd = ls_customercpd
* IMPORTING
* OBJ_TYPE =
* OBJ_KEY =
* OBJ_SYS =
TABLES
accountpayable = lt_accountpayable
accountgl = lt_accountgl
accounttax = lt_accounttax
currencyamount = lt_currencyamount
* PURCHASEORDER =
* PURCHASEAMOUNT =
return = lt_return
* CRITERIA =
* VALUEFIELD =
* EXTENSION1 =
.
lv_rec_count = gv_tot_rec.
READ TABLE lt_return INTO ls_return
WITH KEY type = 'S' id = 'RW' number = '605'.
IF sy-subrc = 0.
COMMIT WORK AND WAIT.
CONCATENATE 'Line Index' lv_rec_count ':' INTO ls_message SEPARATED BY space.
APPEND ls_message TO gt_success_msg.
APPEND ls_message TO gt_complete_log.
CONCATENATE 'Document sucessfully created:' ls_return-message_v2(10)
INTO ls_message.
APPEND ls_message TO gt_success_msg.
APPEND ls_message TO gt_complete_log.
* add blank line
CLEAR ls_message.
APPEND ls_message TO gt_success_msg.
APPEND ls_message TO gt_complete_log.
ELSE.
ROLLBACK WORK.
ev_error = c_x.
CONCATENATE 'Line Index' lv_rec_count ':' INTO ls_message SEPARATED BY space.
APPEND ls_message TO gt_error_msg.
APPEND ls_message TO gt_complete_log.
* read error message
DELETE ADJACENT DUPLICATES FROM lt_return COMPARING message.
LOOP AT lt_return INTO ls_return.
CLEAR ls_message.
ls_message = ls_return-message.
CONDENSE ls_message.
CONCATENATE ls_message '.' INTO ls_message.
APPEND ls_message TO gt_error_msg.
APPEND ls_message TO gt_complete_log.
ENDLOOP.
p_lv_error = ev_error.
* add blank line
CLEAR ls_message.
APPEND ls_message TO gt_error_msg.
APPEND ls_message TO gt_complete_log.
ENDIF.
ENDFORM.