FBL5N 查询客户未清项
清账方式
标准清账:未清行全部进已清
部分清账:部分清的那行还在未清,其他的进已清,产生一行未清参考部分清账那行
剩余清账:原行项目全部变成已清,产生一笔新的未清项凭证
客户付款有两种方式
正常收款冲账:开发票给客户,客户直接付款,这样做会计凭证并自动清账。在fb05先清帐,然后录入手工科目行。
暂收款冲账:用预付款冲账(清账时用预收款的会计凭证和发票)。
预收时记账,借 客户(固定的 票据客户)特别总账-承兑汇票 ,贷 预收;
清账时记账 借 客户特别总账-预收账款
其他清账
客户 应收清应付
客户应收 清供应商应付
用BDC清
如果清账要填行项目,行项目的屏幕可能是不一样的,可以用 NEXT_DYNPRO_SEARCH 确定屏幕,附加屏幕一共就4个,也可以计算出来了,参考函数 ZFM_AR_03_16。
可以定位到未清凭证行项目上,参考 ZFM_AR_03_16。
对于动态屏幕,必填字段等,可以使用替代处理
BDC DEMO
form frm_acc_clear_bdc .
data:begin of lt_alv_c occurs 0,
bukrs like gt_alv-bukrs,
waers like gt_alv-waers,
partner like gt_alv-partner,
dimension like gt_alv-dimension,
wrbtr like gt_alv-wrbtr,
wrbtr_s like gt_alv-wrbtr,
wrbtr_h like gt_alv-wrbtr,
augbl like gt_alv-augbl,
rtype like gt_alv-rtype,
rtmsg like gt_alv-rtmsg,
end of lt_alv_c.
data:
* lt_ztfi048b like table of ztfi048b with header line,
lv_blart like bkpf-blart,
lv_wrbtr_s like gt_alv-wrbtr,
lv_wrbtr_h like gt_alv-wrbtr,
lv_abpos type abpos_f05a. "开始显示的项目号
* if p_d = 'X'..
* lv_blart = 'Z1'.
* else.
* lv_blart = 'Z2'.
* endif.
lv_blart = 'AB'.
loop at gt_alv where sel = 'X'.
clear:lt_alv_c.
lt_alv_c-bukrs = gt_alv-bukrs.
lt_alv_c-partner = gt_alv-partner.
lt_alv_c-waers = gt_alv-waers.
lt_alv_c-dimension = gt_alv-dimension.
if gt_alv-shkzg = 'S'.
lt_alv_c-wrbtr_s = gt_alv-wrbtr.
elseif gt_alv-shkzg = 'H'.
lt_alv_c-wrbtr_h = gt_alv-wrbtr.
endif.
collect lt_alv_c.
endloop.
if sy-subrc ne 0.
message e001(00) with '至少选择一行'.
endif.
delete lt_alv_c where wrbtr_s is initial or wrbtr_h is initial.
loop at lt_alv_c.
if lt_alv_c-wrbtr_s <= lt_alv_c-wrbtr_h.
lt_alv_c-wrbtr = lt_alv_c-wrbtr_s.
else.
lt_alv_c-wrbtr = lt_alv_c-wrbtr_h.
endif.
clear:lv_wrbtr_s,lv_wrbtr_h,lv_abpos.
perform frm_bdc_init.
* 抬头
perform frm_bdc_dynnr using 'SAPMF05A' '0122'.
perform frm_bdc_field using 'DATS' 'BKPF-BLDAT' sy-datum.
perform frm_bdc_field using space 'BKPF-BLART' lv_blart.
perform frm_bdc_field using space 'BKPF-BUKRS' lt_alv_c-bukrs .
perform frm_bdc_field using 'DATS' 'BKPF-BUDAT' sy-datum.
perform frm_bdc_field using space 'BKPF-WAERS' lt_alv_c-waers.
* perform frm_bdc_field using space 'BKPF-BKTXT' is_head-bktxt. " 工单号写入抬头文本
* if is_head-kursf is not initial.
* perform frm_bdc_field using 'NUM' 'BKPF-KURSF' is_head-kursf. " 汇率
* endif.
* if is_head-wwert is not initial.
* perform frm_bdc_field using 'DATS' 'BKPF-WWERT' is_head-wwert. " 换算日期
* endif.
perform frm_bdc_field using space 'BDC_OKCODE' '=SL' . "选择未清项
loop at gt_alv where partner = lt_alv_c-partner and dimension = lt_alv_c-dimension and sel = 'X'.
lv_abpos = lv_abpos + 1.
data(lv_str) = gt_alv-belnr && gt_alv-gjahr && gt_alv-buzei.
if gt_alv-shkzg = 'S'.
lv_wrbtr_s = lv_wrbtr_s + gt_alv-wrbtr.
else.
lv_wrbtr_h = lv_wrbtr_h + gt_alv-wrbtr.
endif.
*选择未清借贷截止行
if ( lv_wrbtr_s > lt_alv_c-wrbtr_h and gt_alv-shkzg = 'S' )
or ( lv_wrbtr_h > lt_alv_c-wrbtr_s and gt_alv-shkzg = 'H' ).
continue.
endif.
*选择未清项目
perform frm_bdc_dynnr using 'SAPMF05A' '0710'.
perform frm_bdc_field using space 'RF05A-AGKOA' gv_agkoa . "账户类型
perform frm_bdc_field using space 'RF05A-AGUMS' gt_alv-umskz . "特别总账标识
*选择
perform frm_bdc_field using space 'BDC_OKCODE' '/05'. "选择
perform frm_bdc_dynnr using 'SAPMF05A' '0733'. "弹框选择凭证
perform frm_bdc_field using space 'RF05A-FELDN(01)' 'BELNR'.
perform frm_bdc_field using space 'RF05A-SEL01(01)' lv_str.
perform frm_bdc_field using space 'BDC_OKCODE' '=PA'. "处理未清项
*计算到最后一行,开始清账
if lt_alv_c-wrbtr_s < lt_alv_c-wrbtr_h.
if lv_wrbtr_s = lt_alv_c-wrbtr_s and lv_wrbtr_s < lv_wrbtr_h.
data(lv_exit) = 'X'.
endif.
elseif lt_alv_c-wrbtr_s > lt_alv_c-wrbtr_h.
if lv_wrbtr_h = lt_alv_c-wrbtr_h and lv_wrbtr_s > lv_wrbtr_h.
lv_exit = 'X'.
endif.
elseif lt_alv_c-wrbtr_s = lt_alv_c-wrbtr_h.
if lv_wrbtr_h = lt_alv_c-wrbtr_h and lv_wrbtr_s = lv_wrbtr_h.
lv_exit = 'X'.
endif.
endif.
if lv_exit = 'X'.
*部分/剩余清账行
if lv_wrbtr_s ne lv_wrbtr_h.
* if p_d = 'X'. "部分清账
data(lv_okcode) = '=PART'.
data(lv_fname) = 'DF05B-PSZAH(01)'.
* elseif p_k = 'X'. "剩余清账
lv_okcode = 'REST'.
lv_fname = 'DF05B-PSDIF(01)'.
* endif.
*处理未清项
perform frm_bdc_dynnr using 'SAPDF05X' '3100'.
perform frm_bdc_field using space 'BDC_OKCODE' lv_okcode.
perform frm_bdc_dynnr using 'SAPDF05X' '3100'.
perform frm_bdc_field using space 'RF05A-ABPOS' lv_abpos. "定位
perform frm_bdc_field using space 'BDC_OKCODE' '=/00'.
perform frm_bdc_dynnr using 'SAPDF05X' '3100'.
perform frm_bdc_field using space 'BDC_CURSOR' lv_fname.
perform frm_bdc_field using space 'BDC_OKCODE' '=PI'. "双击
endif.
*标准清账
exit.
endif.
*概览
perform frm_bdc_dynnr using 'SAPDF05X' '3100'.
perform frm_bdc_field using space 'BDC_OKCODE' '=AB'. "概览
perform frm_bdc_dynnr using 'SAPMF05A' '0700'.
perform frm_bdc_field using space 'BDC_OKCODE' '=SL'. "选择未清项
endloop.
*概览
perform frm_bdc_dynnr using 'SAPDF05X' '3100'.
perform frm_bdc_field using space 'BDC_OKCODE' '=AB'. "概览
perform frm_bdc_dynnr using 'SAPMF05A' '0700'.
perform frm_bdc_field using space 'BDC_OKCODE' '=BU'. "保存
perform frm_bdc_call using 'FB05' 'F5' '312' changing lt_alv_c-rtype lt_alv_c-rtmsg.
lt_alv_c-augbl = gt_messtab-msgv1.
modify lt_alv_c.
endloop.
loop at gt_alv where sel = 'X'.
read table lt_alv_c with key partner = gt_alv-partner dimension = gt_alv-dimension.
if sy-subrc = 0.
gt_alv-augbl = lt_alv_c-augbl.
gt_alv-rtype = lt_alv_c-rtype.
gt_alv-rtmsg = lt_alv_c-rtmsg.
modify gt_alv.
endif.
endloop.
endform.
用函数清(废弃,BDC解决所有问题)
只能做标准和剩余清账,不能做部分清(不确定)
form frm_posting_interface_clearing using uv_hkont changing us_alv like gt_alv .
data: it_blntab type table of blntab with header line,
it_ftclear type table of ftclear with header line,
it_ftpost type table of ftpost with header line,
it_fttax type table of fttax with header line.
export ebr_id from us_alv-ebr_id to memory id 'EBR_POST'.
call function 'POSTING_INTERFACE_START'
exporting
i_function = 'C' "B= BDC, C= Call Trans.
i_keep = 'X' "用于已处理会话的队列删除标志
i_mode = 'N'
exceptions
client_incorrect = 1
function_invalid = 2
group_name_missing = 3
mode_invalid = 4
update_invalid = 5
others = 6.
*日期处理
write sy-datum to sy-datum.
write us_alv-bank_date to us_alv-bank_date.
populate_ftpost:
'K' 1 'BKPF-BUKRS' us_alv-bukrs, "Company code
'K' 1 'BKPF-BLART' 'AB',
'K' 1 'BKPF-BLDAT' sy-datum,
'K' 1 'BKPF-BUDAT' us_alv-bank_date,
'K' 1 'BKPF-WAERS' us_alv-currency,
* 'K' 1 'BKPF-XBLNR' 'Test',
'P' 1 'RF05A-NEWBS' '40',
'P' 1 'BSEG-HKONT' uv_hkont, "银行科目
'P' 1 'BSEG-SGTXT' ':销售商品、提供劳务收到的现金',
'P' 1 'BSEG-VBUND' '1000', "用于测试
'P' 1 'COBL-PRCTR' us_alv-prctr.
if us_alv-rstgr is not initial.
populate_ftpost 'P' 1 'BSEG-RSTGR' us_alv-rstgr. "原因代码
endif.
* 'P' 1 'BSEG-WRBTR' us_alv-amt_claimed,
*金额的bdc处理
it_ftpost-fnam = 'BSEG-WRBTR'.
write us_alv-amt_claimed to it_ftpost-fval(16).
append it_ftpost.
*未清项
loop at gt_epic_ebr_seg into data(ls_epic_ebr_seg) where ebr_id = us_alv-ebr_id.
data(lv_str) = ls_epic_ebr_seg-belnr && ls_epic_ebr_seg-gjahr && ls_epic_ebr_seg-buzei.
if ls_epic_ebr_seg-part_type = 'K'.
select single umskz
into @data(lv_umskz)
from bsik
where gjahr = @ls_epic_ebr_seg-gjahr and bukrs = @ls_epic_ebr_seg-bukrs
and belnr = @ls_epic_ebr_seg-belnr and buzei = @ls_epic_ebr_seg-buzei.
elseif ls_epic_ebr_seg-part_type = 'D'.
select single umskz
into lv_umskz
from bsid
where gjahr = ls_epic_ebr_seg-gjahr and bukrs = ls_epic_ebr_seg-bukrs
and belnr = ls_epic_ebr_seg-belnr and buzei = ls_epic_ebr_seg-buzei.
endif.
populate_ftclear lv_str us_alv-bukrs lv_umskz ls_epic_ebr_seg-part_type. "concatenate doc number + fiscal year + line number
endloop.
call function 'POSTING_INTERFACE_CLEARING'
exporting
* i_auglv = 'UMBUCHNG'
i_auglv = 'AUSGZAHL'
i_tcode = 'FB05'
* i_sgfunct = 'C'
importing
e_msgid = sy-msgid
e_msgno = sy-msgno
e_msgty = sy-msgty
e_msgv1 = sy-msgv1
e_msgv2 = sy-msgv2
e_msgv3 = sy-msgv3
e_msgv4 = sy-msgv4
* E_SUBRC = SY-SUBRC
tables
t_blntab = it_blntab
t_ftclear = it_ftclear
t_ftpost = it_ftpost
t_fttax = it_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
others = 10.
if sy-msgty = 'S' and sy-msgid = 'F5' and sy-msgno = '312'.
us_alv-rtype = 'S'.
* us_alv-belnr_clearing = sy-msgv1.
us_alv-belnr = sy-msgv1.
us_alv-rtmsg = us_alv-rtmsg && '清账成功:' && ';'.
us_alv-status_desc = '已过账'.
elseif sy-subrc <> 0 or sy-msgty = 'E'.
us_alv-rtype = 'E'.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into data(lv_msg).
us_alv-rtmsg = us_alv-rtmsg && '清账失败:' && lv_msg && ';'.
endif.
call function 'POSTING_INTERFACE_END'
exceptions
session_not_processable = 1
others = 2.
if us_alv-rtype = 'S'.
*部分认领再做一笔预收
if us_alv-status = '025'.
perform frm_acc_post_advance_receipt using uv_hkont changing gt_alv.
endif.
endif.
endform.
函数剩余清账
增强位置
主程序 SAPLFIPI include LFIPIF00 form transaktion_beenden
FORM transaktion_beenden USING p_no_auth TYPE c.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Form TRANSAKTION_BEENDEN, Start A
*$*$-Start: (1)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 1 ZFI_DOC_POST_CLEAR. "active version
"部分清账逻辑
DATA:GV_ID TYPE CHAR20. "MEMORY ID
DATA: LT_BDCDATA TYPE TABLE OF BDCDATA.
DATA: LS_BDCDATA TYPE BDCDATA.
CLEAR:LT_BDCDATA,GV_ID.
CONCATENATE SY-UNAME 'ADD_SCR' INTO GV_ID.
IMPORT LT_BDCDATA to LT_BDCDATA FROM MEMORY ID GV_ID. "补充屏幕数据
IF LT_BDCDATA IS NOT INITIAL.
APPEND LINES OF lt_bdcdata to ft.
LOOP AT FT WHERE FVAL = '/11'.
FT-FVAL = '=PA'.
MODIFY FT.
ENDLOOP.
ENDIF.
ENDENHANCEMENT.
minth demo