BAPI ACC GL POSTING POST 建立會計文件
BAPI ACC GL POSTING POST 建立會計文件
BAPI ACC GL POSTING POST 建立會計文件
************************************************************************
* Types type Type-pools
************************************************************************
TYPES:
BEGIN OF ty_doc,
zzno1(4) TYPE n, "編號
bukrs TYPE bukrs, "存續公司
rbukrs TYPE bukrs, "消滅公司
blart TYPE blart, "文件類型
bldat TYPE bldat, "文件日期
budat TYPE budat, "過帳日期
monat TYPE monat, "期間
xblnr TYPE xblnr, "參考號碼
bktxt TYPE bktxt, "表頭內文
waers TYPE waers, "幣別TWD
newbs TYPE bschl, "借過帳碼
newko TYPE saknr, "借方科目
txt20 TYPE txt20_skat, "科目短文
newbs2 TYPE bschl, "貸過帳碼
newko2 TYPE saknr, "貸方科目
dmbtr TYPE dmbtr, "本國貨幣
zamou(15) TYPE n, "金額
bupla TYPE bupla, "營業處
zuonr TYPE dzuonr, "借方指派
sgtxt TYPE sgtxt, "借方內文
zuonr2 TYPE dzuonr, "貸方指派
sgtxt2 TYPE sgtxt, "貨方內文
message TYPE bapi_msg, "訊息
END OF ty_doc.
************************************************************************
* Data global fields & structure
************************************************************************
DATA:
lt_input TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE,
gt_datadoc TYPE ztmd02tmpglacc OCCURS 0 WITH HEADER LINE.
*-----------------------------------------------------------------------
DATA:
docheader LIKE bapiache08 OCCURS 0 WITH HEADER LINE,
docitem LIKE bapiacgl08 OCCURS 0 WITH HEADER LINE,
doccurramount LIKE bapiaccr08 OCCURS 0 WITH HEADER LINE,
obj_key LIKE bapiache08-obj_key,
return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
w_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
*======================================================================*
*※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※*
* FORM create_gl *
*----------------------------------------------------------------------*
FORM create_gl.
LOOP AT lt_input.
AT NEW row.
CLEAR gt_datadoc.
ENDAT.
CASE lt_input-col.
WHEN 1.
l_docno = l_docno + 1.
gt_datadoc-zzno1 = l_docno.
gt_datadoc-bukrs = lt_input-value.
WHEN 2.
gt_datadoc-rbukrs = lt_input-value.
WHEN 3.
gt_datadoc-blart = lt_input-value.
WHEN 4.
gt_datadoc-bldat = lt_input-value.
WHEN 5.
gt_datadoc-budat = lt_input-value.
WHEN 6.
l_docmonat = lt_input-value.
gt_datadoc-monat = l_docmonat.
WHEN 7.
gt_datadoc-xblnr = lt_input-value.
WHEN 8.
gt_datadoc-bktxt = lt_input-value.
WHEN 9.
gt_datadoc-waers = lt_input-value.
WHEN 10.
gt_datadoc-newbs = lt_input-value.
WHEN 11.
l_docnewko = lt_input-value.
gt_datadoc-newko = l_docnewko.
WHEN 12.
gt_datadoc-txt20 = lt_input-value.
WHEN 13.
gt_datadoc-newbs2 = lt_input-value.
WHEN 14.
l_docnewko2 = lt_input-value.
gt_datadoc-newko2 = l_docnewko2.
WHEN 15.
gt_datadoc-zamou = lt_input-value.
gt_datadoc-dmbtr = gt_datadoc-zamou / 100.
WHEN 16.
gt_datadoc-bupla = lt_input-value.
WHEN 17.
gt_datadoc-zuonr = lt_input-value.
WHEN 18.
gt_datadoc-sgtxt = lt_input-value.
WHEN 19.
gt_datadoc-zuonr2 = lt_input-value.
WHEN 20.
gt_datadoc-sgtxt2 = lt_input-value.
ENDCASE.
AT END OF row.
APPEND gt_datadoc.
ENDAT.
ENDLOOP.
IF gt_datadoc[] IS INITIAL.
MESSAGE s398(00) WITH ' 找不到資料' DISPLAY LIKE 'E'.
EXIT.
ELSE.
LOOP AT gt_datadoc.
CLEAR: docheader, docitem, doccurramount, docitem[], doccurramount[], return.
docheader-comp_code = gt_datadoc-bukrs. "公司代碼
docheader-fisc_year = gt_datadoc-budat+0(4). "年度
docheader-fis_period = gt_datadoc-monat. "期間
docheader-doc_date = gt_datadoc-bldat. "文件日期
docheader-pstng_date = gt_datadoc-budat. "過帳日期
docheader-doc_type = gt_datadoc-blart. "文件類型
docheader-username = sy-uname. "建立者
docheader-header_txt = gt_datadoc-bktxt. "表頭內文
docheader-ref_doc_no = gt_datadoc-xblnr. "參考號碼
docheader-trans_date = gt_datadoc-budat. "生效日期
APPEND docheader.
*----------------------------------------------------------------------*
docitem-itemno_acc = gt_datadoc-newbs. "借過帳碼
docitem-gl_account = gt_datadoc-newko. "借方科目
docitem-comp_code = gt_datadoc-bukrs. "公司代碼
docitem-pstng_date = gt_datadoc-budat. "過帳日期
docitem-doc_type = gt_datadoc-blart. "文件類型
docitem-fisc_year = gt_datadoc-budat+0(4). "年度
docitem-fis_period = gt_datadoc-monat. "期間
docitem-alloc_nmbr = space. "指派
docitem-item_text = gt_datadoc-sgtxt. "借方內文
docitem-costcenter = space. "成本中心
docitem-bus_area = space. "業務範圍
docitem-customer = space. "客戶編號
docitem-vendor_no = space. "供應商號碼
APPEND docitem.
*----------------------------------------------------------------------*
docitem-itemno_acc = gt_datadoc-newbs2. "貸過帳碼
docitem-gl_account = gt_datadoc-newko2. "貸方科目
docitem-comp_code = gt_datadoc-bukrs. "公司代碼
docitem-pstng_date = gt_datadoc-budat. "過帳日期
docitem-doc_type = gt_datadoc-blart. "文件類型
docitem-fisc_year = gt_datadoc-budat+0(4). "年度
docitem-fis_period = gt_datadoc-monat. "期間
docitem-alloc_nmbr = gt_datadoc-zuonr2. "指派
docitem-item_text = gt_datadoc-sgtxt2. "貸方內文
docitem-costcenter = space. "成本中心
docitem-bus_area = space. "業務範圍
docitem-customer = space. "客戶編號
docitem-vendor_no = space. "供應商號碼
APPEND docitem.
*----------------------------------------------------------------------*
doccurramount-itemno_acc = gt_datadoc-newbs. "借過帳碼
doccurramount-currency_iso = gt_datadoc-waers. "幣別
IF doccurramount-itemno_acc = '40'.
doccurramount-amt_doccur = gt_datadoc-dmbtr. "金額
ELSE.
doccurramount-amt_doccur = gt_datadoc-dmbtr * -1. "金額
ENDIF.
APPEND doccurramount.
*----------------------------------------------------------------------*
doccurramount-itemno_acc = gt_datadoc-newbs2. "貸過帳碼
doccurramount-currency_iso = gt_datadoc-waers. "幣別
IF doccurramount-itemno_acc = '40'.
doccurramount-amt_doccur = gt_datadoc-dmbtr. "金額
ELSE.
doccurramount-amt_doccur = gt_datadoc-dmbtr * -1. "金額
ENDIF.
APPEND doccurramount.
*----------------------------------------------------------------------*
CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
EXPORTING
documentheader = docheader
IMPORTING
obj_key = obj_key
TABLES
accountgl = docitem
currencyamount = doccurramount
return = return.
*----------------------------------------------------------------------*
IF NOT obj_key IS INITIAL.
CLEAR w_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = w_return.
IF w_return IS INITIAL.
READ TABLE return WITH KEY id = 'F5' number = '312'.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
gt_datadoc-messg = return-message.
ELSE.
gt_datadoc-messg = return-message.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
gt_datadoc-messg = return-message.
ENDIF.
ENDIF.
*----------------------------------------------------------------------*
MODIFY gt_datadoc.
ENDLOOP.
LOOP AT gt_datadoc.
IF gt_datadoc-messg+0(4) = '文件成功'.
l_gjahr = gt_datadoc-messg+28(4).
l_number = gt_datadoc-messg+14(10).
WRITE sy-datum TO l_msgdate.
WRITE sy-uzeit TO l_msgtime.
CONCATENATE '成功' l_gjahr l_number l_msgdate l_msgtime INTO gt_datadoc-messg
SEPARATED BY ' '.
ENDIF.
MODIFY gt_datadoc. CLEAR gt_datadoc.
ENDLOOP.
ENDIF.
*----------------------------------------------------------------------*
TYPE-POOLS: slis.
DATA: l_alv_filed TYPE slis_fieldcat_alv.
DATA: l_alv_filedcat TYPE slis_t_fieldcat_alv.
CLEAR l_alv_filed.
l_alv_filed-col_pos = 1.
l_alv_filed-fieldname = 'ZZNO1'.
l_alv_filed-outputlen = 4.
l_alv_filed-no_zero = 'X'.
l_alv_filed-seltext_m = '編號'.
l_alv_filed-col_pos = 2.
l_alv_filed-fieldname = 'BUKRS'.
l_alv_filed-outputlen = 7.
l_alv_filed-seltext_m = '存續公司'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 3.
l_alv_filed-fieldname = 'RBUKRS'.
l_alv_filed-outputlen = 7.
l_alv_filed-seltext_m = '消滅公司'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 4.
l_alv_filed-fieldname = 'BLART'.
l_alv_filed-outputlen = 7.
l_alv_filed-seltext_m = '文件類型'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 5.
l_alv_filed-fieldname = 'BLDAT'.
l_alv_filed-outputlen = 10.
l_alv_filed-seltext_m = '文件日期'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 6.
l_alv_filed-fieldname = 'BUDAT'.
l_alv_filed-outputlen = 10.
l_alv_filed-seltext_m = '過帳日期'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 7.
l_alv_filed-fieldname = 'MONAT'.
l_alv_filed-outputlen = 4.
l_alv_filed-seltext_m = '期間'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 8.
l_alv_filed-fieldname = 'XBLNR'.
l_alv_filed-outputlen = 7.
l_alv_filed-seltext_m = '參考號碼'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 9.
l_alv_filed-fieldname = 'BKTXT'.
l_alv_filed-outputlen = 20.
l_alv_filed-seltext_m = '表頭內文'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 10.
l_alv_filed-fieldname = 'WAERS'.
l_alv_filed-outputlen = 4.
l_alv_filed-seltext_m = '幣別'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 11.
l_alv_filed-fieldname = 'NEWBS'.
l_alv_filed-outputlen = 7.
l_alv_filed-seltext_m = '借過帳碼'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 12.
l_alv_filed-fieldname = 'NEWKO'.
l_alv_filed-outputlen = 8.
l_alv_filed-seltext_m = '借方科目'.
l_alv_filed-no_zero = 'X'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 13.
l_alv_filed-fieldname = 'TXT20'.
l_alv_filed-outputlen = 20.
l_alv_filed-seltext_m = '科目短文'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 14.
l_alv_filed-fieldname = 'NEWBS2'.
l_alv_filed-outputlen = 7.
l_alv_filed-seltext_m = '貸過帳碼'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 15.
l_alv_filed-fieldname = 'NEWKO2'.
l_alv_filed-outputlen = 8.
l_alv_filed-seltext_m = '貸方科目'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 16.
l_alv_filed-fieldname = 'DMBTR'.
l_alv_filed-outputlen = 10.
l_alv_filed-seltext_m = '帳列金額'.
l_alv_filed-currency = 'TWD'.
l_alv_filed-no_zero = space.
l_alv_filed-do_sum = 'X'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 17.
l_alv_filed-fieldname = 'BUPLA'.
l_alv_filed-outputlen = 5.
l_alv_filed-seltext_m = '營業處'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 18.
l_alv_filed-fieldname = 'ZUONR'.
l_alv_filed-outputlen = 7.
l_alv_filed-seltext_m = '借方指派'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 19.
l_alv_filed-fieldname = 'SGTXT'.
l_alv_filed-outputlen = 20.
l_alv_filed-seltext_m = '借方內文'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 20.
l_alv_filed-fieldname = 'ZUONR2'.
l_alv_filed-outputlen = 7.
l_alv_filed-seltext_m = '貸方指派'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 21.
l_alv_filed-fieldname = 'SGTXT2'.
l_alv_filed-outputlen = 20.
l_alv_filed-seltext_m = '貨方內文'.
APPEND l_alv_filed TO l_alv_filedcat.
l_alv_filed-col_pos = 22.
l_alv_filed-fieldname = 'MESSG'.
l_alv_filed-outputlen = 40.
l_alv_filed-seltext_m = '處理訊息'.
APPEND l_alv_filed TO l_alv_filedcat.
ENDFORM.
*======================================================================*