二维码

部分支付全部清账时,未将清账凭证置为已清账

Twilight发表于 2020-04-15 16:14Twilight 最后回复于 2020-04-15 16:14 [复制链接] 5891 0

当部分支付全部清账时,未将清账凭证置为已清账,数据筛查脚本。

清账凭证.jpg

脚本:
  1. SELECT  BUKRS,
  2.         KUNNR,
  3.         UMSKS,
  4.         UMSKZ,
  5.         AUGDT,
  6.         AUGBL,
  7.         ZUONR,
  8.         GJAHR,
  9.         BELNR,
  10.         BUZEI,
  11.         BLART,
  12.         DMBTR,
  13.         REBZG,
  14.         REBZJ,
  15.         REBZZ
  16. FROM BSID
  17. WHERE BLART IN ('RV','SA','AB')
  18. INTO TABLE @DATA(lt_BSID).

  19. DATA:BEGIN OF lt_rv OCCURS 0,
  20.   BUKRS TYPE BSID-BUKRS,
  21.   GJAHR TYPE BSID-GJAHR,
  22.   BELNR TYPE BSID-BELNR,
  23.   BUZEI TYPE BSID-BUZEI,
  24.   DMBTR TYPE BSID-DMBTR,
  25. END OF lt_rv.
  26. DATA:BEGIN OF lt_ab OCCURS 0,
  27.   BUKRS TYPE BSID-BUKRS,
  28.   GJAHR TYPE BSID-GJAHR,
  29.   BELNR TYPE BSID-BELNR,
  30.   BUZEI TYPE BSID-BUZEI,
  31.   DMBTR TYPE BSID-DMBTR,
  32. END OF lt_ab.
  33. DATA:lv_index TYPE I.
  34. DATA:lt_rv_e LIKE TABLE OF lt_rv.

  35. LOOP AT lt_BSID ASSIGNING FIELD-SYMBOL(<fs_bsid>).
  36.   IF <fs_bsid>-BLART = 'RV' OR <fs_bsid>-BLART = 'SA'.
  37.     CLEAR:lt_rv.
  38.     lt_rv-BUKRS = <fs_bsid>-BUKRS.
  39.     lt_rv-GJAHR = <fs_bsid>-GJAHR.
  40.     lt_rv-BELNR = <fs_bsid>-BELNR.
  41.     lt_rv-BUZEI = <fs_bsid>-BUZEI.
  42.     lt_rv-DMBTR = <fs_bsid>-DMBTR.
  43.     APPEND lt_rv.
  44.   ELSE.
  45.     CLEAR:lt_ab.
  46.     lt_ab-BUKRS = <fs_bsid>-BUKRS.
  47.     lt_ab-GJAHR = <fs_bsid>-REBZJ.
  48.     lt_ab-BELNR = <fs_bsid>-REBZG.
  49.     lt_ab-BUZEI = <fs_bsid>-REBZZ.
  50.     lt_ab-DMBTR = <fs_bsid>-DMBTR.
  51.     COLLECT lt_ab.
  52.   ENDIF.
  53. ENDLOOP.


  54. SORT lt_ab BY BUKRS GJAHR BELNR BUZEI DMBTR.
  55. LOOP AT lt_rv.
  56.   READ TABLE lt_ab WITH KEY BUKRS = lt_rv-BUKRS GJAHR = lt_rv-GJAHR BELNR = lt_rv-BELNR BUZEI = lt_rv-BUZEI DMBTR = lt_rv-DMBTR BINARY SEARCH.
  57.   IF sy-subrc = 0.
  58.     APPEND lt_rv TO lt_rv_e. "收款/应收凭证 部分全部清账时,未置为已清状态数据
  59.   ENDIF.
  60. ENDLOOP.

  61. DELETE lt_BSID[] WHERE REBZG IS INITIAL.

  62. SORT lt_rv_e BY BUKRS GJAHR BELNR BUZEI.
  63. LOOP AT lt_BSID ASSIGNING <fs_BSID>.
  64.   lv_index = sy-tabix.
  65.   READ TABLE lt_rv_e TRANSPORTING NO FIELDS WITH KEY BUKRS = <fs_BSID>-BUKRS GJAHR = <fs_BSID>-REBZJ BELNR = <fs_BSID>-REBZG BUZEI = <fs_BSID>-REBZZ BINARY SEARCH.
  66.   IF sy-subrc NE 0.
  67.     DELETE lt_BSID INDEX lv_index.
  68.   ENDIF.
  69. ENDLOOP.

  70. SORT lt_BSID BY BUKRS ASCENDING REBZJ ASCENDING REBZG ASCENDING REBZZ ASCENDING GJAHR DESCENDING BELNR DESCENDING BUZEI DESCENDING.
  71. DELETE ADJACENT DUPLICATES FROM lt_BSID COMPARING BUKRS REBZJ REBZG REBZZ.  "剩下的最大好的清账凭证,是最后一次清账凭证,有问题的数据

  72. DATA:BEGIN OF lt_out OCCURS 0,
  73.   BUKRS TYPE BSID-BUKRS,
  74.   KUNNR TYPE BSID-KUNNR,
  75.   UMSKS TYPE BSID-UMSKS,
  76.   UMSKZ TYPE BSID-UMSKZ,
  77.   AUGDT TYPE BSID-AUGDT,
  78.   AUGBL TYPE BSID-AUGBL,
  79.   ZUONR TYPE BSID-ZUONR,
  80.   GJAHR TYPE BSID-GJAHR,
  81.   BELNR TYPE BSID-BELNR,
  82.   BUZEI TYPE BSID-BUZEI,
  83.   BLART TYPE BSID-BLART,
  84.   DMBTR TYPE BSID-DMBTR,
  85.   REBZG TYPE BSID-REBZG,
  86.   REBZJ TYPE BSID-REBZJ,
  87.   REBZZ TYPE BSID-REBZZ,
  88.   USNAM TYPE BKPF-USNAM,
  89. END OF lt_out.

  90. LOOP AT lt_BSID ASSIGNING <fs_BSID>.
  91.   CLEAR:lt_out.
  92.   MOVE-CORRESPONDING <fs_BSID> TO lt_out.
  93.   SELECT SINGLE USNAM INTO lt_out-USNAM FROM BKPF WHERE BUKRS = <fs_BSID>-BUKRS AND BELNR = <fs_BSID>-BELNR AND GJAHR = <fs_BSID>-GJAHR.
  94.   APPEND lt_out.
  95. ENDLOOP.

  96. WRITE:'end'.
复制代码
lt_out 最后一次清账凭证,需要冲销,修复账号参数,然后重新清账。
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表