预付款批量清账程序,也是来自于网上,稍微改了一下。依据付款参考清账。
原文参考:【ABAP】供应商、客户的特殊总账和非特殊总账清账_sap f-44 bapi-CSDN博客
&---------------------------------------------------------------------*
*& Report ZC_CLEAR1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZC_CLEAR1.TABLES:bseg,t100.DATA:BEGIN OF lt_bseg OCCURS 0,contract(30),"FAFW合同号
* kunnr LIKE bseg-kunnr,lifnr LIKE bseg-lifnr,bukrs LIKE bseg-bukrs,belnr LIKE bseg-belnr,gjahr LIKE bseg-gjahr,buzei LIKE bseg-buzei,bschl LIKE bseg-bschl,koart LIKE bseg-koart,umskz LIKE bseg-umskz,shkzg LIKE bseg-shkzg,mwskz LIKE bseg-mwskz,wrbtr LIKE bseg-wrbtr,zuonr LIKE bseg-zuonr,sgtxt LIKE bseg-sgtxt,kidno LIKE bseg-KIDNO,bewar LIKE bseg-bewar, "事务类型del,"删除标记
* sign,"清账标记END OF lt_bseg.DATA:BEGIN OF lt_bsegx OCCURS 0,lifnr LIKE bseg-lifnr,kidno LIKE bseg-KIDNO,contract(30),"FAFW合同号wrbtr LIKE bseg-wrbtr,END OF lt_bsegx.DATA:lt_clear LIKE TABLE OF lt_bseg WITH HEADER LINE.FIELD-SYMBOLS:<f_bseg> LIKE lt_bseg.
DATA:delflag,start TYPE i.DATA:t_bdc LIKE TABLE OF bdcdata WITH HEADER LINE,mess LIKE STANDARD TABLE OF bdcmsgcoll INITIAL SIZE 0 WITH HEADER LINE.DATA:lflag VALUE 0,lv_lifnr LIKE bseg-lifnr,lv_contract(30).DATA:message(300).
DATA: l_mstring(480).SELECTION-SCREEN BEGIN OF BLOCK bl00 WITH FRAME.
PARAMETERS: p_bukrs LIKE bseg-bukrs OBLIGATORY DEFAULT '1000'.
PARAMETERS: p_gjahr LIKE bseg-gjahr OBLIGATORY DEFAULT sy-datum+0(4).
PARAMETERS: p_monat LIKE bkpf-monat OBLIGATORY DEFAULT sy-datum+4(2).
PARAMETERS: p_augdt LIKE bsik-augdt OBLIGATORY DEFAULT sy-datum.
SELECT-OPTIONS:s_lifnr FOR bseg-lifnr.
PARAMETERS: p_umskz LIKE bseg-umskz.
PARAMETERS: p_fafw AS CHECKBOX DEFAULT 'X'.
PARAMETERS: p_mode DEFAULT 'N'.
SELECTION-SCREEN END OF BLOCK bl00.START-OF-SELECTION.IF s_lifnr IS INITIAL.MESSAGE '请输入供应商号!' TYPE 'I'.ELSE.PERFORM selectdata.IF p_fafw = 'X'.PERFORM contractmode.ENDIF.PERFORM clear.ENDIF.*&---------------------------------------------------------------------*
*& Form selectdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM selectdata.
* 查询数据IF p_umskz IS NOT INITIAL.SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_bseg FROM bsikWHERE bukrs = p_bukrsAND lifnr IN s_lifnrAND umskz IN ('',p_umskz).ELSE.SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_bseg FROM bsikWHERE bukrs = p_bukrsAND lifnr IN s_lifnrAND umskz = ''.ENDIF.ENDFORM. "selectdata*&---------------------------------------------------------------------*
*& Form subdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM contractmode.* 提取合同号delflag = 0.LOOP AT lt_bseg ASSIGNING <f_bseg>.
* IF <f_bseg>-sgtxt CS 'FA' OR <f_bseg>-sgtxt CS 'FW'.
* SEARCH <f_bseg>-sgtxt FOR 'FA'.
* IF sy-subrc = 0.
* start = sy-fdpos.
* <f_bseg>-contract = <f_bseg>-sgtxt+start(10).
* ELSE.
* SEARCH <f_bseg>-sgtxt FOR 'FW'.
* start = sy-fdpos.
* <f_bseg>-contract = <f_bseg>-sgtxt+start(10).
* ENDIF.
* ELSE.
* <f_bseg>-del = 'X'.
* IF delflag = 0.
* delflag = 1.
* ENDIF.
* ENDIF.IF <f_bseg>-kidno IS NOT INITIAL.<f_bseg>-contract = <f_bseg>-kidno.ELSE.<f_bseg>-del = 'X'.IF delflag = 0.delflag = 1.ENDIF.ENDIF.IF <f_bseg>-shkzg = 'H'.<f_bseg>-wrbtr = <f_bseg>-wrbtr * -1.ELSE.<f_bseg>-wrbtr = <f_bseg>-wrbtr.ENDIF.ENDLOOP.IF delflag = 1.SORT lt_bseg BY del.DELETE lt_bseg WHERE del = 'X'.ENDIF.IF lt_bseg[] IS INITIAL.MESSAGE '没有要清账的项目!' TYPE 'E'.ENDIF.* 查找要清账的合同SORT lt_bseg BY lifnr contract.SORT lt_bseg BY lifnr kidno.LOOP AT lt_bseg.lt_bsegx-lifnr = lt_bseg-lifnr.lt_bsegx-wrbtr = lt_bseg-wrbtr.lt_bsegx-contract = lt_bseg-contract.lt_bsegx-kidno = lt_bseg-kidno.COLLECT lt_bsegx.ENDLOOP.SORT lt_bsegx BY wrbtr DESCENDING.DELETE lt_bsegx WHERE wrbtr NE 0.RANGES:lr_contract FOR lt_bseg-contract.SORT lt_bsegx BY lifnr contract.LOOP AT lt_bsegx.lr_contract-low = lt_bsegx-contract.lr_contract-sign = 'I'.lr_contract-option = 'EQ'.APPEND lr_contract.ENDLOOP.IF lr_contract[] IS INITIAL.MESSAGE '没有要清账的项目!' TYPE 'E'.ELSE.
* DELETE ADJACENT DUPLICATES FROM lr_contract.SORT lt_bseg BY contract.DELETE lt_bseg WHERE contract NOT IN lr_contract.ENDIF.SORT lt_bseg BY contract lifnr.ENDFORM. "subdata*&---------------------------------------------------------------------*
*& Form clear
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM clear.IF lt_bseg[] IS INITIAL.MESSAGE '没有要清账的项目!' TYPE 'E'.ENDIF.LOOP AT lt_bseg.CLEAR lt_clear.REFRESH lt_clear.CLEAR lv_lifnr.AT NEW contract.lflag = 1.ENDAT.IF lflag = 1.lv_lifnr = lt_bseg-lifnr.lv_contract = lt_bseg-contract.LOOP AT lt_bseg WHERE lifnr = lv_lifnr AND contract = lv_contract.MOVE lt_bseg TO lt_clear.APPEND lt_clear.ENDLOOP.PERFORM frmbdc.lflag = 0.ENDIF.ENDLOOP.ENDFORM. "clear*&---------------------------------------------------------------------*
*& Form frmbdc
*&---------------------------------------------------------------------*
* 录屏
*----------------------------------------------------------------------*
FORM frmbdc.CLEAR t_bdc.REFRESH t_bdc.DATA:fnam(15),num(2),i TYPE i.PERFORM fill_bdc_table USING '1' 'SAPMF05A' '0131'.PERFORM fill_bdc_table USING '' 'BDC_OKCODE' '=PA'.PERFORM fill_bdc_table USING '' 'RF05A-AGKON' lv_lifnr.PERFORM fill_bdc_table USING '' 'BKPF-BUDAT' p_augdt.PERFORM fill_bdc_table USING '' 'BKPF-MONAT' p_monat.PERFORM fill_bdc_table USING '' 'BKPF-BUKRS' p_bukrs.PERFORM fill_bdc_table USING '' 'BKPF-WAERS' 'CNY'.PERFORM fill_bdc_table USING '' 'RF05A-AGUMS' p_umskz.PERFORM fill_bdc_table USING '' 'RF05A-XNOPS' 'X'.PERFORM fill_bdc_table USING '' 'RF05A-XPOS1(03)' 'X'.PERFORM fill_bdc_table USING '1' 'SAPMF05A' '0731'.PERFORM fill_bdc_table USING '' 'BDC_OKCODE' '=BU'.LOOP AT lt_clear.num = sy-tabix.* 如果超过7,则先录OKCODE,再录新屏幕号IF i <= 28.CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'EXPORTINGinput = numIMPORTINGoutput = num.CONCATENATE 'RF05A-SEL01(' num ')' INTO fnam.PERFORM fill_bdc_table USING '' fnam lt_clear-belnr.ELSE.
* 翻页ENDIF.ENDLOOP.CALL TRANSACTION 'F-44' USING t_bdc MODE p_mode MESSAGES INTO mess.DATA:message(100).LOOP AT mess FROM 2.
*调试用SELECT SINGLE * FROM t100 WHERE sprsl = mess-msgspraAND arbgb = mess-msgidAND msgnr = mess-msgnr.IF sy-subrc = 0.l_mstring = t100-text.IF l_mstring CS '&1'.REPLACE '&1' WITH mess-msgv1 INTO l_mstring.REPLACE '&2' WITH mess-msgv2 INTO l_mstring.REPLACE '&3' WITH mess-msgv3 INTO l_mstring.REPLACE '&4' WITH mess-msgv4 INTO l_mstring.ELSE.REPLACE '&' WITH mess-msgv1 INTO l_mstring.REPLACE '&' WITH mess-msgv2 INTO l_mstring.REPLACE '&' WITH mess-msgv3 INTO l_mstring.REPLACE '&' WITH mess-msgv4 INTO l_mstring.ENDIF.CONDENSE l_mstring.ENDIF.IF mess-msgid = 'F5' AND mess-msgnr = '312'.EXIT.ELSE.CONCATENATE '供应商' lv_lifnr '付款参考' lv_contract '清账失败,请手工清账或联系IT中心!' INTO message.MESSAGE message TYPE 'E'.ENDIF.ENDLOOP.ENDFORM. "frmbdc*&---------------------------------------------------------------------*
*& Form fill_bdc_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->: text
* -->TMP_FLAG text
* -->TMP_VAR1 text
* -->TMP_VAR2 text
*----------------------------------------------------------------------*
FORM fill_bdc_table USING:tmp_flagtmp_var1tmp_var2.CLEAR t_bdc.IF tmp_flag = '1'.t_bdc-program = tmp_var1.t_bdc-dynpro = tmp_var2.t_bdc-dynbegin = 'X'.ELSE.t_bdc-fnam = tmp_var1.t_bdc-fval = tmp_var2.ENDIF.APPEND t_bdc.
ENDFORM. "fill_bdc_table