*&---------------------------------------------------------------------* *& Report ZFIP001 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* report zfip001. tables: bsid . selection-screen begin of block bl01 with frame title title1 . " select-options: s_bukrs for bsid-bukrs no intervals no-extension obligatory , "BUKRS 公司代码 Char 4 单选 是 s_kunnr for bsid-kunnr , "KUNNR 客户 Char 10 多选 否 s_augdt for bsid-augdt no intervals no-extension obligatory , "AUGDT 清账日期 DATS 8 单选 是 s_budat for bsid-budat no intervals no-extension obligatory . "BUDAT 清账凭证过账日期 DATS 8 单选 是 selection-screen end of block bl01 . selection-screen begin of block bl02 with frame title title2 . parameters:p_qz radiobutton group rg1 default 'X' , "标准版本 p_ghtk radiobutton group rg1 ."关户退款 selection-screen end of block bl02 . define populate_ftpost. ls_ftpost-stype = &1 . ls_ftpost-count = &2 . ls_ftpost-fnam = &3 . ls_ftpost-fval = &4 . condense ls_ftpost-fval no-gaps . append ls_ftpost to lt_ftpost . end-of-definition. data: begin of gs_out , bukrs like bsid-bukrs , kunnr like bsid-kunnr , gjahr like bsid-gjahr , belnr like bsid-belnr , yisdq like bapiret2-message , yusdq like bapiret2-message , msg like bapiret2-message , sel type c , end of gs_out , gt_out like table of gs_out . data:begin of lt_wqyis occurs 0 , bukrs like bsid-bukrs , kunnr like bsid-kunnr , gjahr like bsid-gjahr , belnr like bsid-belnr , buzei like bsid-buzei , hkont like bsid-hkont , "科目 budat like bsid-budat , "记账日期 zfbdt like bsid-zfbdt , "记账日期 shkzg like bsid-shkzg , " dmbtr like bsid-dmbtr , " end of lt_wqyis . *data lt_wqyis_h like lt_wqyis[] with header line . data lt_wqyus like lt_wqyis[] with header line . *data lt_wqyus_s like lt_wqyis[] with header line . data ls_wqyis like line of lt_wqyis . data ls_wqyus like line of lt_wqyis . data: begin of lt_kunnr occurs 0 , bukrs like bsid-bukrs , kunnr like bsid-kunnr , yings like bsid-dmbtr , yus like bsid-dmbtr , t_wqyis_h like lt_wqyis[] , t_wqyis_s like lt_wqyis[] , t_wqyus_h like lt_wqyis[] , t_wqyus_s like lt_wqyis[] , t_wqyis like lt_wqyis[] , t_wqyus like lt_wqyis[] , end of lt_kunnr . field-symbols: <fs_out> like gs_out , <fs_wqyis> like lt_wqyis , <fs_wqyus> like lt_wqyis . initialization . title1 = '输入条件' . title2 = '选择功能' . start-of-selection . if p_qz = 'X' . perform fm_get_yis_yus_data . elseif p_ghtk = 'X' . perform fm_customer_clear . endif . perform fm_alv_display . *----------------------------------------------------------------------* form fm_get_yis_yus_data . data: lv_dmbtr_h like bsid-dmbtr , lv_dmbtr_s like bsid-dmbtr . data: lv_get_date like sy-datum , temp_yis like lt_wqyis[] with header line . field-symbols <fs_kunnr> like lt_kunnr . "未清应收 select *"bukrs kunnr hkont budat shkzg dmbtr into corresponding fields of table lt_wqyis[] from bsid where bukrs in s_bukrs and kunnr in s_kunnr and hkont in ('1122001000' , '1122002000') and budat <= s_augdt-low order by bukrs kunnr shkzg zfbdt . "未清预收 select * " bukrs kunnr hkont budat shkzg dmbtr into corresponding fields of table lt_wqyus[] from bsid where bukrs in s_bukrs and kunnr in s_kunnr and umskz = 'A' and budat <= s_augdt-low order by bukrs kunnr shkzg zfbdt . loop at lt_wqyis assigning <fs_wqyis> . * if <fs_wqyis>-shkzg = 'H' . * <fs_wqyis>-dmbtr = - <fs_wqyis>-dmbtr . * endif. append initial line to lt_kunnr assigning <fs_kunnr> . <fs_kunnr>-bukrs = <fs_wqyis>-bukrs . <fs_kunnr>-kunnr = <fs_wqyis>-kunnr . endloop . loop at lt_wqyus assigning <fs_wqyus> . * if <fs_wqyus>-shkzg = 'S' . * <fs_wqyus>-dmbtr = - <fs_wqyus>-dmbtr . * endif. append initial line to lt_kunnr assigning <fs_kunnr> . <fs_kunnr>-bukrs = <fs_wqyus>-bukrs . <fs_kunnr>-kunnr = <fs_wqyus>-kunnr . endloop . sort lt_kunnr by bukrs kunnr . delete adjacent duplicates from lt_kunnr comparing all fields . *---------------------------------------------------------------------- loop at lt_kunnr assigning <fs_kunnr> . append initial line to gt_out assigning <fs_out> . <fs_out>-bukrs = <fs_kunnr>-bukrs . <fs_out>-kunnr = <fs_kunnr>-kunnr . <fs_out>-gjahr = s_budat-low+0(4) . clear: lv_dmbtr_s , lv_dmbtr_h . loop at lt_wqyis where bukrs = <fs_kunnr>-bukrs and kunnr = <fs_kunnr>-kunnr and shkzg = 'H' . lv_dmbtr_h = lv_dmbtr_h + lt_wqyis-dmbtr . append lt_wqyis to <fs_kunnr>-t_wqyis_h[] . endloop . loop at lt_wqyis where bukrs = <fs_kunnr>-bukrs and kunnr = <fs_kunnr>-kunnr and shkzg = 'S' . if lv_dmbtr_h > lv_dmbtr_s . lv_dmbtr_s = lv_dmbtr_s + lt_wqyis-dmbtr . append lt_wqyis to <fs_kunnr>-t_wqyis_s[] . else . exit . endif . endloop . if <fs_kunnr>-t_wqyis_h[] is not initial and <fs_kunnr>-t_wqyis_s[] is not initial . perform fm_posting_interface_clearing tables <fs_kunnr>-t_wqyis_h[] <fs_kunnr>-t_wqyis_s[] using lv_dmbtr_h lv_dmbtr_s s_budat-low 'YISDQ' changing <fs_kunnr> . endif . *----------------------------------------------------------------------------------------------------------- clear: lv_dmbtr_s , lv_dmbtr_h . loop at lt_wqyus where bukrs = <fs_kunnr>-bukrs and kunnr = <fs_kunnr>-kunnr and shkzg = 'S' . lv_dmbtr_s = lv_dmbtr_s + lt_wqyus-dmbtr . append lt_wqyus to <fs_kunnr>-t_wqyus_s[] . endloop . loop at lt_wqyus where bukrs = <fs_kunnr>-bukrs and kunnr = <fs_kunnr>-kunnr and shkzg = 'H' . if lv_dmbtr_h < lv_dmbtr_s . lv_dmbtr_h = lv_dmbtr_h + lt_wqyus-dmbtr . append lt_wqyus to <fs_kunnr>-t_wqyus_h[] . else . exit . endif . endloop . if <fs_kunnr>-t_wqyus_h[] is not initial and <fs_kunnr>-t_wqyus_s[] is not initial . perform fm_posting_interface_clearing tables <fs_kunnr>-t_wqyus_s[] <fs_kunnr>-t_wqyus_h[] using lv_dmbtr_s lv_dmbtr_h s_budat-low 'YUSDQ' changing <fs_kunnr> . endif . select *"bukrs kunnr hkont budat shkzg dmbtr into corresponding fields of table <fs_kunnr>-t_wqyis[] from bsid where bukrs = <fs_kunnr>-bukrs and kunnr = <fs_kunnr>-kunnr and hkont in ('1122001000' , '1122002000') and budat <= s_augdt-low order by bukrs kunnr shkzg zfbdt . "未清预收 select * " bukrs kunnr hkont budat shkzg dmbtr into corresponding fields of table <fs_kunnr>-t_wqyus from bsid where bukrs = <fs_kunnr>-bukrs and kunnr = <fs_kunnr>-kunnr and umskz = 'A' and budat <= s_augdt-low order by bukrs kunnr shkzg zfbdt . clear: lv_dmbtr_s , lv_dmbtr_h . loop at <fs_kunnr>-t_wqyis[] into ls_wqyis . lv_dmbtr_s = lv_dmbtr_s + ls_wqyis-dmbtr . endloop . loop at <fs_kunnr>-t_wqyus[] into ls_wqyus . lv_dmbtr_h = lv_dmbtr_h + ls_wqyus-dmbtr . endloop . if lv_dmbtr_s >= lv_dmbtr_h . "应收比预收多 loop at <fs_kunnr>-t_wqyis[] into ls_wqyis . if lv_dmbtr_h > 0. lv_dmbtr_h = lv_dmbtr_h - ls_wqyis-dmbtr . else . clear ls_wqyis-belnr . modify <fs_kunnr>-t_wqyis[] from ls_wqyis . endif. endloop . delete <fs_kunnr>-t_wqyis[] where belnr is initial . elseif lv_dmbtr_s < lv_dmbtr_h . "预收比应收多 loop at <fs_kunnr>-t_wqyus[] into ls_wqyus . if lv_dmbtr_s > 0 . lv_dmbtr_s = lv_dmbtr_s - ls_wqyus-dmbtr . else . clear ls_wqyus-belnr . modify <fs_kunnr>-t_wqyus[] from ls_wqyus . endif. endloop. delete <fs_kunnr>-t_wqyus[] where belnr is initial . endif . clear: lv_dmbtr_s , lv_dmbtr_h . loop at <fs_kunnr>-t_wqyis[] into ls_wqyis . lv_dmbtr_s = lv_dmbtr_s + ls_wqyis-dmbtr . endloop . loop at <fs_kunnr>-t_wqyus[] into ls_wqyus . lv_dmbtr_h = lv_dmbtr_h + ls_wqyus-dmbtr . endloop . perform fm_posting_interface_clearing tables <fs_kunnr>-t_wqyis[] <fs_kunnr>-t_wqyus[] using lv_dmbtr_s lv_dmbtr_h s_budat-low 'MSG' changing <fs_kunnr> . endloop . endform . "FM_GET_YIS_YUS_DATA *----------------------------------------------------------------------* form fm_posting_interface_clearing tables lt_yi like lt_wqyis[] lt_yu like lt_wqyis[] using lv_yi lv_yu lv_budat lv_type changing ls_kunnr like lt_kunnr . data: lt_blntab type table of blntab , ls_blntab type blntab , lt_ftclear type table of ftclear , ls_ftclear type ftclear , lt_ftpost type table of ftpost , ls_ftpost type ftpost , lt_fttax type table of fttax with header line . field-symbols <fs> type any . assign component lv_type of structure <fs_out> to <fs> . * clear: ls_blntab, lt_blntab, ls_ftclear, lt_ftclear, ls_ftpost, lt_ftpost, lt_fttax, lt_fttax[] .", lv_yis, lv_yus, lv_zfbdt . call function 'POSTING_INTERFACE_START' exporting i_client = sy-mandt i_function = 'C' i_keep = 'X' i_mode = 'N' "A OR N 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. endif . populate_ftpost: 'K' 1 'BKPF-BLDAT' lv_budat , "凭证日期 'K' 1 'BKPF-BLART' 'AB' , "凭证类型 'K' 1 'BKPF-BUKRS' s_bukrs-low , "公司代码 'K' 1 'BKPF-BUDAT' lv_budat , "过账日期 'K' 1 'BKPF-WAERS' 'RMB' , "货币 'K' 1 'BKPF-BKTXT' '清账' . "抬头文本 loop at lt_yi . ls_ftclear-agkoa = 'D' . ls_ftclear-xnops = 'X' . ls_ftclear-agbuk = lt_yi-bukrs . ls_ftclear-agkon = lt_yi-kunnr . ls_ftclear-agums = 'A' . ls_ftclear-selvon = lt_yi-belnr . "Belegnummer ls_ftclear-selvon+10 = lt_yi-gjahr."Gesch#ftsjahr ls_ftclear-selvon+14 = lt_yi-buzei."Buchungszeichen ls_ftclear-selfd = 'BELNR'. "Selectionstext für Funktion ls_ftclear-selbis = lt_yi-belnr . append ls_ftclear to lt_ftclear . endloop. * * loop at lt_yu . ls_ftclear-agkoa = 'D' . ls_ftclear-xnops = 'X' . ls_ftclear-agbuk = lt_yu-bukrs . ls_ftclear-agkon = lt_yu-kunnr . ls_ftclear-agums = 'A' . ls_ftclear-selvon = lt_yu-belnr . "Belegnummer ls_ftclear-selvon+10 = lt_yu-gjahr."Gesch#ftsjahr ls_ftclear-selvon+14 = lt_yu-buzei."Buchungszeichen ls_ftclear-selfd = 'BELNR'. "Selectionstext für Funktion ls_ftclear-selbis = lt_yu-belnr . append ls_ftclear to lt_ftclear . endloop . data: lv_abs_yiyu type dmbtr . lv_abs_yiyu = abs( lv_yi - lv_yu ) . if lv_type = 'YISDQ'. populate_ftpost: 'P' 1 'BSEG-WRBTR' lv_abs_yiyu , " . 'P' 1 'BSEG-HKONT' ls_kunnr-kunnr , 'P' 1 'RF05A-NEWBS' '07' , 'P' 1 'RF05A-NEWUM' '' , 'P' 1 'BSEG-ZFBDT' lt_yu-zfbdt , 'P' 1 'BSEG-SGTXT' '清账余额' ," 'P' 1 'BSEG-XNEGP' 'X' . elseif lv_type = 'YUSDQ' . populate_ftpost: 'P' 1 'BSEG-WRBTR' lv_abs_yiyu , " . 'P' 1 'BSEG-HKONT' ls_kunnr-kunnr , 'P' 1 'RF05A-NEWBS' '19' , 'P' 1 'RF05A-NEWUM' 'A' , 'P' 1 'BSEG-ZFBDT' lt_yu-zfbdt ," 'P' 1 'BSEG-SGTXT' '清账余额' ." elseif lv_type = 'MSG' . if lv_yi > lv_yu . populate_ftpost: 'P' 1 'BSEG-WRBTR' lv_abs_yiyu , " . 'P' 1 'BSEG-HKONT' ls_kunnr-kunnr , 'P' 1 'RF05A-NEWBS' '07' , 'P' 1 'RF05A-NEWUM' '' , 'P' 1 'BSEG-ZFBDT' lt_yi-zfbdt , 'P' 1 'BSEG-SGTXT' '清账余额' ," 'P' 1 'BSEG-XNEGP' 'X' . elseif lv_yi < lv_yu . * lt_kunnr-yus = abs( lt_kunnr-yus ) . populate_ftpost: 'P' 1 'BSEG-WRBTR' lv_abs_yiyu , "凭证日期 . 'P' 1 'BSEG-HKONT' ls_kunnr-kunnr , 'P' 1 'RF05A-NEWBS' '19' , 'P' 1 'RF05A-NEWUM' 'A' , 'P' 1 'BSEG-ZFBDT' lt_yu-zfbdt ," 'P' 1 'BSEG-SGTXT' '清账余额' ." endif. endif. call function 'POSTING_INTERFACE_CLEARING' exporting i_auglv = 'UMBUCHNG' "转账并清账 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 = lt_blntab t_ftclear = lt_ftclear t_ftpost = lt_ftpost t_fttax = lt_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-subrc = 0 and sy-msgty <> 'E' and lv_type = 'X'. read table lt_blntab into ls_blntab index 1. <fs_out>-bukrs = lt_kunnr-bukrs . <fs_out>-kunnr = lt_kunnr-kunnr . <fs_out>-gjahr = ls_blntab-gjahr . <fs_out>-belnr = ls_blntab-belnr . <fs> = 'S' . else . * rollback work. data lv_errmsg type char50 . call function 'MESSAGE_TEXT_BUILD' exporting msgid = sy-msgid msgnr = sy-msgno msgv1 = sy-msgv1 msgv2 = sy-msgv2 msgv3 = sy-msgv3 msgv4 = sy-msgv4 importing message_text_output = lv_errmsg. <fs_out>-bukrs = ls_kunnr-bukrs . <fs_out>-kunnr = ls_kunnr-kunnr . <fs> = lv_errmsg . * <fs_out>-msg = lv_errmsg . endif . call function 'POSTING_INTERFACE_END' exceptions session_not_processable = 1 others = 2. commit work and wait. endform . "fm_POSTING_INTERFACE_CLEARING *&---------------------------------------------------------------------* *& Form fm_alv_display *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* form fm_alv_display . data: begin of ls_field_config , fieldname type lvc_s_fcat-fieldname, scrtext_l type lvc_s_fcat-scrtext_l, end of ls_field_config , lt_field_config like table of ls_field_config . define add_field_config . ls_field_config-fieldname = &1 . ls_field_config-scrtext_l = &2 . append ls_field_config to lt_field_config . clear ls_field_config . end-of-definition . " alv 函数用 data:lt_fieldcat type lvc_t_fcat, ls_layout type lvc_s_layo, ls_variant type disvariant. field-symbols <ls_fieldcat> like line of lt_fieldcat. "自动获取fieldcat用 data:lo_structdescr type ref to cl_abap_structdescr. data:lt_ddfields type ddfields. data:ls_ddfields type dfies. add_field_config 'BUKRS' '公司代码'. add_field_config 'KUNNR' '客户号码'. add_field_config 'GJAHR' '会计年度'. * add_field_config 'BELNR' '凭证编号'. if p_qz = 'X' . add_field_config 'YISDQ' '应收对清'. add_field_config 'YUSDQ' '预收对清'. endif. add_field_config 'MSG' '应收清预收'. * add_field_config '' ''. lo_structdescr ?= cl_abap_structdescr=>describe_by_data( gs_out ). lt_ddfields = zcl_salv_data_descr=>read_structdescr( lo_structdescr ). loop at lt_ddfields into ls_ddfields . append initial line to lt_fieldcat assigning <ls_fieldcat> . move-corresponding ls_ddfields to <ls_fieldcat>. <ls_fieldcat>-no_zero = 'X' . read table lt_field_config into ls_field_config with key fieldname = <ls_fieldcat>-fieldname . if sy-subrc = 0 . <ls_fieldcat>-coltext = ls_field_config-scrtext_l. else . clear <ls_fieldcat>-fieldname . endif. endloop. delete lt_fieldcat where fieldname is initial . *设置布局 ls_layout-zebra = 'X' . ls_layout-cwidth_opt = 'X'. ls_layout-box_fname = 'SEL'. * ls_layout-info_fname = 'COLOR' . ls_variant-report = sy-repid. ls_variant-handle = '0001'. *ALV显示 call function 'REUSE_ALV_GRID_DISPLAY_LVC' exporting i_callback_program = sy-repid * i_callback_pf_status_set = 'FM_PF_STATUS_SET' i_callback_user_command = 'FM_USER_COMMAND' i_default = 'X' i_save = 'A' is_layout_lvc = ls_layout is_variant = ls_variant it_fieldcat_lvc = lt_fieldcat * i_grid_title = lv_title tables t_outtab = gt_out[] exceptions program_error = 1 others = 2. endform . "fm_alv_display *&---------------------------------------------------------------------* * text 关户退款 *----------------------------------------------------------------------* form fm_customer_clear . select distinct bukrs kunnr into corresponding fields of table gt_out from bsid where bukrs in s_bukrs and kunnr in s_kunnr . data: ls_input type zifs_fis006_input , ls_output type zifs_fis006_output , ls_return type bapiret2 . loop at gt_out assigning <fs_out> . clear: ls_input , ls_output , ls_return . <fs_out>-gjahr = s_budat-low+0(4) . ls_input-bukrs = <fs_out>-bukrs . ls_input-kunnr = <fs_out>-kunnr . ls_input-augdt = s_budat-low . call function 'ZCL_IFS_FI006_CUST_CLEAR' exporting input = ls_input importing output = ls_output. if sy-subrc = 0 . <fs_out>-belnr = ls_output-belnr . read table ls_output-t_return into ls_return index 1 . <fs_out>-msg = ls_return-message . endif. endloop. endform . "fm_customer_CLEAR
标签:wqyis,清账,程序,dmbtr,lv,lt,ls,FICO,kunnr From: https://www.cnblogs.com/Anyohh233/p/17980142