BADI增强 ac_document 用行项目中某行的利润中心去替代另外一行

  METHOD IF_EX_AC_DOCUMENT~CHANGE_INITIAL.
  DATA:IT_ACCIT TYPE ACCIT_T.
  DATA:WA_ACCIT TYPE ACCIT.
  DATA:L_ACCIT TYPE ACCIT.
  DATA:IT_SUB_T TYPE ACCIT_SUB_T.
  DATA:WA_ACCIT_SUB TYPE ACCIT_SUB.
  IT_ACCIT = IM_DOCUMENT-ITEM[].
  LOOP AT IT_ACCIT INTO WA_ACCIT.                                                                     "获取客户的统驭科目
    IF WA_ACCIT-HKONT IS INITIAL AND  WA_ACCIT-KUNNR IS NOT INITIAL.
      SELECT SINGLE AKONT INTO WA_ACCIT-HKONT
        FROM  KNB1
        WHERE KUNNR = WA_ACCIT-KUNNR
         AND BUKRS = WA_ACCIT-BUKRS.
      MODIFY IT_ACCIT  FROM WA_ACCIT.
    ENDIF.
  ENDLOOP.
  IF IM_DOCUMENT-HEADER-TCODE = 'VF01'
    OR IM_DOCUMENT-HEADER-TCODE = 'VF04'.                                                            "判断TCODE是否等于VF01 或 VF04
    LOOP AT IT_ACCIT INTO WA_ACCIT
      WHERE HKONT BETWEEN 0112200000 AND  0112299999
      AND PRCTR = ''.                                                                               "行项目中是否存在1122开头的科目号并且利润中心不为空的行项目
    ENDLOOP.
    IF WA_ACCIT IS NOT INITIAL.
      CLEAR WA_ACCIT.
      LOOP AT IT_ACCIT INTO WA_ACCIT
        WHERE ( HKONT BETWEEN 0600100000 AND  0600199999  OR HKONT BETWEEN 0605100000 AND  0605199999 )
        AND PRCTR <> ''.                                                                            "行项目中是否存在6001或6051开头的科目号并且利润中心不为空的行项目
      ENDLOOP.
      IF WA_ACCIT IS NOT INITIAL.
        CLEAR WA_ACCIT.
        LOOP AT IT_ACCIT INTO WA_ACCIT.
          IF WA_ACCIT-HKONT+0(5) = '01122'.
            LOOP AT IT_ACCIT INTO L_ACCIT
              WHERE ( HKONT BETWEEN 0600100000 AND  0600199999  OR HKONT BETWEEN 0605100000 AND  0605199999 ).
              IF L_ACCIT IS NOT INITIAL.
                EXIT.
              ENDIF.
            ENDLOOP.
            CLEAR WA_ACCIT-HKONT.
            WA_ACCIT-PRCTR = L_ACCIT-PRCTR.
            MOVE-CORRESPONDING WA_ACCIT TO WA_ACCIT_SUB.
            APPEND WA_ACCIT_SUB TO IT_SUB_T.
          ELSE.
            APPEND WA_ACCIT_SUB TO IT_SUB_T.
          ENDIF.
          CLEAR WA_ACCIT_SUB.
          CLEAR WA_ACCIT.
          CLEAR L_ACCIT.
        ENDLOOP.
        EX_DOCUMENT-ITEM[] = IT_SUB_T[].                                                           "输入行项目替代输出行项目
        EX_DOCUMENT-HEADER = IM_DOCUMENT-HEADER.                                                   "输入的抬头替代输出的
      ENDIF.
    ENDIF.
  ENDIF.
ENDMETHOD.

你可能感兴趣的:(SAP,ABAP)