近期的ABAP FI开发总结
Posted 想发财的小夏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了近期的ABAP FI开发总结相关的知识,希望对你有一定的参考价值。
最近项目上,做了FICO的开发,这段时间有空,做一个总结
FI开发目录
一.常用函数 BAPI_ACC_DOCUMENT_POST
1.调用方法
调用函数的方法比较简单,如下图:
FUNCTION ytest_001.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IS_HEAD) TYPE ZFICO_ZY_002_S001
*" TABLES
*" IT_ITEMS STRUCTURE ZFICO_ZY_002_S002
*" ET_RETURN STRUCTURE ZFICO_ZY_002_S004
*"----------------------------------------------------------------------
DATA: ls_documentheader LIKE bapiache09,
ls_accountgl LIKE bapiacgl09,
lt_accountgl LIKE TABLE OF bapiacgl09,
ls_accountpayable LIKE bapiacap09,
lt_accountpayable LIKE TABLE OF bapiacap09,
ls_accountreceivable LIKE bapiacar09,
lt_accountreceivable LIKE TABLE OF bapiacar09,
ls_currencyamount LIKE bapiaccr09,
lt_currencyamount LIKE TABLE OF bapiaccr09,
ls_criteria LIKE bapiackec9,
lt_criteria LIKE TABLE OF bapiackec9,
ls_return LIKE bapiret2,
lt_return LIKE TABLE OF bapiret2,
ls_extension2 LIKE bapiparex,
lt_extension2 LIKE TABLE OF bapiparex,
lv_obj_type TYPE bapiache09-obj_type,
lv_obj_key TYPE bapiache09-obj_key,
lv_obj_sys TYPE bapiache09-obj_sys,
lv_mitkz TYPE mitkz,
lv_umskz TYPE umskz.
" enhance
DATA:ls_head_exten TYPE zbapi_acc_head_exten,
ls_item_exten TYPE zbapi_acc_item_exten.
DATA:lt_hkont TYPE RANGE OF bseg-hkont.
DATA:lr_hkont TYPE rseloption,
lr_zzffs TYPE rseloption.
DATA: lt_bsed TYPE TABLE OF bsed,
ls_bsed TYPE bsed.
CLEAR: lt_bsed.
lt_hkont = VALUE #( sign = 'I' option = 'CP' ( low = '1001*' )
( low = '1002*' )
( low = '1012*' ) ).
lr_zzffs = VALUE #( sign = 'I' option = 'EQ' ( low = 'Z3' )
( low = 'O2' ) ).
ls_documentheader-username = sy-uname.
ls_documentheader-header_txt = is_head-bktxt.
ls_documentheader-comp_code = is_head-bukrs .
ls_documentheader-doc_date = is_head-bldat.
ls_documentheader-pstng_date = is_head-budat.
ls_documentheader-doc_type = is_head-blart.
ls_documentheader-ref_doc_no = is_head-xblnr.
CLEAR:ls_head_exten,ls_extension2,lt_extension2.
ls_head_exten-xref1_hd = is_head-xref1_hd.
ls_head_exten-xref2_hd = is_head-xref2_hd.
ls_head_exten-numpg = is_head-numpg.
ls_extension2-structure = 'ZBAPI_ACC_HEAD_EXTEN'.
ls_extension2-valuepart1 = ls_head_exten.
APPEND ls_extension2 TO lt_extension2.
LOOP AT it_items INTO DATA(ls_item).
CLEAR:lv_mitkz,lv_umskz.
* 特殊总账标识
lv_umskz = '*'. ”写入
* 科目类型
SELECT SINGLE mitkz INTO lv_mitkz FROM skb1 WHERE bukrs = is_head-bukrs AND saknr = ls_item-hkont.
IF sy-subrc = 0.
CASE lv_mitkz.
WHEN ''. "总账
CLEAR ls_accountgl.
ls_accountgl-itemno_acc = ls_item-buzei.
ls_accountgl-gl_account = ls_item-hkont.
ls_accountgl-costcenter = ls_item-kostl.
ls_accountgl-orderid = | ls_item-aufnr ALPHA = IN |.
ls_accountgl-profit_ctr = | ls_item-prctr ALPHA = IN |.
ls_accountgl-ref_key_3 = ls_item-xref3 .
ls_accountgl-asset_no = | ls_item-anln1 ALPHA = IN | .
ls_accountgl-sub_number = | ls_item-anln2 ALPHA = IN |.
IF ls_item-ebeln NE '0000000000' AND ls_item-ebeln NE ''.
ls_accountgl-po_number = ls_item-ebeln.
ls_accountgl-po_item = '00010'.
ENDIF.
ls_accountgl-material_long = ls_item-matnr.
ls_accountgl-item_text = ls_item-sgtxt .
IF ls_item-hkont IN lt_hkont.
ls_accountgl-housebankid = ls_item-hbkid.
ls_accountgl-housebankacctid = ls_item-hktid.
ENDIF.
" 票据传利润中心,不根据成本中心找,预付传成本中心,根据成本中心找利润中心然后写入凭证行项目的利润中心字段
" 非8*的科目行成本中心字段不写入,8*的科目也不用走这段逻辑
IF ls_item-hkont+0(1) NE '8' AND is_head-zzffs IN lr_zzffs AND is_head-blart = 'Y' .
ls_accountgl-costcenter = ''. " 去除成本中心
IF ls_item-kostl IS NOT INITIAL.
SELECT SINGLE prctr
FROM csks
INTO @DATA(lv_prctr)" 利润中心
WHERE kokrs = '1000'
AND kostl = @ls_item-kostl
AND datbi >= @sy-datum
AND datab <= @sy-datum.
IF sy-subrc EQ 0.
ls_accountgl-profit_ctr = lv_prctr. "ls_item-AUFNR .
ENDIF.
ENDIF.
ENDIF.
* 获利能力
CASE ls_item-hkont+0(4).
WHEN '6401'." 针对6401*的科目 物料+客户+利润中心写入COPA 忽略成本中心 2022.01.20
ls_accountgl-costcenter = ''. " 去除成本中心
IF ls_item-kostl IS NOT INITIAL.
SELECT SINGLE prctr
FROM csks
INTO @lv_prctr" 利润中心
WHERE kokrs = '1000'
AND kostl = @ls_item-kostl
AND datbi >= @sy-datum
AND datab <= @sy-datum.
IF sy-subrc EQ 0.
ls_accountgl-profit_ctr = lv_prctr.
PERFORM set_criteria_data TABLES lt_criteria USING ls_item-buzei 'PRCTR' lv_prctr.
ENDIF.
ENDIF.
IF ls_item-kunnr1 IS NOT INITIAL. " 客户
PERFORM set_criteria_data TABLES lt_criteria USING ls_item-buzei 'KNDNR' ls_item-kunnr1.
ENDIF.
IF ls_item-matnr IS NOT INITIAL. " 物料
PERFORM set_criteria_data TABLES lt_criteria USING ls_item-buzei 'ARTNR' ls_item-matnr.
ENDIF.
WHEN OTHERS.
IF ls_item-hkont+0(4) = '6051'.
ls_accountgl-customer = ls_item-kunnr.
PERFORM set_criteria_data TABLES lt_criteria USING ls_item-buzei 'KNDNR' ls_item-kunnr.
ELSEIF ls_item-kunnr1 IS NOT INITIAL.
PERFORM set_criteria_data TABLES lt_criteria USING ls_item-buzei 'KNDNR' ls_item-kunnr1.
ENDIF.
IF ls_item-xsdq IS NOT INITIAL.
PERFORM set_criteria_data TABLES lt_criteria USING ls_item-buzei 'BZIRK' ls_item-xsdq.
ENDIF.
IF ls_item-vbeln IS NOT INITIAL.
PERFORM set_criteria_data TABLES lt_criteria USING ls_item-buzei 'KAUFN' ls_item-vbeln.
ENDIF.
IF ls_item-vkbur IS NOT INITIAL.
PERFORM set_criteria_data TABLES lt_criteria USING ls_item-buzei 'VKBUR' ls_item-vkbur.
ENDIF.
IF ls_item-matnr1 IS NOT INITIAL.
PERFORM set_criteria_data TABLES lt_criteria USING ls_item-buzei 'MATNR' ls_item-matnr1.
ENDIF.
ENDCASE.
APPEND ls_accountgl TO lt_accountgl.
WHEN 'K'. "供应商
CLEAR:ls_accountpayable.
ls_accountpayable-itemno_acc = ls_item-buzei.
ls_accountpayable-gl_account = ls_item-hkont.
ls_accountpayable-vendor_no = ls_item-lifnr.
* ls_accountpayable-orderid = | ls_item-aufnr ALPHA = IN |. "ls_item-AUFNR .
ls_accountpayable-profit_ctr = | ls_item-prctr ALPHA = IN |. "ls_item-AUFNR .
ls_accountpayable-ref_key_3 = ls_item-xref3 .
* ls_accountpayable-asset_no = | ls_item-anln1 ALPHA = IN | . "ls_item-AUFNR .
* ls_accountpayable-sub_number = | ls_item-anln2 ALPHA = IN | . "ls_item-AUFNR .
ls_accountpayable-item_text = ls_item-sgtxt .
ls_accountpayable-sp_gl_ind = lv_umskz.
APPEND ls_accountpayable TO lt_accountpayable.
WHEN 'D'. "客户
CLEAR:ls_accountreceivable.
ls_accountreceivable-itemno_acc = ls_item-buzei.
ls_accountreceivable-gl_account = ls_item-hkont.
ls_accountreceivable-customer = ls_item-kunnr.
ls_accountreceivable-profit_ctr = | ls_item-prctr ALPHA = IN |. "ls_item-AUFNR .
ls_accountreceivable-ref_key_3 = ls_item-xref3 .
ls_accountreceivable-item_text = ls_item-sgtxt .
ls_accountreceivable-sp_gl_ind = lv_umskz.
IF lv_umskz = 'C' OR lv_umskz = 'E'.
ls_accountreceivable-bline_date = ls_item-zfbdt.
ENDIF.
APPEND ls_accountreceivable TO lt_accountreceivable.
ENDCASE.
ENDIF.
CLEAR:ls_currencyamount.
ls_currencyamount-itemno_acc = ls_item-buzei.
ls_currencyamount-currency = is_head-waers.
CASE ls_item-shkzg.
WHEN 'S'.
ls_currencyamount-amt_doccur = abs( ls_item-wrbtr ).
WHEN 'H'.
ls_currencyamount-amt_doccur = abs( ls_item-wrbtr ) * ( -1 ).
ENDCASE.
APPEND ls_currencyamount TO lt_currencyamount.
* extension2
IF ls_item-rstgr IS NOT INITIAL OR ls_item-ebeln IS NOT INITIAL.
CLEAR:ls_item_exten,ls_extension2.
ls_item_exten-posnr = ls_item-buzei.
ls_item_exten-rstgr = ls_item-rstgr.
IF ls_item-ebeln NE ''.
ls_item_exten-ebeln = ls_item-ebeln.
ls_item_exten-ebelp = '00010'.
ENDIF.
ls_extension2-structure = 'ZBAPI_ACC_ITEM_EXTEN'.
ls_extension2-valuepart1 = ls_item_exten.
APPEND ls_extension2 TO lt_extension2.
ENDIF.
*--- Add by xiax 02.03.2022 15:59:09 Start ----*
" 针对BSED无法写入,增强写入BAPI中的XBSED 增强位置LFACIF5D->ZFI_BSED。
CASE lv_umskz.
WHEN 'E' OR 'W'.
CLEAR ls_bsed.
ls_bsed-buzei = ls_item-buzei.
SELECT SINGLE butxt,ort01
FROM t001
INTO ( @ls_bsed-wname,@ls_bsed-wort1 )" 汇票收款人
WHERE bukrs = @is_head-bukrs.
SELECT SINGLE c~name1,c~city1,c~region
FROM but020 AS a
LEFT OUTER JOIN adrc AS c
ON a~addrnumber = c~addrnumber
AND c~date_from <= @sy-datum
AND c~date_to >= @sy-datum
INTO ( @ls_bsed-wbzog,@ls_bsed-wort2,@ls_bsed-regio ) " 汇票付款人
WHERE a~partner = @ls_item-kunnr.
APPEND ls_bsed TO lt_bsed.
WHEN OTHERS.
ENDCASE.
*--- Add by xiax 02.03.2022 15:59:09 End ----*
ENDLOOP.
EXPORT lt_bsed TO MEMORY ID 'ZFIZY002'.
IF lt_currencyamount[] IS NOT INITIAL.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = ls_documentheader
IMPORTING
obj_type = lv_obj_type
obj_key = lv_obj_key
obj_sys = lv_obj_sys
TABLES
accountgl = lt_accountgl
ls_accountreceivable = lt_accountreceivable
ls_accountpayable = lt_accountpayable
* ACCOUNTTAX =
ls_currencyamount = lt_currencyamount
criteria = lt_criteria
* VALUEFIELD =
* EXTENSION1 =
return = lt_return
* PAYMENTCARD =
* CONTRACTITEM =
extension2 = lt_extension2
* REALESTATE =
* ACCOUNTWT =
.
LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<fs_return>) WHERE type CA 'EA'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = <fs_return>-id
msgnr = <fs_return>-number
msgv1 = <fs_return>-message_v1
msgv2 = <fs_return>-message_v2
msgv3 = <fs_return>-message_v3
msgv4 = <fs_return>-message_v4
IMPORTING
message_text_output = <fs_return>-message.
es_return-message = es_return-message && <fs_return>-message.
ENDLOOP.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
es_return-type = 'S'.
es_return-bukrs = lv_obj_key+10(4).
es_return-belnr = lv_obj_key(10).
es_return-gjahr = lv_obj_key+14(4).
es_return-message = '凭证过账成功'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDFUNCTION.
FORM set_criteria_data TABLES lt_criteria STRUCTURE bapiackec9
USING VALUE(value1)
VALUE(value2)
VALUE(value3).
DATA:ls_criteria TYPE bapiackec9.
ls_criteria-itemno_acc = value1.
ls_criteria-fieldname = value2.
ls_criteria-character = value3.
APPEND ls_criteria TO lt_criteria.
CLEAR:ls_criteria.
ENDFORM.
2.抬头/行项目 字段增强
有些字段可能在bapi里面不存在,需要进行增强,还有一些比如供应商/客户科目,bapi里面没有提供字段的写入逻辑,就需要使用到增强。
我们可以看到bapi的EXTENSION2参数里面给了详细的增强位置,我们只需要se19激活这个增强即可。
写在CHANGE里即可,具体代码如下:
METHOD if_ex_acc_document~change .
DATA: wa_extension TYPE bapiparex,
ext_value(960) TYPE c,
wa_accit TYPE accit,
l_ref TYPE REF TO data.
FIELD-SYMBOLS: <l_struc> TYPE any,
<l_field> TYPE any.
SORT c_extension2 BY structure.
LOOP AT c_extension2 INTO wa_extension.
AT NEW structure.
CREATE DATA l_ref TYPE (wa_extension-structure).
ASSIGN l_ref->* TO <l_struc>.
ENDAT.
CONCATENATE wa_extension-valuepart1 wa_extension-valuepart2
wa_extension-valuepart3 wa_extension-valuepart4
INTO ext_value.
MOVE ext_value TO <l_struc>.
ASSIGN COMPONENT 'POSNR' OF STRUCTURE <l_struc> TO <l_field>.
IF <l_field> IS ASSIGNED.
READ TABLE c_accit WITH KEY posnr = <l_field>
INTO wa_accit.
IF sy-subrc IS INITIAL.
MOVE-CORRESPONDING <l_struc> TO wa_accit.
MODIFY c_accit FROM wa_accit INDEX sy-tabix.
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD. "IF_EX_ACC_DOCUMENT~CHANGE
二.清账函数 POSTING_INTERFACE_XXX
清账用到了一套函数:
POSTING_INTERFACE_START
POSTING_INTERFACE_CLEARING
POSTING_INTERFACE_END
DATA i_auglv TYPE t041a-auglv.
DATA i_tcode TYPE sy-tcode.
DATA i_sgfunct TYPE rfipi-sgfunct.
DATA e_msgid TYPE sy-msgid.
DATA e_msgno TYPE sy-msgno.
DATA e_msgty TYPE sy-msgty.
DATA e_msgv1 TYPE sy-msgv1.
DATA e_msgv2 TYPE sy-msgv2.
DATA e_msgv3 TYPE sy-msgv3.
DATA e_msgv4 TYPE sy-msgv4.
DATA e_subrc TYPE sy-subrc.
DATA t_blntab TYPE STANDARD TABLE OF blntab.
DATA t_ftclear TYPE STANDARD TABLE OF ftclear.
DATA t_ftpost TYPE STANDARD TABLE OF ftpost.
DATA t_fttax TYPE STANDARD TABLE OF fttax.
DATA p_mode TYPE rfpdo-allgazmd VALUE 'N'.
DATA:ls_ftpost TYPE ftpost,
ls_ftclear TYPE ftclear,
ls_blntab TYPE blntab.
* bdc
DATA: lt_bdcdata TYPE TABLE OF bdcdata.
DATA: ls_bdcdata TYPE bdcdata.
DATA: lv_zyfje TYPE bseg-wrbtr. "应付金额
*&******types
TYPES:BEGIN OF typ_bsid.
INCLUDE STRUCTURE bsid.
TYPES: netdt TYPE bseg-netdt.
TYPES: znum TYPE c,
END OF typ_bsid.
TYPES:BEGIN OF typ_bsik.
INCLUDE STRUCTURE bsik.
TYPES: netdt TYPE bseg-netdt.
TYPES: znum TYPE c,
END OF typ_bsik.
TYPES:BEGIN OF typ_bseg,
bukrs TYPE bseg-bukrs,
belnr TYPE bseg-belnr,
gjahr TYPE bseg-gjahr,
buzei TYPE bseg-buzei,
netdt TYPE bseg-netdt,
END OF typ_bseg.
DATA:lt_bseg TYPE TABLE OF typ_bseg,
ls_bseg TYPE typ_bseg.
DATA:lt_zfit001 TYPE TABLE OF zfit001,
ls_zfit001 TYPE zfit001.
DATA:lv_mitkz TYPE mitkz,
lv_umskz TYPE umskz,
lv_wrbtr TYPE string.
DATA:gv_id TYPE char20. "MEMORY ID
DATA:lv_menge TYPE menge_d.
DATA:lv_shkzg TYPE shkzg.
RANGES:lr_xblnr FOR bkpf-xblnr.
RANGES:lr_xref3 FOR bseg-xref3.
RANGES:lr_hkont FOR bseg-hkont.
RANGES:lr_lifnr FOR bseg-lifnr,
lr_kunnr FOR bseg-kunnr.
DATA:lt_hkont TYPE RANGE OF bseg-hkont.
* 定义宏
DEFINE def_ftpost.
ls_ftpost-stype = &1.
ls_ftpost-count = &2.
ls_ftpost-fnam = &3.
ls_ftpost-fval = &4.
APPEND ls_ftpost TO t_ftpost.
END-OF-DEFINITION.
DEFINE def_bdcdata.
CLEAR ls_bdcdata.
ls_bdcdata-program = &1.
ls_bdcdata-dynpro = &2.
ls_bdcdata-dynbegin = &3.
ls_bdcdata-fnam = &4.
ls_bdcdata-fval = &5.
APPEND ls_bdcdata TO lt_bdcdata.
END-OF-DEFINITION.
"银行科目
lt_hkont = VALUE #( sign = 'I' option = 'CP' ( low = '1001*' )
( low = '1002*' )
( low = '1012*' )
).
IF pt_item[] IS NOT INITIAL.
SELECT bukrs,
lifnr,
umsks,
umskz,
augdt,
augbl,
zuonr,
gjahr,
belnr,
buzei
FROM bsik
INTO TABLE @DATA(lt_bsik)
FOR ALL ENTRIES IN @pt_item
WHERE bukrs = @i_head-bukrs
AND gjahr = @pt_item-gjahr
AND belnr = @pt_item-belnr.
SORT lt_bsik BY bukrs gjahr belnr.
SELECT bukrs,
kunnr,
umsks,
umskz,
augdt,
augbl,
zuonr,
gjahr,
belnr,
buzei
FROM bsid
INTO TABLE @DATA(lt_bsid)
FOR ALL ENTRIES IN @pt_item
WHERE bukrs = @i_head-bukrs
AND gjahr = @pt_item-gjahr
AND belnr = @pt_item-belnr.
SORT lt_bsid BY bukrs gjahr belnr.
ENDIF.
REFRESH:lt_zfit001[].
SELECT * INTO TABLE lt_zfit001 FROM zfit001 WHERE zzffs = i_head-zzffs.
CLEAR:lt_bdcdata,gv_id.
CONCATENATE sy-uname 'ADD_SCR' INTO gv_id.
" 部分清账界面 6014
def_bdcdata: 'SAPDF05X' '3100' 'X' '' '',
'' '' '' 'BDC_OKCODE' '=PART', " 点击部分清账页签
'' '' '' 'BDC_SUBSCR' 'SAPDF05X 6102PAGE',
'' '' '' 'BDC_CURSOR' 'DF05B-PSSKT(01)',
'' '' '' 'RF05A-ABPOS' '1'.
DATA:doc_line TYPE i.
DATA:lv_kbetr TYPE string.
REFRESH: t_blntab[], t_ftclear[], t_ftpost[], t_fttax[].
" Header
def_ftpost: 'K' '001' 'BKPF-BUKRS' i_head-bukrs, " 公司代码
'K' '001' 'BKPF-BUDAT' i_head-budat, " 过账日期
'K' '001' 'BKPF-BLDAT' i_head-bldat, " 记账日期
'K' '001' 'BKPF-MONAT' i_head-budat+4(2), " 期间
'K' '001' 'BKPF-BLART' i_head-blart, " 凭证类型
'K' '001' 'BKPF-WAERS' i_head-waers, " 货币
'K' '001' 'BKPF-XBLNR' i_head-xblnr, " 参考
'K' '001' 'BKPF-BKTXT' i_head-bktxt. " 抬头文本
" 查找清账行
CLEAR:doc_line.
LOOP AT pt_item INTO DATA(ps_item) WHERE belnr NE ''. " 凭证号不为空的行,循环
* 'Z2' 'P'
CLEAR:lv_mitkz.
SELECT SINGLE mitkz INTO lv_mitkz FROM skb1 WHERE bukrs = i_head-bukrs AND saknr = ps_item-hkont.
IF sy-subrc = 0.
CASE lv_mitkz.
WHEN 'K'. " 供应商
READ TABLE lt_bsik INTO DATA(ls_bsik) WITH KEY bukrs = i_head-bukrs gjahr = ps_item-gjahr belnr = ps_item-belnr BINARY SEARCH.
IF sy-subrc EQ 0.
ps_item-buzei = ls_bsik-buzei.
ps_item-umskz = ls_bsik-umsks.
ENDIF.
lv_shkzg = 'S'.
CLEAR ls_ftclear.
ls_ftclear-agkoa = 'K'. " 账户类型
ls_ftclear-agbuk = i_head-bukrs. " 公司代码
IF ps_item-umskz IS INITIAL.
ls_ftclear-xnops = 'X'. " 未清
ELSE.
ls_ftclear-agums = ps_item-umskz." 特殊总帐标识符
ENDIF.
ls_ftclear-selfd = 'BELNR'. " 凭证索引中的字段名
ls_ftclear-agkon = ps_item-lifnr. " 供应商
ls_ftclear-selvon = ps_item-belnr && ps_item-gjahr && ps_item-buzei. "选择未清项目的搜索标准的输入字段
APPEND ls_ftclear TO t_ftclear.
def_bdcdata: 'SAPDF05X' '3100' 'X' '' '',
'' '' '' 'BDC_OKCODE' '=OSU', " 点击筛选按钮
'' '' '' 'BDC_SUBSCR' 'SAPDF05X 6104PAGE',
'' '' '' 'BDC_CURSOR' 'RF05A-ABPOS',
'' '' '' 'RF05A-ABPOS' '1'.
"选择凭证编号按钮
def_bdcdata: 'SAPDF05X' '2000' 'X' '' '',
'' '' '' 'BDC_CURSOR' 'RF05A-XPOS1(03)',
'' '' '' 'BDC_OKCODE' '=GO', " 下一步
'' '' '' 'RF05A-XPOS1(01)' '',
'' '' '' 'RF05A-XPOS1(03)' 'X'." 选择凭证编号
"填入凭证编号
def_bdcdata: 'SAPDF05X' '0731' 'X' '' '',
'' '' '' 'BDC_CURSOR' 'RF05A-SEL01(01)',
'' '' '' 'BDC_OKCODE' '=GO', " 下一步
'' '' '' 'RF05A-SEL01(01)' ps_item-belnr . " 填入凭证编号
"填入金额
CLEAR:lv_wrbtr.
lv_wrbtr = ps_item-wrbtr.
CONDENSE lv_wrbtr NO-GAPS.
def_bdcdata: 'SAPDF05X' '3100' 'X' '' '',
'' '' '' 'BDC_OKCODE' '/00', "回车
'' '' '' 'BDC_SUBSCR' 'SAPDF05X 6104PAGE',
'' '' '' 'RF05A-ABPOS' '1',
'' '' '' 'BDC_CURSOR' 'DF05B-PSZAH(01)',
'' '' '' 'DF05B-PSZAH(01)' lv_wrbtr.""金额
def_bdcdata: 'SAPDF05X' '3100' 'X' '' '',
'' '' '' 'BDC_OKCODE' '=OSE', "返回上一层
'' '' '' 'BDC_SUBSCR' 'SAPDF05X 6104PAGE'.
WHEN 'D'."客户
READ TABLE lt_bsid INTO DATA(ls_bsid) WITH KEY bukrs = i_head-bukrs gjahr = ps_item-gjahr belnr = ps_item-belnr BINARY SEARCH.
IF sy-subrc EQ 0.
ps_item-buzei = ls_bsid-buzei.
ps_item-umskz = ls_bsid-umsks.
ENDIF.
lv_shkzg = 'H'.
CLEAR ls_ftclear.
ls_ftclear-agkoa = 'D'. "账户类型
ls_ftclear-agbuk = i_head-bukrs. "公司代码
IF ps_item-umskz IS INITIAL.
ls_ftclear-xnops = 'X'. "" No Special G/L items
ELSE.
ls_ftclear-agums = ps_item-umskz.
ENDIF.
ls_ftclear-selfd = 'BELNR'. "凭证索引中的字段名
ls_ftclear-agkon = ps_item-kunnr. "客户
ls_ftclear-selvon = ps_item-belnr && ps_item-gjahr && ps_item-buzei. "选择未清项目的搜索标准的输入字段
APPEND ls_ftclear TO t_ftclear.
def_bdcdata: 'SAPDF05X' '3100' 'X' '' '',
'' '' '' 'BDC_OKCODE' '=OSU', "点击筛选按钮
'' '' '' 'BDC_SUBSCR' 'SAPDF05X 6104PAGE',
'' '' '' 'BDC_CURSOR' 'RF05A-ABPOS',
'' '' '' 'RF05A-ABPOS' '1'.
" 选择凭证编号按钮
def_bdcdata: 'SAPDF05X' '2000' 'X' '' '',
'' '' '' 'BDC_CURSOR' 'RF05A-XPOS1(03)',
'' '' '' 'BDC_OKCODE' '=GO', "下一步
'' '' '' 'RF05A-XPOS1(01)' '',
'' '' '' 'RF05A-XPOS1(03)' 'X'. "选择凭证编号
"填入凭证编号
def_bdcdata: 'SAPDF05X' '0731' 'X' '' '',
'' '' '' 'BDC_CURSOR' 'RF05A-SEL01(01)',
'' '' '' 'BDC_OKCODE' '=GO', "下一步
'' '' '' 'RF05A-SEL01(01)' ps_item-belnr . "填入凭证编号
"填入金额
CLEAR:lv_wrbtr.
lv_wrbtr = ps_item-wrbtr.
CONDENSE lv_wrbtr NO-GAPS.
def_bdcdata: 'SAPDF05X' '3100' 'X' '' '',
'' '' '' 'BDC_OKCODE' '/00', "回车
'' '' '' 'BDC_SUBSCR' 'SAPDF05X 6104PAGE',
'' '' '' 'RF05A-ABPOS' '1',
'' '' '' 'BDC_CURSOR' 'DF05B-PSZAH(01)',
'' '' '' 'DF05B-PSZAH(01)' lv_wrbtr.""金额
def_bdcdata: 'SAPDF05X' '3100' 'X' '' '',
'' '' '' 'BDC_OKCODE' '=OSE', "返回上一层
'' '' '' 'BDC_SUBSCR' 'SAPDF05X 6104PAGE'.
WHEN OTHERS.
...
ENDCASE.
ENDIF.
ENDLOOP.
" 过账
def_bdcdata: 'SAPDF05X' '3100' 'X' '' '',
'' '' '' 'BDC_OKCODE' '=BU', " 保存过账
'' '' '' 'BDC_SUBSCR' 'SAPDF05X 6104PAGE',
'' '' '' 'BDC_CURSOR' 'DF05B-PSZAH(01)',
'' '' '' 'RF05A-ABPOS' '1'.
CLEAR:doc_line.
LOOP AT pt_item INTO ps_item WHERE shkzg = 'S' AND belnr EQ ''.
doc_line = doc_line + 1.
lv_kbetr = ps_item-wrbtr.
CONDENSE lv_kbetr NO-GAPS.
* 特殊总账标识
CLEAR:lv_umskz,ls_zfit001.
LOOP AT lt_zfit001 INTO ls_zfit001 WHERE shkzg = ps_item-shkzg.
REFRESH:lr_hkont.
MOVE 'ICP' TO lr_hkont. lr_hkont-low = ls_zfit001-hkont. APPEND lr_hkont.
IF ps_item-hkont IN lr_hkont.
EXIT.
ELSE.
CLEAR:ls_zfit001.
ENDIF.
ENDLOOP.
def_ftpost : 'P' doc_line 'RF05A-NEWBS' ls_zfit001-bschl, " posting key
'P' doc_line 'RF05A-NEWUM' ls_zfit001-umskz.
IF ps_item-kunnr IS NOT INITIAL.
def_ftpost:'P' doc_line 'RF05A-NEWKO' ps_item-kunnr.
ELSEIF ps_item-lifnr IS NOT INITIAL.
def_ftpost:'P' doc_line 'RF05A-NEWKO' ps_item-lifnr.
ELSE.
def_ftpost:'P' doc_line 'RF05A-NEWKO' ps_item-hkont. " G/L account
ENDIF.
IF ps_item-hkont IN lt_hkont.
IF ps_item-hkont(4) NE '1001'.
def_ftpost :'P' doc_line 'BSEG-HBKID' ps_item-hbkid. " G/L account
def_ftpost :'P' doc_line 'BSEG-HKTID' ps_item-hktid. " G/L account
ENDIF.
def_ftpost :'P' doc_line 'BSEG-RSTGR' ps_item-rstgr. " G/L account
ENDIF.
def_ftpost : 'P' doc_line 'BSEG-WRBTR' lv_kbetr. " amount
def_ftpost : 'P' doc_line 'COBL-PRCTR' ps_item-prctr. " 利润中心
IF ls_zfit001-umskz CA 'EW'.
def_ftpost : 'P' doc_line 'BSEG-ZFBDT' ps_item-zfbdt. "reason code
ENDIF.
*记账方式字段ZZFFS=Z, 科目类型KOART=D 借贷标识SHKZG=S ,UMSKZ不为空 字段ZFBDT为空则默认为系统当前日期加2个月
CLEAR:lv_mitkz.
SELECT SINGLE mitkz INTO lv_mitkz FROM skb1 WHERE bukrs = i_head-bukrs
AND saknr = ps_item-hkont
AND mitkz = 'D'.
IF sy-subrc = 0 AND i_head-zzffs = 'Z'.
CALL FUNCTION 'MONTH_PLUS_DETERMINE'
EXPORTING
months = 2
olddate = sy-datum "输入日期
IMPORTING
newdate = ps_item-zfbdt. "返回日期:20140401
def_ftpost : 'P' doc_line 'BSEG-ZFBDT' ps_item-zfbdt.
ENDIF.
def_ftpost : 'P' doc_line 'BSEG-SGTXT' ps_item-sgtxt.
IF ps_item-xref3 IS NOT INITIAL.
def_ftpost : 'P' doc_line 'BSEG-XREF3' ps_item-xref3.
ENDIF.
ENDLOOP.
* CLEAR:doc_line.
LOOP AT pt_item INTO ps_item WHERE shkzg = 'H' AND belnr EQ ''.
doc_line = doc_line + 1.
lv_kbetr = ps_item-wrbtr.
CONDENSE lv_kbetr NO-GAPS.
* 特殊总账标识
CLEAR:lv_umskz,ls_zfit001.
LOOP AT lt_zfit001 INTO ls_zfit001 WHERE shkzg = ps_item-shkzg.
REFRESH:lr_hkont.
MOVE 'ICP' TO lr_hkont. lr_hkont-low = ls_zfit001-hkont. APPEND lr_hkont.
IF ps_item-hkont IN lr_hkont.
EXIT.
ELSE.
CLEAR:ls_zfit001.
ENDIF.
ENDLOOP.
def_ftpost : 'P' doc_line 'RF05A-NEWBS' ls_zfit001-bschl, " posting key
'P' doc_line 'RF05A-NEWUM' ls_zfit001-umskz.
IF ps_item-kunnr IS NOT INITIAL.
def_ftpost:'P' doc_line 'RF05A-NEWKO' ps_item-kunnr.
ELSEIF ps_item-lifnr IS NOT INITIAL..
def_ftpost:'P' doc_line 'RF05A-NEWKO' ps_item-lifnr.
ELSEIF ps_item-hkont IS NOT INITIAL.
def_ftpost:'P' doc_line 'RF05A-NEWKO' ps_item-hkont. " G/L account
ENDIF.
IF ps_item-hkont IN lt_hkont.
def_ftpost :'P' doc_line 'BSEG-HBKID' ps_item-hbkid. " G/L account
def_ftpost :'P' doc_line 'BSEG-HKTID' ps_item-hktid. " G/L account
def_ftpost :'P' doc_line 'BSEG-RSTGR' ps_item-rstgr. " G/L account
ENDIF.
def_ftpost : 'P' doc_line 'BSEG-WRBTR' lv_kbetr. " amount
def_ftpost : 'P' doc_line 'COBL-PRCTR' ps_item-prctr. " 利润中心
IF ls_zfit001-umskz CA 'EW'.
def_ftpost : 'P' doc_line 'BSEG-ZFBDT' ps_item-zfbdt. "reason code
ENDIF.
def_ftpost : 'P' doc_line 'BSEG-SGTXT' ps_item-sgtxt.
IF ps_item-xref3 IS NOT INITIAL.
def_ftpost : 'P' doc_line 'BSEG-XREF3' ps_item-xref3.
ENDIF.
ENDLOOP.
CALL FUNCTION 'POSTING_INTERFACE_START'
EXPORTING
i_client = sy-mandt
i_function = 'C'
i_keep = 'X'
i_mode = p_mode
i_update = 'S'
i_user = sy-uname
EXCEPTIONS
client_incorrect = 1
function_invalid = 2
group_name_missing = 3
mode_invalid = 4
update_invalid = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO es_return-message.
es_return-type = 'E'.
RETURN.
ELSE.
IF lt_bdcdata IS NOT INITIAL.
EXPORT lt_bdcdata FROM lt_bdcdata TO MEMORY ID gv_id. "部分清账时补充屏幕数据
ENDIF.
REFRESH:t_blntab[].
CALL FUNCTION 'POSTING_INTERFACE_CLEARING'
EXPORTING
i_auglv = 'UMBUCHNG'
i_tcode = 'FB05'
i_sgfunct = 'C'
IMPORTING
e_msgid = e_msgid
e_msgno = e_msgno
e_msgty = e_msgty
e_msgv1 = e_msgv1
e_msgv2 = e_msgv2
e_msgv3 = e_msgv3
e_msgv4 = e_msgv4
e_subrc = e_subrc
TABLES
t_blntab = t_blntab
t_ftclear = t_ftclear
t_ftpost = t_ftpost
t_fttax = t_fttax
EXCEPTIONS
clearing_procedure_invalid = 1
clearing_procedure_missing = 2
table_t041a_empty = 3
transaction_code_invalid = 4
amount_format_error = 5
too_many_line_items = 6
company_code_invalid = 7
screen_not_found = 8
no_authorization = 9.
READ TABLE t_blntab INTO ls_blntab INDEX 1.
IF sy-subrc <> 0.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = e_msgid
lang = sy-langu
no = e_msgno
v1 = e_msgv1
v2 = e_msgv2
v3 = e_msgv3
v4 = e_msgv4
IMPORTING
msg = es_return-message
EXCEPTIONS
not_found = 1
OTHERS = 2.
es_return-type = 'E'.
ELSE.
es_return-type = 'S'.
CONCATENATE ls_blntab-belnr ls_blntab-bukrs ls_blntab-gjahr INTO es_return-message.
es_return-belnr = ls_blntab-belnr.
es_return-gjahr = ls_blntab-gjahr.
es_return-bukrs = ls_blntab-bukrs.
ENDIF.
CALL FUNCTION 'POSTING_INTERFACE_END'
EXPORTING
i_bdcimmed = 'X'
EXCEPTIONS
session_not_processable = 1
OTHERS = 2.
ENDIF.
三.替代(BTE)
tcode FIBF
复制一个SAMPLE_PROCESS_00001120为
ZSAMPLE_PROCESS_00001120,同时更新结构BKPF_SUBST和BSEG_SUBST
具体的操作步骤可以参考以下链接:
SAP BTE增强
四.隐式增强
主要是在凭证创建的一些增强替代,FM: ac_document_create中查询对应的增强位置,程序LRWCLF01->document_create
凭证配置报错 Message:凭证错误: BKPFF $ 不支持的特殊总帐交易
通过程序LFACIF02->subst_bschl
AFAB替代增强,更新其中的功能范围
暂时只更新了这么多,还有一些没有更新,等有空。
以上是关于近期的ABAP FI开发总结的主要内容,如果未能解决你的问题,请参考以下文章
sap fi清账函数POSTING_INTERFACE*的使用