SAP 凭证项目文本 增强 demo2

SAP 凭证项目文本 增强 demo2
增强点 AC_DOCUMENT
METHOD if_ex_ac_document~change_initial.
DATA: ls_item TYPE accit,
ls_exitem TYPE accit_sub,
lv_sgtxt TYPE bseg-sgtxt,
lv_bktxt TYPE bkpf-bktxt,
lv_zuonr TYPE bseg-zuonr,
lv_blart TYPE bkpf-blart,
lv_zprono TYPE vbap-zprono,
lv_kunnr TYPE bseg-kunnr,
lv_name TYPE but000-bu_sort1,
lv_lifnr TYPE char6,
lv_ebeln TYPE char12,
lv_aubel TYPE bseg-vbeln.

CLEAR:ls_item,lv_sgtxt,lv_bktxt,lv_blart,lv_kunnr,lv_zuonr.
lv_bktxt = im_document-header-bktxt.
LOOP AT im_document-item INTO ls_item.
  lv_blart = ls_item-blart.
  IF lv_blart = 'Z6'.
    IF im_document-header-bktxt IS INITIAL.
      lv_zuonr = ls_item-zuonr.
    ENDIF.
  ENDIF.
  MOVE-CORRESPONDING ls_item TO ls_exitem.
  IF im_document-header-tcode = 'MIR7' OR im_document-header-tcode = 'MIRO' OR im_document-header-tcode = 'MR8M'.
    IF ls_item-sgtxt IS NOT INITIAL.
      lv_sgtxt = ls_item-sgtxt.
    ELSE.
      SELECT SINGLE vbund INTO lv_lifnr FROM bp001 WHERE  partner = ls_item-lifnr .
      IF lv_lifnr IS NOT INITIAL AND lv_sgtxt IS  INITIAL.
        CLEAR:lv_ebeln,lv_name.
        SELECT SINGLE bu_sort1 INTO lv_name FROM but000 WHERE partner =  ls_item-lifnr.
        READ TABLE im_document-item INTO DATA(ls_item2) WITH KEY ktosl = 'WRX' .
        IF sy-subrc = 0 .
          lv_ebeln = ls_item2-ebeln.
        ENDIF.
        CONCATENATE lv_name lv_ebeln INTO lv_sgtxt SEPARATED BY ''.
        lv_bktxt = lv_sgtxt.
      ENDIF.
      ls_exitem-sgtxt = lv_sgtxt.
    ENDIF.
  ELSEIF im_document-header-tcode = 'VF02' OR im_document-header-tcode = 'VF01' OR im_document-header-tcode = 'VFX3' OR im_document-header-tcode = 'VF04'.
    IF ls_item-kunnr IS NOT INITIAL.
      lv_kunnr = ls_item-kunnr.
    ENDIF.
    IF lv_kunnr IS INITIAL.
      lv_kunnr = ls_item-kunag.
    ENDIF.
    IF ls_item-sgtxt IS INITIAL.
      CLEAR:lv_zprono,lv_name,lv_aubel.

      IF ls_item-vbel2 IS NOT INITIAL.
        SELECT SINGLE zprono INTO lv_zprono FROM vbap WHERE vbeln = ls_item-vbel2 AND posnr = ls_item-posn2.
        SELECT SINGLE bu_sort1 INTO lv_name FROM but000 WHERE partner =  lv_kunnr.
        CONCATENATE lv_name lv_zprono ls_item-vbel2 '确认收入' INTO ls_exitem-sgtxt SEPARATED BY ''.

      ELSEIF ls_item-aubel IS NOT INITIAL.
        SELECT SINGLE zprono INTO lv_zprono FROM vbap WHERE vbeln = ls_item-aubel AND posnr = ls_item-aupos.
        SELECT SINGLE bu_sort1 INTO lv_name FROM but000 WHERE partner =  lv_kunnr.
        CONCATENATE lv_name lv_zprono ls_item-aubel '确认收入' INTO ls_exitem-sgtxt SEPARATED BY ''.
      ELSE.
        lv_aubel = ls_item-ebeln.
        SELECT SINGLE bu_sort1 INTO lv_name FROM but000 WHERE partner =  lv_kunnr.
        CONCATENATE lv_name lv_zprono lv_aubel '确认收入' INTO ls_exitem-sgtxt SEPARATED BY ''.
      ENDIF.
    ELSE.
      ls_exitem-sgtxt =  ls_item-sgtxt.
    ENDIF.
  ELSEIF im_document-header-tcode = 'VL02N' OR im_document-header-tcode = 'VL09'.
    IF ls_item-sgtxt IS INITIAL.
      CLEAR:lv_zprono,lv_name.
      IF ls_item-vbel2 IS NOT INITIAL.
        SELECT SINGLE zprono INTO lv_zprono FROM vbap WHERE vbeln = ls_item-vbel2 AND posnr = ls_item-posn2.
        SELECT SINGLE bu_sort1 INTO lv_name FROM but000 WHERE partner =  ls_item-kunnr.
  •        CONCATENATE lv_name lv_zprono ls_item-vbel2 '结转成本' INTO ls_exitem-sgtxt SEPARATED BY ''.
          SELECT SINGLE auart INTO @DATA(lv_auart) FROM vbak WHERE vbeln EQ @ls_item-vbel2.
          IF sy-subrc = 0.
            IF lv_auart = 'ZRE2' OR lv_auart = 'ZCCR'.
              IF im_document-header-tcode = 'VL02N'.
                CONCATENATE lv_name lv_zprono ls_item-vbel2 '退货冲销成本' INTO ls_exitem-sgtxt SEPARATED BY ''.
              ELSE.
                CONCATENATE lv_name lv_zprono ls_item-vbel2 '退货冲销成本-冲销' INTO ls_exitem-sgtxt SEPARATED BY ''.
              ENDIF.
            ELSEIF lv_auart = 'ZFP'.
              IF im_document-header-tcode = 'VL02N'.
                CONCATENATE lv_name lv_zprono ls_item-vbel2 '结转费用' INTO ls_exitem-sgtxt SEPARATED BY ''.
              ELSE.
                CONCATENATE lv_name lv_zprono ls_item-vbel2 '结转费用-冲销' INTO ls_exitem-sgtxt SEPARATED BY ''.
              ENDIF.
            ELSE.
              IF im_document-header-tcode = 'VL02N'.
                CONCATENATE lv_name lv_zprono ls_item-vbel2 '结转成本' INTO ls_exitem-sgtxt SEPARATED BY ''.
              ELSE.
                CONCATENATE lv_name lv_zprono ls_item-vbel2 '结转成本-冲销' INTO ls_exitem-sgtxt SEPARATED BY ''.
              ENDIF.
            ENDIF.
          ELSE.
            IF im_document-header-tcode = 'VL02N'.
              CONCATENATE lv_name lv_zprono ls_item-vbel2 '结转成本' INTO ls_exitem-sgtxt SEPARATED BY ''.
            ELSE.
              CONCATENATE lv_name lv_zprono ls_item-vbel2 '结转成本-冲销' INTO ls_exitem-sgtxt SEPARATED BY ''.
            ENDIF.
          ENDIF.
        ENDIF.
      ELSE.
        ls_exitem-sgtxt =  ls_item-sgtxt.
      ENDIF.
    ENDIF.
    "  暂估科目 不带成本中心和订单
    IF ls_item-hkont = '2202010300'.
      ls_exitem-kostl = ''.
      ls_exitem-aufnr = '' .
    ENDIF.
    APPEND ls_exitem TO ex_document-item.
    
    ENDLOOP.
    IF lv_blart = ‘Z6’ AND ( im_document-header-tcode = ‘KO88’ OR im_document-header-tcode = ‘KO8G’ ). " 拆解工单抬头文本
    CONCATENATE ‘结算’ lv_zuonr ‘拆解费用’ INTO lv_bktxt.
    ex_document-header-bktxt = lv_bktxt.
    ELSEIF im_document-header-tcode = ‘VF02’ OR im_document-header-tcode = ‘VF01’ OR im_document-header-tcode = ‘VFX3’.
    IF im_document-header-bktxt IS INITIAL.
    ex_document-header-bktxt = ls_exitem-sgtxt.
    ENDIF.
    ELSEIF im_document-header-tcode = ‘VL02N’ OR im_document-header-tcode = ‘VL09’.
    ex_document-header-bktxt = ls_exitem-sgtxt.
    ELSE.
    ex_document-header-bktxt = lv_bktxt.
    ENDIF.
    ENDMETHOD.

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