欢迎来到萧静默的博客

书山有路勤为径,学海无涯苦作舟。

资产明细查询表

自己做的

*&---------------------------------------------------------------------*
*& 程序ID:   ZFIRP006C
*& 程序名称: 固定资产明细表(含租赁情况)
*& 程序描述: 资产用户查询资产原值、折旧、净值及各个明细字段,便于资产管理。
*&---------------------------------------------------------------------*
*& 开发人员: Bruce King
*& 创建时间: 2019-08-21
*&---------------------------------------------------------------------*
*& 修改日期       版本      修改人     修改描述
*&                1.0
*&
*&---------------------------------------------------------------------*

REPORT ZFIRP006C.

*&---------------------------------------------------------------------*
* 表的声明
*&---------------------------------------------------------------------*
TABLES: ANLA,ANLZ,PRPS,ZTFI034.


*&---------------------------------------------------------------------*
* 数据类型声明
*&---------------------------------------------------------------------*
TYPES:BEGIN OF TY_ANLA,
        ANLKL         LIKE ANLA-ANLKL, "资产分类
        ANLN1         LIKE ANLA-ANLN1, "资产编号
        ANLN2         LIKE ANLA-ANLN2, "次级编号
        TXT50         LIKE ANLA-TXT50, "资产名称
        INVNR         LIKE ANLA-INVNR, "设备型号
        LIFNR         LIKE ANLA-LIFNR, "供应商编码
        HERST         LIKE ANLA-HERST, "制造商
        MENGE         LIKE ANLA-MENGE, "数量
        MSEHL         LIKE T006A-MSEHL, "单位
        AKTIV         LIKE ANLA-AKTIV, "资产化日期
        DEAKT         LIKE ANLA-DEAKT, "报废日期
        TXK50         LIKE ANKT-TXK50, "资产分类描述
        NAME1         LIKE LFA1-NAME1, "供应商名称
        KOSTL         LIKE ANLZ-KOSTL, "成本中心
        CAUFN         LIKE ANLZ-CAUFN, "内部订单
        ZCONTRACT_NO  LIKE ANLU-ZCONTRACT_NO,  "合同号
        ZPROCESS      LIKE ANLU-ZPROCESS,      "工序
        ZASSET_STATUS LIKE ANLU-ZASSET_STATUS, "资产状态
        VERAK         LIKE CSKS-VERAK, "使用部门负责人
        KTEXT         LIKE T499S-KTEXT, "资产存放位置
        NDJAR         LIKE ANLB-NDJAR, "使用年限
        NDPER         LIKE ANLB-NDPER, "使用期间
        AFASL         LIKE ANLB-AFASL, "折旧码
        AFABG         LIKE ANLB-AFABG, "折旧开始日期
        KANSW         LIKE ANLC-KANSW, "累计购置价值
        KAUFW         LIKE ANLC-KAUFW, "重置价值的累计重估
        BUKRS         LIKE ANLA-BUKRS,
        SCHRW         LIKE ANLB-SCHRW, "资产残值
        MEINS         LIKE ANLA-MEINS, "不展示
        TXA50         LIKE ANLA-TXA50, "附加资产描述
        POSID         LIKE PRPS-POSID, "WBS元素
        PS_PSP_PNR2   LIKE ANLZ-PS_PSP_PNR2, "WBS元素
        ZERDAT        LIKE ANLA-ERDAT, "特殊标注类型日期
        ZTYPE(50)     TYPE C, "特殊标注类型
        ZMENGE        LIKE ANLA-MENGE, "特殊标注类型数量
        ZINVNR        LIKE ANLA-INVNR, "特殊标注类型资产描述
      END OF TY_ANLA.

TYPES:BEGIN OF TY_PRINT,
        BUTXT         LIKE T001-BUTXT, "公司名称
        ANLKL         LIKE ANLA-ANLKL, "资产分类
        TXK50         LIKE ANKT-TXK50, "资产分类描述
        ANLN1         LIKE ANLA-ANLN1, "资产编号
        ANLN2         LIKE ANLA-ANLN2, "次级编号
        TXT50         LIKE ANLA-TXT50, "资产名称
        INVNR         LIKE ANLA-INVNR, "设备型号
        LIFNR         LIKE ANLA-LIFNR, "供应商编码
        NAME1         LIKE LFA1-NAME1, "供应商名称
        HERST         LIKE ANLA-HERST, "制造商
        MENGE         LIKE ANLA-MENGE, "数量
        MSEHL         LIKE T006A-MSEHL, "单位
        AKTIV         LIKE ANLA-AKTIV, "资产化日期
        KOSTL         LIKE ANLZ-KOSTL, "成本中心
        LTEXT         LIKE CSKT-LTEXT, "成本中心描述
        CAUFN         LIKE ANLZ-CAUFN, "内部订单
        KTEXT1        LIKE AUFK-KTEXT, "内部订单描述
        DEAKT         LIKE ANLA-DEAKT, "报废日期
        ZCONTRACT_NO  LIKE ANLU-ZCONTRACT_NO,  "合同号
        ZPROCESS      LIKE ANLU-ZPROCESS,      "工序
        ZASSET_STATUS LIKE ANLU-ZASSET_STATUS, "资产状态
        VERAK         LIKE CSKS-VERAK,    "使用部门负责人
        KTEXT         LIKE T499S-KTEXT,   "资产存放地点
        AFBTXT        LIKE T093T-AFBTXT, "折旧范围
        NDJAR         LIKE ANLB-NDJAR,    "使用年限
        NDPER         LIKE ANLB-NDPER,    "使用期间
        AFASL         LIKE ANLB-AFASL,    "折旧码
        AFABG         LIKE ANLB-AFABG,    "折旧开始日期
        ZCYZ          LIKE ANLC-KANSW,    "资产原值
        KANSW         LIKE ANLC-KANSW,    "累计购置价值
        AUFWV         LIKE ANLC-AUFWV,    "比例累计重估
        AUFWL         LIKE ANLC-AUFWL,    "当年累计重估价值
        KAUFW         LIKE ANLC-KAUFW,    "重置价值的累计重估
        SUMZJ         LIKE ANLC-KNAFA,    "累计折旧额 = ANLC – KNAFA + ANLC –KSAFA + ANLC –KAAFA + ANLC + KAUFN.
        ADZC          LIKE ANLC-ANSWL,    "资产价值调整 = ANLC~ANSWL + ANLC~ABGAN.
        AUFWB         LIKE ANLC-AUFWB,    "当年重置价值重估
        BLLJZJ        LIKE ANLC-NAFAV,   "比例累计折旧 = ANLC –NAFAV + ANLC –SAFAV + ANLC –AAFAV + ANLC –AUFNV
        DNBLZJ        LIKE ANLC-NAFAL,   "当年比例折旧 = ANLC – NAFAL + ANLC – SAFAL + ANLC- AAFAL + ANLC – AUFNL.
        ZJZE          LIKE ANLC-NAFAV,  "折旧总额
        DNZJE         LIKE ANLC-NAFAV, "当年折旧额
        VALUE         LIKE ANLC-KANSW,    "净值
        REMAIN        LIKE ANLB-SCHRW,   "残值
        ONE           LIKE ANLP-NAFAZ,
        TWO           LIKE ANLP-NAFAZ,
        THREE         LIKE ANLP-NAFAZ,
        FOUR          LIKE ANLP-NAFAZ,
        FIVE          LIKE ANLP-NAFAZ,
        SIX           LIKE ANLP-NAFAZ,
        SEVEN         LIKE ANLP-NAFAZ,
        EIGHT         LIKE ANLP-NAFAZ,
        NINE          LIKE ANLP-NAFAZ,
        TEN           LIKE ANLP-NAFAZ,
        ELEVEN        LIKE ANLP-NAFAZ,
        TWELVE        LIKE ANLP-NAFAZ,
        MEINS         LIKE ANLA-MEINS,   "不展示
        BUKRS         LIKE ANLP-BUKRS,   "不展示
        TXA50         LIKE ANLA-TXA50, "附加资产描述
        POST1         LIKE PRPS-POST1, "WBS描述
        POSID         LIKE PRPS-POSID, "WBS元素
        PS_PSP_PNR2   LIKE ANLZ-PS_PSP_PNR2, "WBS要素
        ZERDAT        LIKE ANLA-ERDAT, "特殊标注类型日期
        ZTYPE(50)     TYPE C, "特殊标注类型
        ZMENGE        LIKE ANLA-MENGE, "特殊标注类型数量
        ZINVNR        LIKE ANLA-INVNR, "特殊标注类型资产描述
      END OF TY_PRINT.

TYPES:BEGIN OF TY_ANLP,
        NAFAZ LIKE ANLP-NAFAZ,
        SAFAZ LIKE ANLP-SAFAZ,
        AAFAZ LIKE ANLP-AAFAZ,
        AUFNZ LIKE ANLP-AUFNZ,
        PERAF LIKE ANLP-PERAF,
        BUKRS LIKE ANLP-BUKRS,  "不展示
        ANLN1 LIKE ANLP-ANLN1,  "不展示
        ANLN2 LIKE ANLP-ANLN2,  "不展示
        AFBNR LIKE ANLP-AFBNR,  "不展示
      END OF TY_ANLP.


*&---------------------------------------------------------------------*
* 内表和工作区声明
*&---------------------------------------------------------------------*
DATA: IT_ANLA  TYPE STANDARD TABLE OF TY_ANLA,
      WA_ANLA  TYPE TY_ANLA,
      IT_PRINT TYPE STANDARD TABLE OF TY_PRINT,
      WA_PRINT TYPE TY_PRINT,
      IT_DATA  TYPE STANDARD TABLE OF TY_PRINT,
      WA_DATA  TYPE TY_PRINT.


DATA: IT_ANLP TYPE STANDARD TABLE OF TY_ANLP,
      WA_ANLP TYPE TY_ANLP.


* ALV用
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
      WA_FIELDCAT LIKE LINE OF IT_FIELDCAT,
      WA_LAYOUT   TYPE SLIS_LAYOUT_ALV.
*&---------------------------------------------------------------------*
* 全局变量的声明
*&---------------------------------------------------------------------*
DATA: G_BUTXT  LIKE T001-BUTXT.
DATA: G_AFBTXT TYPE T093T-AFBTXT,
      G_01(10) TYPE C,
      G_02(10) TYPE C,
      G_03(10) TYPE C,
      G_04(10) TYPE C,
      G_05(10) TYPE C,
      G_06(10) TYPE C,
      G_07(10) TYPE C,
      G_08(10) TYPE C,
      G_09(10) TYPE C,
      G_10(10) TYPE C,
      G_11(10) TYPE C,
      G_12(10) TYPE C.


*&---------------------------------------------------------------------*
* 选择屏幕的定义
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLK01 WITH FRAME.
PARAMETERS: P_BUKRS TYPE T001-BUKRS OBLIGATORY,
            P_GJAHR TYPE BKPF-GJAHR OBLIGATORY,
            P_AFABE TYPE ANLB-AFABE OBLIGATORY, "折旧范围
            P_TXT50 TYPE ANLA-TXT50.

SELECT-OPTIONS: S_ANLKL FOR ANLA-ANLKL, "资产分类
                S_ANLN1 FOR ANLA-ANLN1,"资产编号
                S_KOSTL FOR ANLZ-KOSTL NO INTERVALS, "成本中心
                S_CAUFN FOR ANLZ-CAUFN NO INTERVALS, "内部订单
                S_POSID FOR PRPS-POSID NO INTERVALS,
                S_ZTYPE FOR ZTFI034-ZTYPE.
SELECTION-SCREEN END OF BLOCK BLK01.

*&---------------------------------------------------------------------*
* START-OF-SELECTION 程序开始
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM AUTH_CHECK.
  PERFORM GET_DATA.
  PERFORM DATA_PRINT.

*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM GET_DATA .

  SELECT SINGLE BUTXT INTO G_BUTXT FROM T001 WHERE BUKRS = P_BUKRS AND SPRAS = SY-LANGU. "公司名称

  SELECT ANLA~ANLKL, "资产分类
         ANLA~ANLN1, "资产编号
         ANLA~ANLN2, "次级编号
         ANLA~TXT50, "资产名称
         ANLA~INVNR, "设备型号
         ANLA~LIFNR, "供应商编码
         ANLA~HERST, "制造商
         ANLA~MENGE, "数量
         ANLA~AKTIV, "资产化日期
         ANLA~DEAKT, "报废日期
         LFA1~NAME1, "供应商名称
         ANLZ~KOSTL, "成本中心
         ANLZ~CAUFN, "内部订单
         ANLZ~PS_PSP_PNR2,  "WBS
         ANLU~ZCONTRACT_NO, "合同号
         ANLU~ZPROCESS,     "工序
         ANLU~ZASSET_STATUS,"资产状态
         T499S~KTEXT,"资产存放位置
         ANLB~NDJAR, "使用年限
         ANLB~NDPER, "使用期间
         ANLB~AFASL, "折旧码
         ANLB~AFABG, "折旧开始日期
         ANLB~SCHRW, "资产残值
         ANLA~BUKRS,
         ANLA~MEINS,
         ZTFI034~ZERDAT,
         ZTFI034~ZTYPE,
         ZTFI034~ZMENGE,
         ZTFI034~ZINVNR,
         ANLA~TXA50 "附加资产描述
    FROM ANLA
    LEFT JOIN ZTFI034 ON ANLA~ANLN1 = ZTFI034~ANLN1   AND ANLA~BUKRS = ZTFI034~BUKRS
    LEFT JOIN LFA1 ON ANLA~LIFNR = LFA1~LIFNR
    LEFT JOIN ANLZ ON ANLA~BUKRS = ANLZ~BUKRS AND ANLA~ANLN1 = ANLZ~ANLN1 AND ANLA~ANLN2 = ANLZ~ANLN2
    LEFT JOIN ANLU ON ANLA~BUKRS = ANLU~BUKRS AND ANLA~ANLN1 = ANLU~ANLN1 AND ANLA~ANLN2 = ANLU~ANLN2
    LEFT JOIN T499S ON T499S~STAND  = ANLZ~STORT
    LEFT JOIN ANLB ON ANLA~BUKRS = ANLB~BUKRS AND ANLA~ANLN1 = ANLB~ANLN1 AND ANLA~ANLN2 = ANLB~ANLN2
    INTO CORRESPONDING FIELDS OF TABLE @IT_ANLA
    WHERE ANLA~BUKRS = @P_BUKRS
    AND ANLA~ANLKL IN @S_ANLKL AND ANLA~ANLKL <> 'HC800'   "资产分类排除在建工程
    AND ANLA~ANLN1 IN @S_ANLN1
    AND ANLB~AFABE = @P_AFABE
    AND ( ANLZ~ADATU <= @SY-DATUM AND ANLZ~BDATU >= @SY-DATUM )
    AND ANLZ~KOSTL IN @S_KOSTL
    AND ANLZ~CAUFN IN @S_CAUFN
    AND ZTFI034~ZTYPE IN @S_ZTYPE.


  "从anlc中取数
  IF IT_ANLA[] IS NOT INITIAL.
    SELECT ANLC~KANSW, "累计购置价值
           ANLC~KAUFW, "重置价值的累计重估
           ANLC~KNAFA, "累计折旧 = ANLC – KNAFA + ANLC –KSAFA + ANLC –KAAFA + ANLC + KAUFN.
           ANLC~KSAFA,
           ANLC~KAAFA,
           ANLC~KAUFN,
           ANLC~ANSWL, "资产价值调整 = ANLC~ANSWL + ANLC~BGAN.
           ANLC~ABGAN,
           ANLC~AUFWB, "当年重置价值重估
           ANLC~AUFWV, "比例累计重估
           ANLC~NAFAV, "比例累计折旧 = ANLC –NAFAV + ANLC –SAFAV + ANLC –AAFAV + ANLC –AUFNV
           ANLC~SAFAV,
           ANLC~AAFAV,
           ANLC~AUFNV,
           ANLC~AUFWL, "当年比例重估价值
           ANLC~NAFAL, "当年比例折旧 = ANLC – NAFAL + ANLC – SAFAL + ANLC- AAFAL + ANLC – AUFNL.
           ANLC~SAFAL,
           ANLC~AAFAL,
           ANLC~AUFNL,
           ANLC~BUKRS,
           ANLC~ANLN1,
           ANLC~ANLN2
      INTO TABLE @DATA(IT_ANLC)
      FROM ANLC
      FOR ALL ENTRIES IN @IT_ANLA
      WHERE ANLC~BUKRS = @IT_ANLA-BUKRS AND ANLC~ANLN1 = @IT_ANLA-ANLN1 AND ANLC~ANLN2 = @IT_ANLA-ANLN2
      AND ANLC~GJAHR = @P_GJAHR
      AND ANLC~AFABE = @P_AFABE.
  ENDIF.

  SORT IT_ANLC BY BUKRS ANLN1 ANLN2 ASCENDING.

  " 折旧范围
  SELECT SINGLE T093T~AFBTXT
    FROM T093T
    INTO G_AFBTXT
    WHERE T093T~SPRAS = SY-LANGU
    AND T093T~AFAPL = 'HC00'
    AND T093T~AFABER  = P_AFABE.


* 01-12月 折旧额
  IF IT_ANLA[] IS NOT INITIAL.
    SELECT ANLP~NAFAZ
           ANLP~SAFAZ
           ANLP~AAFAZ
           ANLP~AUFNZ
           ANLP~PERAF  "折旧的过账期间
           ANLP~BUKRS  "不展示
           ANLP~ANLN1  "不展示
           ANLP~ANLN2  "不展示
           ANLP~AFBNR  "不展示
      FROM ANLP
      INTO CORRESPONDING FIELDS OF TABLE IT_ANLP
      FOR ALL ENTRIES IN IT_ANLA
      WHERE ANLP~BUKRS = IT_ANLA-BUKRS
      AND ANLP~ANLN1 = IT_ANLA-ANLN1
      AND ANLP~ANLN2 = IT_ANLA-ANLN2
      AND ANLP~AFABER = P_AFABE
      AND ANLP~GJAHR = P_GJAHR.
  ENDIF.

  CONCATENATE P_GJAHR '01折旧' INTO G_01.
  CONCATENATE P_GJAHR '02折旧' INTO G_02.
  CONCATENATE P_GJAHR '03折旧' INTO G_03.
  CONCATENATE P_GJAHR '04折旧' INTO G_04.
  CONCATENATE P_GJAHR '05折旧' INTO G_05.
  CONCATENATE P_GJAHR '06折旧' INTO G_06.
  CONCATENATE P_GJAHR '07折旧' INTO G_07.
  CONCATENATE P_GJAHR '08折旧' INTO G_08.
  CONCATENATE P_GJAHR '09折旧' INTO G_09.
  CONCATENATE P_GJAHR '10折旧' INTO G_10.
  CONCATENATE P_GJAHR '11折旧' INTO G_11.
  CONCATENATE P_GJAHR '12折旧' INTO G_12.


  LOOP AT IT_ANLA INTO WA_ANLA.
    MOVE-CORRESPONDING WA_ANLA TO WA_PRINT.
    WA_PRINT-BUTXT = G_BUTXT.                                                         "公司名称
    WA_PRINT-AFBTXT = G_AFBTXT.                                                       "折旧范围

    READ TABLE IT_ANLC INTO DATA(WA_ANLC) WITH KEY BUKRS = WA_ANLA-BUKRS ANLN1 = WA_ANLA-ANLN1 ANLN2 = WA_ANLA-ANLN2 BINARY SEARCH.
    IF SY-SUBRC = 0.
      WA_PRINT-KANSW = WA_ANLC-KANSW. "累计购置价值
      WA_PRINT-KAUFW = WA_ANLC-KAUFW. "重置价值的累计重估
      WA_PRINT-AUFWB = WA_ANLC-AUFWB. "当年重置价值重估
      WA_PRINT-AUFWV = WA_ANLC-AUFWV. "比例累计重估
      WA_PRINT-AUFWL = WA_ANLC-AUFWL. "当年比例重估价值

      WA_PRINT-SUMZJ = WA_ANLC-KNAFA + WA_ANLC-KSAFA + WA_ANLC-KAAFA + WA_ANLC-KAUFN.   "累计折旧额
      WA_PRINT-ADZC = WA_ANLC-ANSWL + WA_ANLC-ABGAN.                                    "资产价值调整
      WA_PRINT-BLLJZJ = WA_ANLC-NAFAV + WA_ANLC-SAFAV + WA_ANLC-AAFAV + WA_ANLC-AUFNV.  "比例累计折旧
      WA_PRINT-DNBLZJ = WA_ANLC-NAFAL + WA_ANLC-SAFAL + WA_ANLC-AAFAL + WA_ANLC-AUFNL.  "当年比例折旧
    ENDIF.

    SELECT SINGLE PRPS~POST1 INTO WA_PRINT-POST1 FROM PRPS WHERE PRPS~PSPNR = WA_PRINT-PS_PSP_PNR2. "WBS描述
    SELECT SINGLE PRPS~POSID INTO WA_PRINT-POSID FROM PRPS WHERE PRPS~PSPNR = WA_PRINT-PS_PSP_PNR2. "WBS元素

* 计算残值
    IF WA_ANLA-SCHRW <> 0.
      WA_PRINT-REMAIN = WA_ANLA-SCHRW.
    ELSEIF WA_ANLA-AFASL = 'Z100'.
      WA_PRINT-REMAIN = ( WA_PRINT-KANSW + WA_PRINT-KAUFW + WA_PRINT-ADZC + WA_PRINT-AUFWB + WA_PRINT-AUFWB + WA_PRINT-AUFWL ) * 5 / 100.
    ELSEIF WA_ANLA-AFASL = 'Z200'.
      WA_PRINT-REMAIN = 0.
    ENDIF.
    APPEND WA_PRINT TO IT_PRINT.
    CLEAR: WA_PRINT,WA_ANLA, WA_ANLC.
  ENDLOOP.


  LOOP AT IT_PRINT INTO WA_PRINT.

    "单位
    SELECT SINGLE MSEHL FROM T006A INTO WA_PRINT-MSEHL WHERE T006A~MSEHI = WA_PRINT-MEINS AND T006A~SPRAS = SY-LANGU.

    "产分类描述
    SELECT SINGLE TXK50 FROM ANKT INTO WA_PRINT-TXK50 WHERE ANKT~ANLKL = WA_PRINT-ANLKL AND ANKT~SPRAS = SY-LANGU.

    "使用部门负责人
    SELECT SINGLE VERAK FROM CSKS INTO WA_PRINT-VERAK WHERE CSKS~KOSTL = WA_PRINT-KOSTL AND CSKS~KOKRS = '9999'.

    "成本中心描述
    IF WA_PRINT-KOSTL IS NOT INITIAL.
      SELECT SINGLE LTEXT INTO WA_PRINT-LTEXT FROM CSKT WHERE KOKRS = '9999' AND SPRAS = '1'
        AND KOSTL = WA_PRINT-KOSTL.
    ENDIF.

    "内部订单描述
    IF WA_PRINT-CAUFN IS NOT INITIAL.
      SELECT SINGLE KTEXT INTO WA_PRINT-KTEXT1 FROM AUFK WHERE AUFNR = WA_PRINT-CAUFN.
    ENDIF.
*    "租赁类型
*    IF WA_PRINT-anln1 IS NOT INITIAL.
*      SELECT SINGLE type INTO WA_PRINT-type FROM ztfi034 WHERE anln1 = WA_PRINT-anln1.
*    ENDIF.

    "折旧额
    LOOP AT IT_ANLP INTO WA_ANLP .
      IF WA_ANLP-BUKRS = WA_PRINT-BUKRS  AND WA_ANLP-ANLN1 = WA_PRINT-ANLN1 AND WA_ANLP-ANLN2 = WA_PRINT-ANLN2.
        "去掉前导零
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
          EXPORTING
            INPUT  = WA_ANLP-PERAF
          IMPORTING
            OUTPUT = WA_ANLP-PERAF.

        IF WA_ANLP-PERAF = '1'.
          WA_PRINT-ONE = WA_PRINT-ONE + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '2'.
          WA_PRINT-TWO = WA_PRINT-TWO + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '3'.
          WA_PRINT-THREE = WA_PRINT-THREE + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '4'.
          WA_PRINT-FOUR = WA_PRINT-FOUR + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '5'.
          WA_PRINT-FIVE = WA_PRINT-FIVE + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '6'.
          WA_PRINT-SIX = WA_PRINT-SIX + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '7'.
          WA_PRINT-SEVEN = WA_PRINT-SEVEN + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '8'.
          WA_PRINT-EIGHT = WA_PRINT-EIGHT + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '9'.
          WA_PRINT-NINE = WA_PRINT-NINE + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '10'.
          WA_PRINT-TEN = WA_PRINT-TEN + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '11'.
          WA_PRINT-ELEVEN = WA_PRINT-ELEVEN + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ELSEIF WA_ANLP-PERAF = '12'.
          WA_PRINT-TWELVE = WA_PRINT-TWELVE + WA_ANLP-NAFAZ + WA_ANLP-SAFAZ + WA_ANLP-AAFAZ + WA_ANLP-AUFNZ.
        ENDIF.
      ENDIF.
    ENDLOOP.

    WA_PRINT-VALUE = WA_PRINT-KANSW + WA_PRINT-KAUFW + WA_PRINT-SUMZJ + WA_PRINT-ADZC "净值
                   + WA_PRINT-AUFWB + WA_PRINT-BLLJZJ + WA_PRINT-AUFWV + WA_PRINT-DNBLZJ + WA_PRINT-AUFWL
                   + WA_PRINT-ONE + WA_PRINT-TWO + WA_PRINT-THREE + WA_PRINT-FOUR + WA_PRINT-FIVE
                   + WA_PRINT-SIX + WA_PRINT-SEVEN + WA_PRINT-EIGHT + WA_PRINT-NINE
                   + WA_PRINT-TEN + WA_PRINT-ELEVEN + WA_PRINT-TWELVE.
    "当年折旧额=当年各期折旧额合计+当年比例折旧
    WA_PRINT-DNZJE = WA_PRINT-ONE + WA_PRINT-TWO + WA_PRINT-THREE + WA_PRINT-FOUR + WA_PRINT-FIVE + WA_PRINT-SIX
                   + WA_PRINT-SEVEN + WA_PRINT-EIGHT + WA_PRINT-NINE + WA_PRINT-TEN + WA_PRINT-ELEVEN + WA_PRINT-TWELVE.
*                   + wa_print-dnblzj.         "注释BY LEE 20190715
    "折旧总额=累计折旧+当年各期折旧额+比例累计折旧+当年比例折旧
    WA_PRINT-ZJZE  = WA_PRINT-DNZJE + WA_PRINT-SUMZJ
                   + WA_PRINT-BLLJZJ + WA_PRINT-DNBLZJ.
    "资产原值:累计购置价值+重置价值的累计重估+资产价值调整+当年重置价值重估+比例累计重估+当年比例重估价值
    WA_PRINT-ZCYZ  = WA_PRINT-KANSW + WA_PRINT-KAUFW + WA_PRINT-ADZC + WA_PRINT-AUFWB + WA_PRINT-AUFWV + WA_PRINT-AUFWL.

    MODIFY IT_PRINT FROM WA_PRINT.
    CLEAR: WA_PRINT, WA_ANLP.
  ENDLOOP.
  CLEAR:WA_PRINT,WA_DATA.


ENDFORM.
*&---------------------------------------------------------------------*
*& Form DATA_PRINT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM DATA_PRINT .
  PERFORM FRM_EDIT_FIELDCAT USING:
    '1'   'BUTXT'           'IT_PRINT'  '公司名称'       '25',
    '2'   'ANLKL'           'IT_PRINT'  '资产分类'       '8',
    '3'   'TXK50'           'IT_PRINT'  '资产分类描述'   '50',
    '3'   'TXA50'           'IT_PRINT'  '附加资产描述'   '50',
    '4'   'ANLN1'           'IT_PRINT'  '资产编号'       '12',
    '5'   'ANLN2'           'IT_PRINT'  '次级编号'       '4',
    '6'   'TXT50'           'IT_PRINT'  '资产名称'       '50',
    '7'   'INVNR'           'IT_PRINT'  '设备型号'       '12',
    '8'   'LIFNR'           'IT_PRINT'  '供应商编码'     '10',
    '9'   'NAME1'           'IT_PRINT'  '供应商名称'     '35',
    '10'  'HERST'           'IT_PRINT'  '制造商'         '30',
    '11'  'MENGE'           'IT_PRINT'  '数量'           '13',
    '12'  'MSEHL'           'IT_PRINT'  '单位'           '30',
    '13'  'AKTIV'           'IT_PRINT'  '资产化日期'     '8',
    '14'  'KOSTL'           'IT_PRINT'  '成本中心'       '10',
    '15'  'LTEXT'           'IT_PRINT'  '成本中心描述'   '40',
    '16'  'CAUFN'           'IT_PRINT'  '内部订单'       '20',
    '17'  'KTEXT1'          'IT_PRINT'  '内部订单描述'   '40',
    '18'  'POSID'           'IT_PRINT'  'WBS元素'        '8',
    '19'  'POST1'           'IT_PRINT'  'WBS描述'        '40',
    '20'  'DEAKT'           'IT_PRINT'  '报废日期'       '8',
    '21'  'ZCONTRACT_NO'    'IT_PRINT'  '合同号'         '30',
    '22'  'ZPROCESS'        'IT_PRINT'  '工序'           '20',
    '23'  'ZASSET_STATUS'   'IT_PRINT'  '资产状态'       '10',
    '24'  'VERAK'           'IT_PRINT'  '使用部门负责人' '20',
    '25'  'KTEXT'           'IT_PRINT'  '资产存放地点'   '40',
    '26'  'AFBTXT'          'IT_PRINT'  '折旧范围'       '50',
    '27'  'NDJAR'           'IT_PRINT'  '使用年限'       '3',
    '28'  'NDPER'           'IT_PRINT'  '使用期间'       '3',
    '29'  'AFASL'           'IT_PRINT'  '折旧码'         '4',
    '30'  'AFABG'           'IT_PRINT'  '折旧开始日期'   '8',
    '30'  'ZCYZ'            'IT_PRINT'  '资产原值'       '30',
    '31'  'KANSW'           'IT_PRINT'  '以前年度资产原值'   '30',
    '32'  'KAUFW'           'IT_PRINT'  '以前年度资产减值准备' '30',
    '33'  'SUMZJ'           'IT_PRINT'  '以前年度累计折旧额'     '30',
    '34'  'ADZC'            'IT_PRINT'  '当年资产购置价值'   '30',
    '35'  'AUFWB'           'IT_PRINT'  '当年资产减值准备' '30',
    '36'  'AUFWV'           'IT_PRINT'  '冲回以前年度减值准备'    '30',
    '37'  'BLLJZJ'          'IT_PRINT'  '冲回以前年度折旧'    '30',
    '38'  'AUFWL'           'IT_PRINT'  '冲回当年减值准备' '30',
    '39'  'DNBLZJ'          'IT_PRINT'  '冲回当年折旧'     '30',
    '40'  'ONE'             'IT_PRINT'   G_01            '30',
    '41'  'TWO'             'IT_PRINT'   G_02            '30',
    '42'  'THREE'           'IT_PRINT'   G_03            '30',
    '43'  'FOUR'            'IT_PRINT'   G_04            '30',
    '44'  'FIVE'            'IT_PRINT'   G_05            '30',
    '45'  'SIX'             'IT_PRINT'   G_06            '30',
    '46'  'SEVEN'           'IT_PRINT'   G_07            '30',
    '47'  'EIGHT'           'IT_PRINT'   G_08            '30',
    '48'  'NINE'            'IT_PRINT'   G_09            '30',
    '49'  'TEN'             'IT_PRINT'   G_10            '30',
    '50'  'ELEVEN'          'IT_PRINT'   G_11            '30',
    '51'  'TWELVE'          'IT_PRINT'   G_12            '30',
    '52'  'ZJZE'            'IT_PRINT'  '折旧总额'       '30',
    '53'  'DNZJE'           'IT_PRINT'  '当年折旧额'     '30',
    '54'  'VALUE'           'IT_PRINT'  '净值'           '30',
    '55'  'REMAIN'          'IT_PRINT'  '残值'           '30',
    '56'  'ZERDAT'          'IT_PRINT'  '特殊标注类型日期'       '30',
    '57'  'ZTYPE'           'IT_PRINT'  '特殊标注类型'       '30',
    '58'  'ZMENGE'          'IT_PRINT'  '特殊标注类型数量'       '30',
    '59'  'ZINVNR'          'IT_PRINT'  '特殊标注类型资产描述'       '30'.

  WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM          = SY-REPID
      IS_LAYOUT                   = WA_LAYOUT
      IT_FIELDCAT                 = IT_FIELDCAT
      I_SAVE                      = 'A'
      I_CALLBACK_HTML_TOP_OF_PAGE = 'F_TOP_OF_PAGE'
    TABLES
      T_OUTTAB                    = IT_PRINT.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_EDIT_FIELDCAT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*      -->P_       text
*      -->P_       text
*      -->P_       text
*      -->P_       text
*&---------------------------------------------------------------------*
FORM FRM_EDIT_FIELDCAT  USING P_COL_POS   TYPE ANY
                              P_FIELDNAME TYPE ANY
                              P_TABNAME   TYPE ANY
                              P_SELTEXT   TYPE ANY
                              P_OUTPUTLEN TYPE ANY.
  WA_FIELDCAT-COL_POS   = P_COL_POS.
  WA_FIELDCAT-FIELDNAME = P_FIELDNAME.
  WA_FIELDCAT-TABNAME   = P_TABNAME.
  WA_FIELDCAT-SELTEXT_M = P_SELTEXT.
  WA_FIELDCAT-OUTPUTLEN = P_OUTPUTLEN.

  APPEND WA_FIELDCAT TO IT_FIELDCAT.
  CLEAR WA_FIELDCAT.
ENDFORM.

FORM F_TOP_OF_PAGE USING P_CL_DD TYPE REF TO CL_DD_DOCUMENT.
  DATA: M_P      TYPE I,
        M_BUFFER TYPE STRING.

  M_BUFFER = '<HTML><CENTER><H1>资产明细表</H1></CENTER></HTML>' .
  CALL METHOD P_CL_DD->HTML_INSERT
    EXPORTING
      CONTENTS = M_BUFFER
    CHANGING
      POSITION = M_P.
ENDFORM.

FORM AUTH_CHECK.
  DATA:LS_MESSAGE TYPE STRING.

  AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
  ID 'BUKRS' FIELD P_BUKRS.
  IF SY-SUBRC <> 0.
    CLEAR LS_MESSAGE.
    CONCATENATE '您没有公司' P_BUKRS '的权限' INTO LS_MESSAGE.
    MESSAGE LS_MESSAGE TYPE 'E' .
    EXIT.
  ENDIF.

ENDFORM.

网上的

"CODE LISTING FOR: ZFIR016
"DESCRIPTION: 资产明细查询
*&---------------------------------------------------------------------*
*& Report ZFIR016
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZFIR016.

TYPES: BEGIN OF TY_OUTPUT,
         SELECT       TYPE AS4FLAG, "选中标识
         BUKRS        TYPE BUKRS, "公司代码
         ANLN1        TYPE ANLN1, "资产编号
         ANLN2        TYPE ANLN2, "资产次级编号
         TXT50        TYPE TXA50_ANLT, "资产名称
         ANLKL        TYPE ANLKL, "资产分类
         TXK20        TYPE TXT20_ANKT, "资产分类名称
         TXA50        TYPE TXA50_MORE, "规格参数/附加资产描述
         ANLHTXT      TYPE ANLHTXT, "资产主号文本
         LETXT        TYPE LETXT, "租赁数据文本
         SERNR        TYPE AM_SERNR, "序列号/旧资产号码
         INVNR        TYPE INVNR_ANLA, "存货号
         AIBN1        TYPE AIBN1, "转帐的原始资产
         AIBN2        TYPE AIBN2, "转帐的原始资产
         MENGE        TYPE AM_MENGE, "数量
         MEINS        TYPE MEINS, "计量单位
         KOSTL        TYPE KOSTL, "成本中心
         KOSTL_TXT    TYPE KTEXT, "成本中心描述
         VERAK        TYPE VERAK, "成本中心负责人
         CAUFN        TYPE CAUFN, "内部订单
         AUFNR_TXT    TYPE AUFTEXT, "内部订单描述
         RAUMN        TYPE RAUMNR, "资产保管人
         KFZKZ        TYPE AM_KFZKZ, "执照牌号
         LIFNR        TYPE AM_LIFNR, "供应商
         NAME1        TYPE NAME1, "供应商描述
         HERST        TYPE HERST, "制造商
         AKTIV        TYPE AKTIVD, "资本化日期
         ORD41        TYPE ORD41, "使用状态
         ORD41_T      TYPE ORDTX, "使用状态名称
*         ord41        TYPE anla-ord41, "使用状态
         ORD42        TYPE ANLA-ORD42, "资产性质
         ORD42_T      TYPE ORDTX,      "资产性质
         ORD43        TYPE ANLA-ORD43, "资产来源
         ORD43_T      TYPE ORDTX,      "资产来源
         ORD44        TYPE ANLA-ORD44, "资金来源
         ORD44_T      TYPE ORDTX,      "资金来源
         GDLGRP       TYPE ANLA-GDLGRP, "明细分类
         GDLGRP_T     TYPE T087S-GDLGRP_TXT, "明细分类
         DEAKT        TYPE DEAKT, "不活动日期
         AFABE        TYPE AFABE_D, "折旧范围
         AFBKTX       TYPE AFBKTX, "折旧范围说明
         AFASL        TYPE AFASL, "折旧方法
         AFATXT       TYPE AFATXT, "折旧方法说明
         AFABG        TYPE AFABG, "开始折旧日期
         NDJAR        TYPE NDJAR, "计划使用年限
         NDPER        TYPE NDPER, "计划使用期间
         USDPER       TYPE NDPER, "已计提期间
         RMNPER       TYPE NDPER, "剩余计提期间
         ORGVAL       TYPE KANSW, "原值
         ACCDEP       TYPE KNAFA, "累计折旧
         NETVAL       TYPE RBWRT, "净值
         RSDVAL       TYPE SCHRW, "残值
         AHPROZ       TYPE AHPROZ, "残值率(%)
         USDPER_MONTH TYPE NDPER, "时点已计提期间
         RMNPER_MONTH TYPE NDPER, "时点剩余计提期间
         ORGVAL_MONTH TYPE KANSW, "时点原值
         ACCDEP_MONTH TYPE KNAFA, "时点累计折旧
         NETVAL_MONTH TYPE RBWRT, "时点净值
         KTOGR        TYPE KTOGR, "科目定位码
         KTANSW       TYPE KTANSW, "原值科目
         KTANSW_TXT   TYPE TXT50_SKAT, "原值科目描述
         KTNAFB       TYPE KTNAFB, "累计折旧科目
         KTNAFB_TXT   TYPE TXT50_SKAT, "累计折旧科目描述
         KTNAFG       TYPE KTNAFG, "折旧费科目
         KTNAFG_TXT   TYPE TXT50_SKAT, "折旧费科目描述
         GJAHR        TYPE GJAHR, "资产财年
         CURDEP       TYPE NAFAP, "本年应计提折旧
         DEP_001      TYPE NAFAP, "1月份计提折旧
         FLG_001      TYPE ICON_D, "计划/记账
         DEP_002      TYPE NAFAP, "2月份计提折旧
         FLG_002      TYPE ICON_D, "计划/记账
         DEP_003      TYPE NAFAP, "3月份计提折旧
         FLG_003      TYPE ICON_D, "计划/记账
         DEP_004      TYPE NAFAP, "4月份计提折旧
         FLG_004      TYPE ICON_D, "计划/记账
         DEP_005      TYPE NAFAP, "5月份计提折旧
         FLG_005      TYPE ICON_D, "计划/记账
         DEP_006      TYPE NAFAP, "6月份计提折旧
         FLG_006      TYPE ICON_D, "计划/记账
         DEP_007      TYPE NAFAP, "7月份计提折旧
         FLG_007      TYPE ICON_D, "计划/记账
         DEP_008      TYPE NAFAP, "8月份计提折旧
         FLG_008      TYPE ICON_D, "计划/记账
         DEP_009      TYPE NAFAP, "9月份计提折旧
         FLG_009      TYPE ICON_D, "计划/记账
         DEP_010      TYPE NAFAP, "10月份计提折旧
         FLG_010      TYPE ICON_D, "计划/记账
         DEP_011      TYPE NAFAP, "11月份计提折旧
         FLG_011      TYPE ICON_D, "计划/记账
         DEP_012      TYPE NAFAP, "12月份计提折旧
         FLG_012      TYPE ICON_D, "计划/记账
         WAERS        TYPE WAERS, "货币
*-------START BY VAN 20191226-------
         INVZU        TYPE INVZU_ANLA, "库存注记
*-------END   BY VAN 20191226-------
       END OF TY_OUTPUT.
TYPES:BEGIN OF TY_T001,
        BUKRS TYPE T001-BUKRS,
      END OF TY_T001.
TYPES:BEGIN OF TY_LFA1,
        LIFNR TYPE LIFNR,
        NAME1 TYPE NAME1,
      END OF TY_LFA1.
DATA:GT_LFA1 TYPE STANDARD TABLE OF TY_LFA1,
     GW_LFA1 TYPE TY_LFA1.
DATA:GT_T001 TYPE STANDARD TABLE OF  T001,
     GW_T001 TYPE T001.
TABLES:
*  主数据及资产价值
  ANLA,"资产主记录段
  ANLB,"折旧期限
  ANLC,"资产值字段
  ANLH,"主资产号
  ANLZ,"时间相关资产分配
  ANEK,"凭证抬头资产过帐
  ANEP,"资产行项目
  ANEA,"比例值的资产行项目
*      文本描述
  ANKT,"资产类别描述
  AUFK,"订单主数据
  CSKS,"成本中心主数据
  CSKT,"成本中心说明文本
  T087T,"评估组描述
  T090NA,"折旧码
  T090NAT,"折旧码名称
  T091P,"截止值百分率
  T093B,"与公司代码相关的折旧范围参数
  T093C,"在资产会计中的公司代码
  T093T."有关实际的和派生折旧范围的名称

"输出表样相关的内表、工作区定义
DATA: GT_OUTPUT TYPE TABLE OF  TY_OUTPUT,
      GS_OUTPUT TYPE  TY_OUTPUT.
FIELD-SYMBOLS: <FS_OUTPUT> TYPE TY_OUTPUT.
"ALV相关字段目录、排序、布局定义
DATA : GT_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE,
       GT_SORT     TYPE LVC_T_SORT WITH HEADER LINE,
       GS_LAYOUT   TYPE LVC_S_LAYO.

"ALV字段目录宏
DEFINE GET_FIELDCAT.
  gt_fieldcat-col_pos = &1."输出列
  gt_fieldcat-fieldname = &2."字段名称
  gt_fieldcat-reptext = &3."标题
  gt_fieldcat-scrtext_l = &3."长字段标签
  gt_fieldcat-scrtext_m = &3."中字段标签
  gt_fieldcat-scrtext_s = &3."短字段标签
  gt_fieldcat-ref_field = &4. "参考字段
  gt_fieldcat-ref_table = &5. "参考表
  IF &6 = 'QUAN'.
    gt_fieldcat-qfieldname = 'MEINS'."参考计量单位
    gt_fieldcat-do_sum = abap_true."总计
ELSEIF &6 = 'CURR'.
    gt_fieldcat-cfieldname = 'WAERS'."参考货币
    gt_fieldcat-do_sum = abap_true."总计
  ENDIF.
  IF gt_fieldcat-fieldname+0(3) = 'DEP'.
    gt_fieldcat-no_zero = abap_true.
  ENDIF.
  IF gt_fieldcat-fieldname EQ 'BUKRS' OR gt_fieldcat-fieldname EQ 'ANLN1' OR
  gt_fieldcat-fieldname EQ 'ANLN2' OR gt_fieldcat-fieldname EQ 'TXT50'.
    gt_fieldcat-KEY = 'X'.
  ENDIF.
  APPEND gt_fieldcat.
  CLEAR gt_fieldcat.
END-OF-DEFINITION.
SELECT-OPTIONS:
S_BUKRS FOR ANLA-BUKRS OBLIGATORY MEMORY ID BUK, "公司代码
S_ANLN1 FOR ANLA-ANLN1,"资产编号,考虑到大多数是资产清单,资产编号相关不存取内存
S_ANLN2 FOR ANLA-ANLN2,"资产次级编号
S_TXT50 FOR ANLA-TXT50 NO INTERVALS,
S_ANLKL FOR ANLA-ANLKL.
*  S_ORD41 FOR ANLA-ORD41 NO INTERVALS.

PARAMETERS:
  P_GJAHR TYPE GJAHR OBLIGATORY DEFAULT SY-DATLO+0(4), "资产财年,用于显示资产价值
  P_PERAF TYPE PERAF OBLIGATORY DEFAULT SY-DATLO+4(2), "折旧期间用于显示资产时点价值
  P_AFABE TYPE ANLB-AFABE OBLIGATORY DEFAULT '01',
  C_DEAKT AS CHECKBOX DEFAULT ABAP_TRUE, "显示不活动的资产(全部资产价值报废),取消时则仅显示活动资产
  P_RB1   RADIOBUTTON GROUP RB DEFAULT 'X', "资产明细清单
  P_RB2   RADIOBUTTON GROUP RB, "按资产分类小计
  P_RB3   RADIOBUTTON GROUP RB. "按资产分类汇总

INITIALIZATION.
  PERFORM FRM_DEFUALT_GJAHR.

AT SELECTION-SCREEN.
  PERFORM FRM_CHECK_AUTHORIZATION.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_AFABE.
  PERFORM FRM_REQUEST_AFABE.

START-OF-SELECTION.
  PERFORM FRM_GET_DATA.

END-OF-SELECTION.
  PERFORM FRM_DISPLAY_ALV.
*&---------------------------------------------------------------------*
*&      Form  FRM_CHECK_AUTHORIZATION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_CHECK_AUTHORIZATION .
  SELECT *
  INTO TABLE GT_T001
  FROM T001
  WHERE BUKRS IN S_BUKRS.

  LOOP AT  GT_T001 INTO GW_T001.
    AUTHORITY-CHECK OBJECT 'A_S_ANLKL'
    ID 'ACTVT' FIELD '03'
*      ID 'ANLKL' FIELD DUMMY
    ID 'BUKRS' FIELD GW_T001-BUKRS.
    IF SY-SUBRC NE 0.
      DELETE GT_T001 WHERE BUKRS = GW_T001-BUKRS.
    ENDIF.
  ENDLOOP.

  IF GT_T001 IS INITIAL.
    MESSAGE E048(AA) WITH GW_T001-BUKRS.
  ENDIF.


  SELECT DISTINCT
  BUKRS
  FROM TVKO
  INTO TABLE @DATA(LT_BUKRS)
        WHERE BUKRS IN @S_BUKRS.

  LOOP AT LT_BUKRS INTO DATA(LS_BUKRS).
    AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
    ID 'BUKRS' FIELD LS_BUKRS-BUKRS
    ID 'ACTVT' FIELD '03'.
    IF SY-SUBRC <> 0.
      MESSAGE '没有权限使用此公司代码' TYPE 'S' DISPLAY LIKE 'E'.
      STOP.
    ENDIF.
  ENDLOOP.

ENDFORM.                    "FRM_CHECK_AUTHORIZATION
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
  DATA:
    LT_ANLA    TYPE STANDARD TABLE OF ANLA,
    LS_ANLA    TYPE ANLA,
    LT_ANLB    TYPE STANDARD TABLE OF ANLB,
    LS_ANLB    TYPE ANLB,
    LT_ANLC    TYPE STANDARD TABLE OF ANLC,
    LS_ANLC    TYPE ANLC,
    LT_ANLP    TYPE STANDARD TABLE OF ANLP,
    LS_ANLP    TYPE ANLP,
    LT_ANLH    TYPE STANDARD TABLE OF ANLH,
    LS_ANLH    TYPE ANLH,
    LT_ANLZ    TYPE STANDARD TABLE OF ANLZ,
    LS_ANLZ    TYPE ANLZ,
    LT_ANEA    TYPE STANDARD TABLE OF ANEA,
    LS_ANEA    TYPE ANEA,
    LT_ANEK    TYPE STANDARD TABLE OF ANEK,
    LS_ANEK    TYPE ANEK,
    LT_ANEP    TYPE STANDARD TABLE OF ANEP,
    LS_ANEP    TYPE ANEP,
    LT_ANKT    TYPE STANDARD TABLE OF ANKT,
    LS_ANKT    TYPE ANKT,
    LT_AUFK    TYPE STANDARD TABLE OF AUFK,
    LS_AUFK    TYPE AUFK,
    LT_CSKS    TYPE STANDARD TABLE OF CSKS,
    LS_CSKS    TYPE CSKS,
    LT_CSKT    TYPE STANDARD TABLE OF CSKT,
    LS_CSKT    TYPE CSKT,
    LT_T087T   TYPE STANDARD TABLE OF T087T,
    LS_T087T   TYPE T087T,
    LT_T090NA  TYPE STANDARD TABLE OF T090NA,
    LS_T090NA  TYPE T090NA,
    LT_T090NAT TYPE STANDARD TABLE OF T090NAT,
    LS_T090NAT TYPE T090NAT,
    LT_T091P   TYPE STANDARD TABLE OF T091P,
    LS_T091P   TYPE T091P,
    LT_T093B   TYPE STANDARD TABLE OF T093B,
    LS_T093B   TYPE T093B,
    LT_T093C   TYPE STANDARD TABLE OF T093C,
    LS_T093C   TYPE T093C,
    LT_T093T   TYPE STANDARD TABLE OF T093T,
    LS_T093T   TYPE T093T,
    LT_T095    TYPE STANDARD TABLE OF T095,
    LS_T095    TYPE T095,
    LT_T095B   TYPE STANDARD TABLE OF T095B,
    LS_T095B   TYPE T095B,
    LT_SKAT    TYPE STANDARD TABLE OF SKAT,
    LS_SKAT    TYPE SKAT.
  DATA:
    LS_ANLA_TMP  LIKE ANLA,
    LT_ANLB_TMP  TYPE TABLE OF ANLB,
    LT_ANLC_TMP  TYPE TABLE OF ANLC,
    LT_ANEP_TMP  TYPE TABLE OF ANEP,
    LT_ANEA_TMP  TYPE TABLE OF ANEA,
    LT_ANEK_TMP  TYPE TABLE OF ANEK,
    LT_DPOST     TYPE TABLE OF FIAA_DPOST,
    LS_DPOST     TYPE FIAA_DPOST,
    LV_FIELDNAME TYPE FIELDNAME,
    LV_PERAF     TYPE PERAF,
    LV_DATUM     LIKE SY-DATUM.
  FIELD-SYMBOLS: <FS_DEP> TYPE NAFAP,
                 <FS_FLG> TYPE ICON_D.
  "取出资产主数据
  SELECT *
  INTO TABLE LT_ANLA
  FROM ANLA
  FOR ALL ENTRIES IN GT_T001
  WHERE BUKRS = GT_T001-BUKRS
  AND ANLN1 IN S_ANLN1
  AND ANLN2 IN S_ANLN2
  AND ANLKL IN S_ANLKL
*    AND ORD41 IN S_ORD41
  AND TXT50 IN S_TXT50.
  SORT LT_ANLA BY BUKRS ANLN1 ANLN2.

  IF LT_ANLA IS NOT INITIAL.
    SELECT LIFNR
    NAME1
    INTO TABLE GT_LFA1
    FROM LFA1
    FOR ALL ENTRIES IN LT_ANLA
    WHERE LIFNR = LT_ANLA-LIFNR.
  ENDIF.

  "赋值部分值至输出内表
*  MOVE-CORRESPONDING LT_ANLA TO GT_OUTPUT.
  LOOP AT LT_ANLA INTO LS_ANLA.
    CLEAR GS_OUTPUT.
    MOVE-CORRESPONDING LS_ANLA TO GS_OUTPUT.
    APPEND GS_OUTPUT TO GT_OUTPUT.
  ENDLOOP.
  "若不显示不活动资产,则直接DELETE
  IF C_DEAKT IS INITIAL.
    DELETE GT_OUTPUT WHERE DEAKT IS NOT INITIAL.
  ENDIF.

  IF GT_OUTPUT IS NOT INITIAL.
    "取出原值科目
    SELECT *
    INTO TABLE LT_T095
    FROM T095
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE KTOPL = '3000'
    AND KTOGR = GT_OUTPUT-KTOGR
    AND AFABE = P_AFABE.
    SORT LT_T095 BY KTOPL KTOGR AFABE.
    "取出折旧科目
    SELECT *
    INTO TABLE LT_T095B
    FROM T095B
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE KTOPL = '3000'
    AND KTOGR = GT_OUTPUT-KTOGR
    AND AFABE = P_AFABE.
    SORT LT_T095B BY KTOPL KTOGR AFABE.
    "取出科目描述
    SELECT *
    INTO TABLE LT_SKAT
    FROM SKAT
    WHERE SPRAS = SY-LANGU
    AND KTOPL = '3000'.
    SORT LT_SKAT BY SPRAS KTOPL SAKNR.
    "取出资产相关折旧范围数据
    SELECT *
    INTO TABLE LT_ANLB
    FROM ANLB
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE BUKRS = GT_OUTPUT-BUKRS
    AND ANLN1 = GT_OUTPUT-ANLN1
    AND ANLN2 = GT_OUTPUT-ANLN2
    AND AFABE = P_AFABE.
    "有效截止日期排倒序
    SORT LT_ANLB BY BUKRS ANLN1 ANLN2 AFABE BDATU DESCENDING.
    IF LT_ANLB IS NOT INITIAL.
      "为了取折旧范围货币,取出与公司代码相关的折旧范围参数
      SELECT *
      INTO TABLE LT_T093B
      FROM T093B
      FOR ALL ENTRIES IN LT_ANLB
      WHERE BUKRS = LT_ANLB-BUKRS.
      SORT LT_T093B BY BUKRS AFABE.

      "为了取公司代码折旧表AFAPL(用于获取折旧范围相关信息)和当前资产财年LGJAHR(用于计算资产价值数据),取出在资产会计中的公司代码配置
      SELECT *
      INTO TABLE LT_T093C
      FROM T093C
      FOR ALL ENTRIES IN LT_ANLB
      WHERE BUKRS = LT_ANLB-BUKRS.
      SORT LT_T093C BY BUKRS.
      IF LT_T093C IS NOT INITIAL.
        "取出折旧表对应的所有折旧码,其中截止值码用于获取残值率
        SELECT *
        INTO TABLE LT_T090NA
        FROM T090NA
        FOR ALL ENTRIES IN LT_T093C
        WHERE AFAPL = LT_T093C-AFAPL.
        SORT LT_T090NA BY AFAPL AFASL.

        IF LT_T090NA IS NOT INITIAL.
          "根据折旧码对应的截止值码,获取残值率
          SELECT *
          INTO TABLE LT_T091P
          FROM T091P
          FOR ALL ENTRIES IN LT_T090NA
          WHERE ANHWSL = LT_T090NA-ANHWSL.
          SORT LT_T091P BY ANHWSL BGJAHR DESCENDING ZGJAHR DESCENDING.
        ENDIF.
        "获取折旧码名称
        SELECT *
        INTO TABLE LT_T090NAT
        FROM T090NAT
        FOR ALL ENTRIES IN LT_T090NA
        WHERE SPRAS = SY-LANGU
        AND AFAPL = LT_T090NA-AFAPL
        AND AFASL = LT_T090NA-AFASL.
        SORT LT_T090NAT BY AFAPL AFASL.

        "获取折旧范围名称
        SELECT *
        INTO TABLE LT_T093T
        FROM T093T
        FOR ALL ENTRIES IN LT_T093C
        WHERE SPRAS = SY-LANGU
        AND AFAPL = LT_T093C-AFAPL.
        SORT LT_T093T BY AFAPL AFABER.
      ENDIF.
    ENDIF.
    "取出资产年度价值
    SELECT *
    INTO TABLE LT_ANLC
    FROM ANLC
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE BUKRS = GT_OUTPUT-BUKRS
    AND ANLN1 = GT_OUTPUT-ANLN1
    AND ANLN2 = GT_OUTPUT-ANLN2
    AND GJAHR = P_GJAHR
    AND AFABE = P_AFABE.
    SORT LT_ANLC BY BUKRS ANLN1 ANLN2 GJAHR DESCENDING AFABE.

    "取期间过账价值
    SELECT *
    INTO  TABLE LT_ANLP
    FROM ANLP
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE BUKRS = GT_OUTPUT-BUKRS
    AND ANLN1 = GT_OUTPUT-ANLN1
    AND ANLN2 = GT_OUTPUT-ANLN2
    AND GJAHR <= P_GJAHR
    AND AFABER = P_AFABE.
    SORT LT_ANLP BY BUKRS ANLN1 ANLN2 GJAHR DESCENDING PERAF DESCENDING.
    "取出资产过账比例值的行项目,主要用于计算月度折旧
    SELECT *
    INTO TABLE LT_ANEA
    FROM ANEA
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE BUKRS = GT_OUTPUT-BUKRS
    AND ANLN1 = GT_OUTPUT-ANLN1
    AND ANLN2 = GT_OUTPUT-ANLN2
    AND AFABE = P_AFABE.
    SORT LT_ANEA BY BUKRS ANLN1 ANLN2 GJAHR DESCENDING AFABE.

    "取出资产凭证抬头信息,主要用于计算月度折旧
    SELECT *
    INTO TABLE LT_ANEK
    FROM ANEK
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE BUKRS = GT_OUTPUT-BUKRS
    AND ANLN1 = GT_OUTPUT-ANLN1
    AND ANLN2 = GT_OUTPUT-ANLN2.
    SORT LT_ANEK BY BUKRS ANLN1 ANLN2 GJAHR DESCENDING.
    "取出资产过账的行项目,主要用于计算月度折旧
    SELECT *
    INTO TABLE LT_ANEP
    FROM ANEP
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE BUKRS = GT_OUTPUT-BUKRS
    AND ANLN1 = GT_OUTPUT-ANLN1
    AND ANLN2 = GT_OUTPUT-ANLN2
    AND AFABE = P_AFABE.
    SORT LT_ANEP BY BUKRS ANLN1 ANLN2 GJAHR DESCENDING AFABE.

    "取出资产的主号文本信息
    SELECT *
    INTO TABLE LT_ANLH
    FROM ANLH
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE BUKRS = GT_OUTPUT-BUKRS
    AND ANLN1 = GT_OUTPUT-ANLN1.
    SORT LT_ANLH BY BUKRS ANLN1.
    "取出资产与时间相关的分配信息
    SELECT *
    INTO TABLE LT_ANLZ
    FROM ANLZ
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE BUKRS = GT_OUTPUT-BUKRS
    AND ANLN1 = GT_OUTPUT-ANLN1
    AND ANLN2 = GT_OUTPUT-ANLN2.
    "按照时间倒序排序
    SORT LT_ANLZ BY BUKRS ANLN1 ANLN2 BDATU DESCENDING.
    IF LT_ANLZ IS NOT INITIAL.
      "若有内部订单,取出相关的订单信息,主要对应订单描述
      SELECT *
      INTO TABLE LT_AUFK
      FROM AUFK
      FOR ALL ENTRIES IN LT_ANLZ
      WHERE AUFNR = LT_ANLZ-CAUFN.
      SORT LT_AUFK BY AUFNR.

      "对应的成本中心,获取相关的负责人信息
      SELECT *
      INTO TABLE LT_CSKS
      FROM CSKS
      FOR ALL ENTRIES IN LT_ANLZ
      WHERE KOSTL = LT_ANLZ-KOSTL
      AND BUKRS = LT_ANLZ-BUKRS.
      "按时间排倒序
      SORT LT_CSKS BY KOSTL DATBI DESCENDING.

      IF LT_CSKS IS NOT INITIAL.
        "取出成本中心描述信息
        SELECT *
        INTO TABLE LT_CSKT
        FROM CSKT
        FOR ALL ENTRIES IN LT_CSKS
        WHERE SPRAS = SY-LANGU
        AND KOKRS = LT_CSKS-KOKRS
        AND KOSTL = LT_CSKS-KOSTL.
        "按时间排倒序
        SORT LT_CSKT BY KOKRS KOSTL DATBI DESCENDING.
      ENDIF.
    ENDIF.

    "取出资产分类描述
    SELECT *
    INTO TABLE LT_ANKT
    FROM ANKT
    FOR ALL ENTRIES IN GT_OUTPUT
    WHERE SPRAS = SY-LANGU
    AND ANLKL = GT_OUTPUT-ANLKL.
    SORT LT_ANKT BY ANLKL.
    "取出资产小类描述
    SELECT *
    INTO TABLE LT_T087T
    FROM T087T
*      FOR ALL ENTRIES IN gt_output
    WHERE SPRAS = SY-LANGU.
*      AND ordnr = '1'
*      AND ord4x = gt_output-ord41.
    SORT LT_T087T BY ORDNR ORD4X.

    SELECT *
    FROM T087S
    INTO TABLE @DATA(LT_T087S)
          WHERE SPRAS = @SY-LANGU.

    SORT LT_T087S BY GDLGRP.
  ENDIF.

  "开始整理和计算
  LOOP AT GT_OUTPUT ASSIGNING <FS_OUTPUT>.
    "公司代码
    "资产编号
    "资产次级编号
    "资产名称
    "资产分类
    "资产分类名称
    READ TABLE LT_ANKT INTO LS_ANKT WITH KEY ANLKL = <FS_OUTPUT>-ANLKL BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-TXK20 = LS_ANKT-TXK20.
    ENDIF.
    "使用状态
    READ TABLE LT_T087T INTO LS_T087T WITH KEY ORDNR = '1' ORD4X = <FS_OUTPUT>-ORD41 BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-ORD41_T = LS_T087T-ORDTX.
    ENDIF.
    "资产性质
    READ TABLE LT_T087T INTO LS_T087T WITH KEY ORDNR = '2' ORD4X = <FS_OUTPUT>-ORD42 BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-ORD42_T = LS_T087T-ORDTX.
    ENDIF.
    "资产来源
    READ TABLE LT_T087T INTO LS_T087T WITH KEY ORDNR = '3' ORD4X = <FS_OUTPUT>-ORD43 BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-ORD43_T = LS_T087T-ORDTX.
    ENDIF.
    "资金来源
    READ TABLE LT_T087T INTO LS_T087T WITH KEY ORDNR = '4' ORD4X = <FS_OUTPUT>-ORD44 BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-ORD44_T = LS_T087T-ORDTX.
    ENDIF.
    "
    READ TABLE LT_T087S INTO DATA(LS_T087S) WITH KEY GDLGRP = <FS_OUTPUT>-GDLGRP BINARY SEARCH.
    IF SY-SUBRC EQ 0.
      <FS_OUTPUT>-GDLGRP_T = LS_T087S-GDLGRP_TXT.
    ENDIF.
    "规格参数/附加资产描述
    "资产主号文本
    READ TABLE LT_ANLH INTO LS_ANLH WITH KEY BUKRS = <FS_OUTPUT>-BUKRS ANLN1 = <FS_OUTPUT>-ANLN1 BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-ANLHTXT = LS_ANLH-ANLHTXT.
    ENDIF.
    "序列号/旧资产号码
    "存货号
    "数量
    "计量单位

    "原值科目
    READ TABLE LT_T095 INTO LS_T095 WITH KEY KTOGR = <FS_OUTPUT>-KTOGR BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-KTANSW = LS_T095-KTANSW.
    ENDIF.
    "原值科目描述
    READ TABLE LT_SKAT INTO LS_SKAT WITH KEY SAKNR = <FS_OUTPUT>-KTANSW BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-KTANSW_TXT = LS_SKAT-TXT50.
    ENDIF.
    "累计折旧科目
    "折旧费科目
    READ TABLE LT_T095B INTO LS_T095B WITH KEY KTOGR = <FS_OUTPUT>-KTOGR BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-KTNAFB = LS_T095B-KTNAFB.
      <FS_OUTPUT>-KTNAFG = LS_T095B-KTNAFG.
    ENDIF.
    "累计折旧科目描述
    READ TABLE LT_SKAT INTO LS_SKAT WITH KEY SAKNR = <FS_OUTPUT>-KTNAFB BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-KTNAFB_TXT = LS_SKAT-TXT50.
    ENDIF.
    "折旧费科目描述
    READ TABLE LT_SKAT INTO LS_SKAT WITH KEY SAKNR = <FS_OUTPUT>-KTNAFG BINARY SEARCH.
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-KTNAFG_TXT = LS_SKAT-TXT50.
    ENDIF.

    "与时间相关的分配信息,不需要BINARY SEARCH,因为前面已经按时间排倒序,直接READ;主要考虑全部显示为最新信息,如需要看详细的时间间隔,建议到AS03查看
    READ TABLE LT_ANLZ INTO LS_ANLZ WITH KEY BUKRS = <FS_OUTPUT>-BUKRS ANLN1 = <FS_OUTPUT>-ANLN1 ANLN2 = <FS_OUTPUT>-ANLN2.
    IF SY-SUBRC = 0.
      "成本中心
      <FS_OUTPUT>-KOSTL = LS_ANLZ-KOSTL.
      READ TABLE LT_CSKS INTO LS_CSKS WITH KEY KOSTL = <FS_OUTPUT>-KOSTL BUKRS = <FS_OUTPUT>-BUKRS.
      IF SY-SUBRC = 0.
        "负责人
        <FS_OUTPUT>-VERAK = LS_CSKS-VERAK.
        READ TABLE LT_CSKT INTO LS_CSKT WITH KEY KOKRS = LS_CSKS-KOKRS KOSTL = LS_CSKS-KOSTL.
        IF SY-SUBRC = 0.
          "成本中心描述
          <FS_OUTPUT>-KOSTL_TXT = LS_CSKT-KTEXT.
        ENDIF.
      ENDIF.
      "内部订单'
      <FS_OUTPUT>-CAUFN = LS_ANLZ-CAUFN.
      READ TABLE LT_AUFK INTO LS_AUFK WITH KEY AUFNR = <FS_OUTPUT>-CAUFN BINARY SEARCH.
      IF SY-SUBRC = 0.
        "内部订单描述
        <FS_OUTPUT>-AUFNR_TXT = LS_AUFK-KTEXT.
      ENDIF.
      "资产保管人
      <FS_OUTPUT>-RAUMN = LS_ANLZ-RAUMN.
      "执照牌号
      <FS_OUTPUT>-KFZKZ = LS_ANLZ-KFZKZ.
    ENDIF.
    "供应商
    "供应商描述
    READ TABLE GT_LFA1 INTO GW_LFA1 WITH KEY LIFNR = <FS_OUTPUT>-LIFNR.
    IF SY-SUBRC EQ 0.
      <FS_OUTPUT>-NAME1 = GW_LFA1-NAME1.
    ENDIF.
    "制造商
    "资本化日期
    "不活动日期
    "资产折旧范围数据和时间有关,取最新的折旧范围记录;剩余使用期间一律按照最新的计算
    READ TABLE LT_ANLB INTO LS_ANLB WITH KEY BUKRS = <FS_OUTPUT>-BUKRS ANLN1 = <FS_OUTPUT>-ANLN1 ANLN2 = <FS_OUTPUT>-ANLN2.
    IF SY-SUBRC = 0.
      "折旧范围
      <FS_OUTPUT>-AFABE = LS_ANLB-AFABE.
      "折旧方法
      <FS_OUTPUT>-AFASL = LS_ANLB-AFASL.

      READ TABLE LT_T093C INTO LS_T093C WITH KEY BUKRS = <FS_OUTPUT>-BUKRS BINARY SEARCH.
      IF SY-SUBRC = 0.
        READ TABLE LT_T093T INTO LS_T093T WITH KEY AFAPL = LS_T093C-AFAPL AFABER = <FS_OUTPUT>-AFABE BINARY SEARCH.
        IF SY-SUBRC = 0.
          "折旧范围说明
          <FS_OUTPUT>-AFBKTX = LS_T093T-AFBKTX.
        ENDIF.
        READ TABLE LT_T090NA INTO LS_T090NA WITH KEY AFAPL = LS_T093C-AFAPL AFASL = <FS_OUTPUT>-AFASL BINARY SEARCH.
        IF SY-SUBRC = 0.
          READ TABLE LT_T091P INTO LS_T091P WITH KEY ANHWSL = LS_T090NA-ANHWSL BINARY SEARCH.
          IF SY-SUBRC = 0.
            "残值率(%),优先级LOW:折旧方法对应截止值码残值率
            <FS_OUTPUT>-AHPROZ = LS_T091P-AHPROZ.
          ENDIF.
        ENDIF.
        READ TABLE LT_T090NAT INTO LS_T090NAT WITH KEY AFAPL = LS_T093C-AFAPL AFASL = <FS_OUTPUT>-AFASL BINARY SEARCH.
        IF SY-SUBRC = 0.
          "折旧方法说明
          <FS_OUTPUT>-AFATXT = LS_T090NAT-AFATXT.
        ENDIF.
      ENDIF.
      "开始折旧日期
      <FS_OUTPUT>-AFABG = LS_ANLB-AFABG.
      "计划使用年限
      <FS_OUTPUT>-NDJAR = LS_ANLB-NDJAR.
      "计划使用期间
      <FS_OUTPUT>-NDPER = LS_ANLB-NDPER.
      "残值,优先级MEDIUM,取折旧范围自定义残值
      IF LS_ANLB-SCHRW IS NOT INITIAL.
        <FS_OUTPUT>-RSDVAL = LS_ANLB-SCHRW.
      ENDIF.
      "残值率(%),优先级HIGH:资产折旧范围定义的残值率
      IF LS_ANLB-SCHRW_PROZ IS NOT INITIAL.
        <FS_OUTPUT>-AHPROZ = LS_ANLB-SCHRW_PROZ.
      ENDIF.
      "货币
      READ TABLE LT_T093B INTO LS_T093B WITH KEY BUKRS = <FS_OUTPUT>-BUKRS AFABE = <FS_OUTPUT>-AFABE BINARY SEARCH.
      IF SY-SUBRC = 0.
        <FS_OUTPUT>-WAERS = LS_T093B-WAERS.
      ENDIF.
    ENDIF.
    "资产价值计算,取公司代码下当前资产财年的价值段进行计算
    READ TABLE LT_ANLC INTO LS_ANLC WITH KEY BUKRS = <FS_OUTPUT>-BUKRS ANLN1 = <FS_OUTPUT>-ANLN1 ANLN2 = <FS_OUTPUT>-ANLN2 GJAHR = P_GJAHR AFABE = <FS_OUTPUT>-AFABE BINARY SEARCH.  "GJAHR = LS_T093C-LGJAHR
    IF SY-SUBRC = 0.
      <FS_OUTPUT>-ORGVAL = LS_ANLC-KANSW"累积购置和生产费用
      + LS_ANLC-KAUFW"重置价值的累计重估
      + LS_ANLC-AUFWB"重置价值的重估记帐
      + LS_ANLC-ANSWL."该年度影响资产值的业务
      <FS_OUTPUT>-ACCDEP = LS_ANLC-KNAFA"累计正常折旧
      + LS_ANLC-KSAFA"累计特殊折旧
      + LS_ANLC-KAUFN"正常折旧的累积重估
      + LS_ANLC-NAFAG"记帐在当前年的正常折旧
      + LS_ANLC-SAFAG"在当前财会年度中的记帐的特别折旧
      + LS_ANLC-ZUSNA"在正常折旧上的价值增加
      + LS_ANLC-ZUSSA"在特别折旧上的价值增加
      + LS_ANLC-AUFWV"有关替换值的比例累积重估
      + LS_ANLC-NAFAV"比例累积正常折旧
      + LS_ANLC-SAFAV"比例累计特别折旧
      + LS_ANLC-AUFNV"有关正常折旧的比例累积重估
      + LS_ANLC-NAFAL"此年的比例正常折旧
      + LS_ANLC-SAFAL"此年的比例特别折旧
      + LS_ANLC-AUFNL"此年正常折旧的比例重估
      + LS_ANLC-KAAFA"累积计划外折旧
      + LS_ANLC-KMAFA"累计准备金转帐
      + LS_ANLC-AAFAG"有关年的计划外折旧记帐
      + LS_ANLC-MAFAG"减少年度过帐折旧的购置价值
      + LS_ANLC-ZUSAA"在无计划折旧上的价值增加
      + LS_ANLC-ZUSMA"增价已转帐的准备金
      + LS_ANLC-AAFAV"比例的累积计划外折旧
      + LS_ANLC-MAFAV"预定的比例累积转帐
      + LS_ANLC-AAFAL"此年的比例计划外折旧
      + LS_ANLC-MAFAL."当年储备金按比例结转
*      <FS_OUTPUT>-ACCDEP = LS_ANLC-KNAFA"累计正常折旧
*                           + LS_ANLC-KSAFA"累计特殊折旧
*                           + LS_ANLC-KAUFN"正常折旧的累积重估
*                           + LS_ANLC-NAFAG"记帐在当前年的正常折旧
*                           + LS_ANLC-SAFAG"在当前财会年度中的记帐的特别折旧
*                           + LS_ANLC-ZUSNA"在正常折旧上的价值增加
*                           + LS_ANLC-ZUSSA"在特别折旧上的价值增加
*                           + LS_ANLC-AUFWV"有关替换值的比例累积重估
*                           + LS_ANLC-NAFAV"比例累积正常折旧
*                           + LS_ANLC-SAFAV"比例累计特别折旧
*                           + LS_ANLC-AUFNV"有关正常折旧的比例累积重估
*                           + LS_ANLC-NAFAL"此年的比例正常折旧
*                           + LS_ANLC-SAFAL"此年的比例特别折旧
*                           + LS_ANLC-AUFNL."此年正常折旧的比例重估
*      <FS_OUTPUT>-IPMLSS = LS_ANLC-KAAFA"累积计划外折旧
*                           + LS_ANLC-KMAFA"累计准备金转帐
*                           + LS_ANLC-AAFAG"有关年的计划外折旧记帐
*                           + LS_ANLC-MAFAG"减少年度过帐折旧的购置价值
*                           + LS_ANLC-ZUSAA"在无计划折旧上的价值增加
*                           + LS_ANLC-ZUSMA"增价已转帐的准备金
*                           + LS_ANLC-AAFAV"比例的累积计划外折旧
*                           + LS_ANLC-MAFAV"预定的比例累积转帐
*                           + LS_ANLC-AAFAL"此年的比例计划外折旧
*                           + LS_ANLC-MAFAL."当年储备金按比例结转
      "净值=原值-累计折旧-减值准备(累计折旧、减值准备时取出贷方以负数表示)
*      <FS_OUTPUT>-NETVAL = <FS_OUTPUT>-ORGVAL + <FS_OUTPUT>-ACCDEP + <FS_OUTPUT>-IPMLSS.
      <FS_OUTPUT>-NETVAL = <FS_OUTPUT>-ORGVAL + <FS_OUTPUT>-ACCDEP.
      "对于期间时点数
      "原值
      "累计折旧
      <FS_OUTPUT>-ORGVAL_MONTH = <FS_OUTPUT>-ORGVAL.
      <FS_OUTPUT>-ACCDEP_MONTH = <FS_OUTPUT>-ACCDEP.
      "把大于期间的ANEP扣除
      LOOP AT LT_ANEP INTO LS_ANEP WHERE BUKRS = <FS_OUTPUT>-BUKRS
      AND ANLN1 = <FS_OUTPUT>-ANLN1
      AND ANLN2 = <FS_OUTPUT>-ANLN2
      AND GJAHR = P_GJAHR
      AND AFABE = <FS_OUTPUT>-AFABE
      AND BZDAT+4(2) > P_PERAF.
        <FS_OUTPUT>-ORGVAL_MONTH = <FS_OUTPUT>-ORGVAL_MONTH - LS_ANEP-ANBTR.
        READ TABLE LT_ANEA INTO LS_ANEA WITH KEY BUKRS = LS_ANEP-BUKRS
        ANLN1 = LS_ANEP-ANLN1
        ANLN2 = LS_ANEP-ANLN2
        GJAHR = LS_ANEP-GJAHR
        LNRAN = LS_ANEP-LNRAN
        AFABE = LS_ANEP-AFABE.
        IF SY-SUBRC = 0.
          <FS_OUTPUT>-ACCDEP_MONTH = <FS_OUTPUT>-ACCDEP_MONTH -
          (  LS_ANEA-AUFWV"有关替换值的比例累积重估
          + LS_ANEA-NAFAV"比例累积正常折旧
          + LS_ANEA-SAFAV"比例累计特别折旧
          + LS_ANEA-AUFNV"有关正常折旧的比例累积重估
          + LS_ANEA-NAFAL"此年的比例正常折旧
          + LS_ANEA-SAFAL"此年的比例特别折旧
          + LS_ANEA-AUFNL"此年正常折旧的比例重估
          + LS_ANEA-AAFAV"比例的累积计划外折旧
          + LS_ANEA-MAFAV"预定的比例累积转帐
          + LS_ANEA-AAFAL"此年的比例计划外折旧
          + LS_ANEA-MAFAL )."当年储备金按比例结转
        ENDIF.
      ENDLOOP.
*      "就把大于期间的ANLP全部扣除
      LOOP AT LT_ANLP INTO LS_ANLP WHERE BUKRS = <FS_OUTPUT>-BUKRS
      AND GJAHR = P_GJAHR
      AND PERAF > P_PERAF
      AND ANLN1 = <FS_OUTPUT>-ANLN1
      AND ANLN2 = <FS_OUTPUT>-ANLN2
      AND AFABER = <FS_OUTPUT>-AFABE.
        <FS_OUTPUT>-ACCDEP_MONTH = <FS_OUTPUT>-ACCDEP_MONTH -
        ( LS_ANLP-NAFAZ
        + LS_ANLP-SAFAZ
        + LS_ANLP-AAFAZ
        + LS_ANLP-MAFAZ
        + LS_ANLP-ZINSZ ).
      ENDLOOP.
      <FS_OUTPUT>-NETVAL_MONTH = <FS_OUTPUT>-ORGVAL_MONTH + <FS_OUTPUT>-ACCDEP_MONTH.
      "残值重计算
      IF LS_ANLB-SCHRW_PROZ IS NOT INITIAL.
        "残值,优先级HIGH,原值*折旧范围数据残值率
        <FS_OUTPUT>-RSDVAL = <FS_OUTPUT>-ORGVAL / 100 * LS_ANLB-SCHRW_PROZ.
      ELSEIF LS_ANLB-SCHRW IS INITIAL.
        "残值,优先级LOW,原值*折旧方法截止码残值率
        <FS_OUTPUT>-RSDVAL = <FS_OUTPUT>-ORGVAL / 100 * LS_T091P-AHPROZ.
      ENDIF.
      "残值率重计算
      IF LS_ANLB-SCHRW_PROZ IS INITIAL AND LS_ANLB-SCHRW IS NOT INITIAL.
        "残值率(%),优先级MEDIUM:折旧范围自定义残值 / 资产原值
        <FS_OUTPUT>-AHPROZ = LS_ANLB-SCHRW / <FS_OUTPUT>-ORGVAL * 100.
      ENDIF.
    ENDIF.
    "期间的计算,全部对应自然月,虽然SAP可能出现365个折旧期间,但是按照12个期间计算
    "已计提期间
*    <FS_OUTPUT>-USDPER = LS_ANLC-NDABJ * 12 + LS_ANLC-NDABP + LS_ANLC-AFBLPE.
    DATA: LV_LASTYEAR TYPE GJAHR,
          LV_BEGDA    LIKE SY-DATUM,
          LV_ENDDA    LIKE SY-DATUM,
          LV_MONTHS   TYPE I.
    CLEAR: LV_LASTYEAR,
    LV_BEGDA,
    LV_ENDDA,
    LV_MONTHS.
    IF <FS_OUTPUT>-NDJAR = 0 AND <FS_OUTPUT>-NDPER = 0.
      "在建工程,全部都是0
      <FS_OUTPUT>-USDPER = 0.
      <FS_OUTPUT>-RMNPER = 0.
    ELSE.
      CONCATENATE <FS_OUTPUT>-AFABG+0(4) <FS_OUTPUT>-AFABG+4(2) '01' INTO LV_BEGDA.
      READ TABLE LT_ANLP INTO LS_ANLP WITH KEY BUKRS = <FS_OUTPUT>-BUKRS ANLN1 = <FS_OUTPUT>-ANLN1 ANLN2 = <FS_OUTPUT>-ANLN2 AFABER = <FS_OUTPUT>-AFABE.
      IF SY-SUBRC = 0.
        "运行过折旧的,以最后折旧日期来计算
        CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
          EXPORTING
            I_GJAHR        = LS_ANLP-GJAHR
*           I_MONMIT       = 00
            I_PERIV        = 'K4'
            I_POPER        = LS_ANLP-PERAF
          IMPORTING
            E_DATE         = LV_ENDDA
          EXCEPTIONS
            INPUT_FALSE    = 1
            T009_NOTFOUND  = 2
            T009B_NOTFOUND = 3
            OTHERS         = 4.
        IF SY-SUBRC <> 0.
*   Implement suitable error handling here
        ENDIF.
      ELSE.
        "从未折旧过的,看下开始折旧日期是否为本年以前
        IF <FS_OUTPUT>-AFABG+0(4) < P_GJAHR.
          "本年以前的资产,使用去年最后一天计算
          LV_LASTYEAR = P_GJAHR - 1.
          CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
            EXPORTING
              I_GJAHR        = LV_LASTYEAR
*             I_MONMIT       = 00
              I_PERIV        = 'K4'
              I_POPER        = '12'
            IMPORTING
              E_DATE         = LV_ENDDA
            EXCEPTIONS
              INPUT_FALSE    = 1
              T009_NOTFOUND  = 2
              T009B_NOTFOUND = 3
              OTHERS         = 4.
          IF SY-SUBRC <> 0.
*     Implement suitable error handling here
          ENDIF.
        ELSE."本年及以后的资产,使用折旧开始日期计算
          LV_ENDDA = LV_BEGDA.
        ENDIF.
      ENDIF.
      CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'
        EXPORTING
          BEGDA    = LV_BEGDA
          ENDDA    = LV_ENDDA
*         TAB_MODE = ' '
        IMPORTING
*         DAYS     =
*         C_WEEKS  =
*         C_MONTHS =
*         C_YEARS  =
*         WEEKS    =
*         MONTHS   =
*         YEARS    =
          D_MONTHS = LV_MONTHS
*         MONTH_TAB =
        .
      IF LV_MONTHS < 0.
        <FS_OUTPUT>-USDPER = 0.
      ELSEIF LV_MONTHS > <FS_OUTPUT>-NDJAR * 12 + <FS_OUTPUT>-NDPER.
        <FS_OUTPUT>-USDPER = <FS_OUTPUT>-NDJAR * 12 + <FS_OUTPUT>-NDPER.
      ELSE.
        <FS_OUTPUT>-USDPER = LV_MONTHS.
      ENDIF.
      "判断这个期间是否已经跑过折旧了
      READ TABLE LT_ANLP INTO LS_ANLP WITH KEY BUKRS = <FS_OUTPUT>-BUKRS GJAHR = P_GJAHR PERAF = P_PERAF ANLN1 = <FS_OUTPUT>-ANLN1 ANLN2 = <FS_OUTPUT>-ANLN2 AFABER = <FS_OUTPUT>-AFABE.
      IF SY-SUBRC = 0.
        "跑过了,就按照这个期间为最后折旧期间来计算
        CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
          EXPORTING
            I_GJAHR        = LS_ANLP-GJAHR
*           I_MONMIT       = 00
            I_PERIV        = 'K4'
            I_POPER        = LS_ANLP-PERAF
          IMPORTING
            E_DATE         = LV_ENDDA
          EXCEPTIONS
            INPUT_FALSE    = 1
            T009_NOTFOUND  = 2
            T009B_NOTFOUND = 3
            OTHERS         = 4.
        IF SY-SUBRC <> 0.
*   Implement suitable error handling here
        ENDIF.
        CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'
          EXPORTING
            BEGDA    = LV_BEGDA
            ENDDA    = LV_ENDDA
*           TAB_MODE = ' '
          IMPORTING
*           DAYS     =
*           C_WEEKS  =
*           C_MONTHS =
*           C_YEARS  =
*           WEEKS    =
*           MONTHS   =
*           YEARS    =
            D_MONTHS = LV_MONTHS
*           MONTH_TAB =
          .
        IF LV_MONTHS < 0.
          <FS_OUTPUT>-USDPER_MONTH = 0.
        ELSEIF LV_MONTHS > <FS_OUTPUT>-NDJAR * 12 + <FS_OUTPUT>-NDPER.
          <FS_OUTPUT>-USDPER_MONTH = <FS_OUTPUT>-NDJAR * 12 + <FS_OUTPUT>-NDPER.
        ELSE.
          <FS_OUTPUT>-USDPER_MONTH = LV_MONTHS.
        ENDIF.
      ELSE.
        "没跑过,时点期间等于实时的期间
        <FS_OUTPUT>-USDPER_MONTH = <FS_OUTPUT>-USDPER.
      ENDIF.
      "剩余计提期间
      <FS_OUTPUT>-RMNPER = <FS_OUTPUT>-NDJAR * 12 + <FS_OUTPUT>-NDPER - <FS_OUTPUT>-USDPER.
      "时点剩余计提期间
      <FS_OUTPUT>-RMNPER_MONTH = <FS_OUTPUT>-NDJAR * 12 + <FS_OUTPUT>-NDPER - <FS_OUTPUT>-USDPER_MONTH.
    ENDIF.
    "资产财年
    <FS_OUTPUT>-GJAHR = P_GJAHR.

    "调用函数AMS2I_SHOW_POST_DEPR进行资产财年的折旧计算时,由于传入参数含折旧范围、会计年度,资产价值段、资产过账行项目的筛选不加入折旧范围、年度、时间;
    READ TABLE LT_ANLA INTO LS_ANLA_TMP WITH KEY BUKRS = <FS_OUTPUT>-BUKRS ANLN1 = <FS_OUTPUT>-ANLN1 ANLN2 = <FS_OUTPUT>-ANLN2 BINARY SEARCH.
    MOVE LT_ANLB TO LT_ANLB_TMP.
    DELETE LT_ANLB_TMP WHERE NOT ( BUKRS = <FS_OUTPUT>-BUKRS AND ANLN1 = <FS_OUTPUT>-ANLN1 AND ANLN2 = <FS_OUTPUT>-ANLN2 ).
    MOVE LT_ANLC TO LT_ANLC_TMP.
    DELETE LT_ANLC_TMP WHERE NOT ( BUKRS = <FS_OUTPUT>-BUKRS AND ANLN1 = <FS_OUTPUT>-ANLN1 AND ANLN2 = <FS_OUTPUT>-ANLN2 ).
    MOVE LT_ANEP TO LT_ANEP_TMP.
    DELETE LT_ANEP_TMP WHERE NOT ( BUKRS = <FS_OUTPUT>-BUKRS AND ANLN1 = <FS_OUTPUT>-ANLN1 AND ANLN2 = <FS_OUTPUT>-ANLN2 ).
    MOVE LT_ANEA TO LT_ANEA_TMP.
    DELETE LT_ANEA_TMP WHERE NOT ( BUKRS = <FS_OUTPUT>-BUKRS AND ANLN1 = <FS_OUTPUT>-ANLN1 AND ANLN2 = <FS_OUTPUT>-ANLN2 ).
    MOVE LT_ANEK TO LT_ANEK_TMP.
    DELETE LT_ANEK_TMP WHERE NOT ( BUKRS = <FS_OUTPUT>-BUKRS AND ANLN1 = <FS_OUTPUT>-ANLN1 AND ANLN2 = <FS_OUTPUT>-ANLN2 ).
*    CALL FUNCTION 'AMS2I_SHOW_POST_DEPR'
*      EXPORTING
*        I_ANLA  = LS_ANLA_TMP
*        I_AFABE = <FS_OUTPUT>-AFABE
*        I_GJAHR = <FS_OUTPUT>-GJAHR
**       I_SIMU  =
*      TABLES
*        T_DPOST = LT_DPOST
**       T_ANLBZA =
*        T_ANLB  = LT_ANLB_TMP
*        T_ANLC  = LT_ANLC_TMP
*        T_ANEP  = LT_ANEP_TMP
*        T_ANEA  = LT_ANEA_TMP
*        T_ANEK  = LT_ANEK_TMP
**       T_ANFM  =
**   EXCEPTIONS
**       NOT_FOUND                    = 1
**       DIFFERENCES_POSTED_AFA       = 2
**       OTHERS  = 3
*      .
*    IF SY-SUBRC <> 0.
** Implement suitable error handling here
*    ENDIF.
    "ECC只能使用函数AM_SHOW_POST_DEPR
    CALL FUNCTION 'AM_SHOW_POST_DEPR'
      EXPORTING
        I_ANLA  = LS_ANLA_TMP
        I_AFABE = <FS_OUTPUT>-AFABE
        I_GJAHR = <FS_OUTPUT>-GJAHR
*       I_SIMU  =
      TABLES
        T_DPOST = LT_DPOST
        T_ANLB  = LT_ANLB_TMP
        T_ANLC  = LT_ANLC_TMP
        T_ANEP  = LT_ANEP_TMP
        T_ANEA  = LT_ANEA_TMP
        T_ANEK  = LT_ANEK_TMP
*       T_ANFM  =
*       T_ANLBZA                     =
*     EXCEPTIONS
*       NOT_FOUND                    = 1
*       DIFFERENCES_POSTED_AFA       = 2
*       OTHERS  = 3
      .
    IF SY-SUBRC <> 0.
* Implement suitable error handling here
    ENDIF.


    "默认初始12个期间的过账标识为无过账
    CLEAR LV_PERAF.
    DO 12 TIMES.
      LV_PERAF = LV_PERAF + 1.
      CONCATENATE '<FS_OUTPUT>-FLG_'  LV_PERAF INTO LV_FIELDNAME.
      ASSIGN (LV_FIELDNAME) TO <FS_FLG>.
      IF <FS_FLG> IS ASSIGNED..
        <FS_FLG> = '@BZ@'.
      ENDIF.
    ENDDO.
    "根据调用函数得到资产财年折旧计划/实际数据,分配至12个期间的过账字段
    LOOP AT LT_DPOST INTO LS_DPOST WHERE AFABER = <FS_OUTPUT>-AFABE.
      CONCATENATE '<FS_OUTPUT>-DEP_'  LS_DPOST-PERAF INTO LV_FIELDNAME.
      ASSIGN (LV_FIELDNAME) TO <FS_DEP>.
      CONCATENATE '<FS_OUTPUT>-FLG_'  LS_DPOST-PERAF INTO LV_FIELDNAME.
      ASSIGN (LV_FIELDNAME) TO <FS_FLG>.
      IF <FS_DEP> IS ASSIGNED.
        "期间折旧=正常折旧+特殊折旧+计划外折旧+转帐准备金+利息+重置值重估+正常折旧重估
        <FS_DEP> = <FS_DEP> + LS_DPOST-NAFAZ + LS_DPOST-SAFAZ + LS_DPOST-AAFAZ + LS_DPOST-MAFAZ + LS_DPOST-ZINSZ + LS_DPOST-AUFWZ + LS_DPOST-AUFNZ.
        "累计到年度折旧
        <FS_OUTPUT>-CURDEP =  <FS_OUTPUT>-CURDEP + LS_DPOST-NAFAZ + LS_DPOST-SAFAZ + LS_DPOST-AAFAZ + LS_DPOST-MAFAZ + LS_DPOST-ZINSZ + LS_DPOST-AUFWZ + LS_DPOST-AUFNZ.
        IF <FS_FLG> IS ASSIGNED..
          IF LS_DPOST-XFELD = 'X' AND <FS_FLG> <> '@5D'.
            "已过账,如果已存在了一条未过账,就不更新了
            <FS_FLG> = '@5B@'.
          ELSEIF LS_DPOST-XFELD = SPACE.
            "已计划
            <FS_FLG> = '@5D@'.
          ELSEIF LS_DPOST-XFELD ='A' AND <FS_FLG> <> '@5D'.
            "来自历史资产的转账传输
            <FS_FLG> = '@KB@'.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDLOOP.
    CLEAR: LT_DPOST.
  ENDLOOP.
  SORT GT_OUTPUT BY BUKRS ANLN1 ANLN2.
ENDFORM.                    "FRM_GET_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DISPLAY_ALV .

  PERFORM FRM_SET_LAYOUT.

  PERFORM FRM_SET_FIELDCAT.

  PERFORM FRM_SET_SORT.

  PERFORM FRM_CHECK_DEPRECIATION.

  PERFORM FRM_DISPLAY_DETAIL.


ENDFORM.                    "FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_SET_LAYOUT .
*  交叉底纹
  GS_LAYOUT-ZEBRA = ABAP_TRUE.
*  适应列宽
  GS_LAYOUT-CWIDTH_OPT = ABAP_TRUE.
*  禁用单元格合并
  GS_LAYOUT-NO_MERGING = ABAP_TRUE.
*  选择方式
  GS_LAYOUT-SEL_MODE = 'A'.
*  选择字段
  GS_LAYOUT-BOX_FNAME = 'SELECT'.
ENDFORM.                    "FRM_SET_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_SET_FIELDCAT .

*GET_FIELDCAT '' 'SELECT' TEXT-000 '' '' ''.
  GET_FIELDCAT '' 'BUKRS'         TEXT-001 'BUKRS' 'ANLA' ''.
  GET_FIELDCAT '' 'ANLN1'         TEXT-002 'ANLN1' 'ANLA' ''.
  GET_FIELDCAT '' 'ANLN2'         TEXT-003 'ANLN2' 'ANLA' ''.
  GET_FIELDCAT '' 'TXT50'         TEXT-004 'TXT50' 'ANLA' ''.
  GET_FIELDCAT '' 'ANLKL'         TEXT-005 'ANLKL' 'ANLA' ''.
  GET_FIELDCAT '' 'TXK20'         TEXT-006 'TXK50' 'ANAT' ''.
  GET_FIELDCAT '' 'ANLHTXT'       TEXT-007 'ANLHTXT' 'ANLH' ''.
  GET_FIELDCAT '' 'SERNR'         TEXT-073 'SERNR' 'ANLA' ''.
  GET_FIELDCAT '' 'AIBN1'         TEXT-008 'AIBN1' 'ANLA' ''.
  GET_FIELDCAT '' 'AIBN2'         TEXT-009 'AIBN2' 'ANLA' ''.
  GET_FIELDCAT '' 'MENGE'         TEXT-010 'MENGE' 'ANLA' 'QUAN'.
  GET_FIELDCAT '' 'MEINS'         TEXT-011 'MEINS' 'ANLA' ''.
  GET_FIELDCAT '' 'KOSTL'         TEXT-012 'KOSTL' 'ANLZ' ''.
  GET_FIELDCAT '' 'KOSTL_TXT'     TEXT-013 'KTEXT' 'CKST' ''.
  GET_FIELDCAT '' 'VERAK'         TEXT-014 'VERAK' 'CSKS' ''.
  GET_FIELDCAT '' 'CAUFN'         TEXT-015 'CAUFN' 'ANLZ' ''.
  GET_FIELDCAT '' 'AUFNR_TXT'     TEXT-016 'KTEXT' 'AUFK' ''.
  GET_FIELDCAT '' 'LIFNR'         TEXT-017 'LIFNR' 'ANLA' ''.
  GET_FIELDCAT '' 'NAME1'         TEXT-018 'NAME1' 'LFA1' ''.
  GET_FIELDCAT '' 'AKTIV'         TEXT-019 'AKTIV' 'ANLA' ''.
  GET_FIELDCAT '' 'ORD41'         '使用状态' 'ORD41' 'ANLA' ''.
  GET_FIELDCAT '' 'ORD41_T'       '使用状态' '' '' ''.
  GET_FIELDCAT '' 'ORD42'         '资产性质' 'ORD42' 'ANLA' ''.
  GET_FIELDCAT '' 'ORD42_T'       '资产性质' '' '' ''.
  GET_FIELDCAT '' 'ORD43'         '资产来源' 'ORD43' 'ANLA' ''.
  GET_FIELDCAT '' 'ORD43_T'       '资产来源' '' '' ''.
  GET_FIELDCAT '' 'ORD44'         '资金来源' 'ORD44' 'ANLA' ''.
  GET_FIELDCAT '' 'ORD44_T'       '资金来源' '' '' ''.
  GET_FIELDCAT '' 'GDLGRP'        '明细分类' 'GDLGRP' 'ANLA' ''.
  GET_FIELDCAT '' 'GDLGRP_T'      '明细分类' '' '' ''.

  GET_FIELDCAT '' 'AFABE'         TEXT-020 'AFABE' 'ANLB' ''.
  GET_FIELDCAT '' 'AFBKTX'        TEXT-021 'AFBKTX' 'T093T' ''.
  GET_FIELDCAT '' 'AFASL'         TEXT-022 'AFASL' 'ANLB' ''.
  GET_FIELDCAT '' 'AFATXT'        TEXT-023 'AFATXT' 'T090NAT' ''.
  GET_FIELDCAT '' 'AFABG'         TEXT-024 'AFABG' 'ANLB' ''.
  GET_FIELDCAT '' 'NDJAR'         TEXT-025 'NDJAR' 'ANLB' ''.
  GET_FIELDCAT '' 'NDPER'         TEXT-026 'NDPER' 'ANLB' ''.
  GET_FIELDCAT '' 'USDPER'        TEXT-027 'NDPER' 'ANLB' ''.
  GET_FIELDCAT '' 'RMNPER'        TEXT-028 'NDPER' 'ANLB' ''.
  GET_FIELDCAT '' 'ORGVAL'        TEXT-029 'KANSW' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'ACCDEP'        TEXT-030 'KNAFA' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'NETVAL'        TEXT-031 'KANSW' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'RSDVAL'        TEXT-032 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'AHPROZ'        TEXT-033 'AHPROZ' 'T091P' ''.
  GET_FIELDCAT '' 'USDPER_MONTH'  TEXT-034 'NDPER' 'ANLB' ''.
  GET_FIELDCAT '' 'RMNPER_MONTH'  TEXT-035 'NDPER' 'ANLB' ''.
  GET_FIELDCAT '' 'ORGVAL_MONTH'  TEXT-036 'KANSW' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'ACCDEP_MONTH'  TEXT-037 'KNAFA' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'NETVAL_MONTH'  TEXT-038 'KANSW' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'KTOGR'         TEXT-039 'KTOGR' 'ANLA' ''.
  GET_FIELDCAT '' 'KTANSW'        TEXT-040 'KTANSW' 'T095' ''.
  GET_FIELDCAT '' 'KTANSW_TXT'    TEXT-041 'TXT50' 'SKAT' ''.
  GET_FIELDCAT '' 'KTNAFB'        TEXT-042 'KTNAFB' 'T095B' ''.
  GET_FIELDCAT '' 'KTNAFB_TXT'    TEXT-043 'TXT50' 'SKAT' ''.
  GET_FIELDCAT '' 'KTNAFG'        TEXT-044 'KTNAFG' 'T095B' ''.
  GET_FIELDCAT '' 'KTNAFG_TXT'    TEXT-045 'TXT50' 'SKAT' ''.
  GET_FIELDCAT '' 'GJAHR'         TEXT-046 'GJAHR' 'ANLC' ''.
  GET_FIELDCAT '' 'CURDEP'        TEXT-047 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'DEP_001'       TEXT-048 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_001'       TEXT-049 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_002'       TEXT-050 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_002'       TEXT-051 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_003'       TEXT-052 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_003'       TEXT-053 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_004'       TEXT-054 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_004'       TEXT-055 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_005'       TEXT-056 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_005'       TEXT-057 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_006'       TEXT-058 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_006'       TEXT-059 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_007'       TEXT-060 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_007'       TEXT-061 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_008'       TEXT-062 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_008'       TEXT-063 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_009'       TEXT-064 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_009'       TEXT-065 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_010'       TEXT-066 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_010'       TEXT-067 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_011'       TEXT-068 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_011'       TEXT-069 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'DEP_012'       TEXT-070 'NAFAG' 'ANLC' 'CURR'.
  GET_FIELDCAT '' 'FLG_012'       TEXT-071 'ID' 'ICON' ''.
  GET_FIELDCAT '' 'WAERS'         TEXT-072 'WAERS' 'T093B' ''.
*  get_fieldcat '' 'TXA50'         TEXT-074 'TXA50' 'ANLA' ''.
**-------START BY VAN 20191226-------
*  get_fieldcat '' 'INVZU'         TEXT-075 'INVZU' 'INVZU' ''.
**-------END   BY VAN 20191226-------


ENDFORM.                    "FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_SORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_SET_SORT.
  "按公司代码排升序
*  GT_SORT-SPOS = '1'.
*  GT_SORT-FIELDNAME = 'BUKRS'.
*  GT_SORT-UP = ABAP_TRUE.
*  GT_SORT-DOWN = SPACE.
*  APPEND GT_SORT.
  CLEAR GT_SORT.
  IF P_RB2 = ABAP_TRUE.
    "按资产分类小计
    GT_SORT-SPOS = '2'.
    GT_SORT-FIELDNAME = 'ANLKL'.
    GT_SORT-UP = ABAP_TRUE.
    GT_SORT-DOWN = SPACE.
    GT_SORT-SUBTOT = ABAP_TRUE.
    APPEND GT_SORT.
    CLEAR GT_SORT.
  ELSEIF P_RB3 = ABAP_TRUE.
    "按资产分类汇总
    GT_SORT-SPOS = '2'.
    GT_SORT-FIELDNAME = 'TXK20'.
    GT_SORT-UP = ABAP_TRUE.
    GT_SORT-DOWN = SPACE.
    GT_SORT-SUBTOT = ABAP_TRUE.
    GT_SORT-EXPA = ABAP_TRUE.
    APPEND GT_SORT.
    CLEAR GT_SORT.
  ENDIF.
ENDFORM.                    "FRM_SET_SORT
*&---------------------------------------------------------------------*
*&      Form  FRM_DISPLAY_DETAIL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DISPLAY_DETAIL .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
*     I_INTERFACE_CHECK  = ' '
*     I_BYPASSING_BUFFER =
*     I_BUFFER_ACTIVE    =
      I_CALLBACK_PROGRAM = SY-REPID
*     I_CALLBACK_PF_STATUS_SET = 'FRM_SET_STATUS'
*     I_CALLBACK_USER_COMMAND  = 'FRM_USER_COMMAND'
*     I_CALLBACK_TOP_OF_PAGE   = ' '
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*     I_CALLBACK_HTML_END_OF_LIST       = ' '
*     I_STRUCTURE_NAME   =
*     I_BACKGROUND_ID    = ' '
*     I_GRID_TITLE       =
*     I_GRID_SETTINGS    =
      IS_LAYOUT_LVC      = GS_LAYOUT
      IT_FIELDCAT_LVC    = GT_FIELDCAT[]
*     IT_EXCLUDING       =
*     IT_SPECIAL_GROUPS_LVC    =
      IT_SORT_LVC        = GT_SORT[]
*     IT_FILTER_LVC      =
*     IT_HYPERLINK       =
*     IS_SEL_HIDE        =
*     I_DEFAULT          = 'X'
      I_SAVE             = 'A'
*     IS_VARIANT         =
*     IT_EVENTS          =
*     IT_EVENT_EXIT      =
*     IS_PRINT_LVC       =
*     IS_REPREP_ID_LVC   =
*     I_SCREEN_START_COLUMN    = 0
*     I_SCREEN_START_LINE      = 0
*     I_SCREEN_END_COLUMN      = 0
*     I_SCREEN_END_LINE  = 0
*     I_HTML_HEIGHT_TOP  =
*     I_HTML_HEIGHT_END  =
*     IT_ALV_GRAPHICS    =
*     IT_EXCEPT_QINFO_LVC      =
*     IR_SALV_FULLSCREEN_ADAPTER        =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER  =
*     ES_EXIT_CAUSED_BY_USER   =
    TABLES
      T_OUTTAB           = GT_OUTPUT
*   EXCEPTIONS
*     PROGRAM_ERROR      = 1
*     OTHERS             = 2
    .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
ENDFORM.                    "FRM_DISPLAY_DETAIL
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_SET_STATUS USING PT_EXTAB TYPE SLIS_T_EXTAB.
  SET PF-STATUS 'STANDARD_FULLSCREEN' EXCLUDING PT_EXTAB.
  IF P_RB1 = ABAP_TRUE.
    SET TITLEBAR 'T01'.
  ELSEIF P_RB2 = ABAP_TRUE.
    SET TITLEBAR 'T02'.
  ELSEIF P_RB3 = ABAP_TRUE.
    SET TITLEBAR 'T03'.
  ENDIF.
ENDFORM.                    "FRM_SET_STATUS
*&---------------------------------------------------------------------*
*&      Form  FRM_USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_USER_COMMAND USING PV_UCOMM LIKE SY-UCOMM
      PV_SELFIELD TYPE SLIS_SELFIELD.
  READ TABLE GT_OUTPUT INTO GS_OUTPUT WITH KEY SELECT = ABAP_TRUE.
  IF SY-SUBRC = 0.
    "选中的第一条记录写入内存
    SET PARAMETER ID 'AN1' FIELD GS_OUTPUT-ANLN1.
    SET PARAMETER ID 'AN2' FIELD GS_OUTPUT-ANLN2.
    SET PARAMETER ID 'BUK' FIELD GS_OUTPUT-BUKRS.
    SET PARAMETER ID 'GJR' FIELD GS_OUTPUT-GJAHR.
    CASE PV_UCOMM.
      WHEN '&AMDATA'.
        "资产主数据,调用AS03查看
        CALL TRANSACTION 'AS03' AND SKIP FIRST SCREEN.
      WHEN '&AMVAL'.
        "资产价值,调用AW01N查看
        CALL TRANSACTION 'AW01N' AND SKIP FIRST SCREEN.
      WHEN '&AMDOC'.
        "资产事务,调用AB03查看
        CALL TRANSACTION 'AB03' AND SKIP FIRST SCREEN.
      WHEN OTHERS.
    ENDCASE.
  ENDIF.
  PV_SELFIELD-REFRESH    = ABAP_TRUE.
  PV_SELFIELD-COL_STABLE = ABAP_TRUE.
  PV_SELFIELD-ROW_STABLE = ABAP_TRUE.
ENDFORM.                    "FRM_USER_COMMAND
*&---------------------------------------------------------------------*
*&      Form  FRM_REQUEST_AFABE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_REQUEST_AFABE .
  CALL FUNCTION 'AM_AFABE_F4'
    EXPORTING
      I_DYNAME   = SY-REPID
      I_DYNUMB   = SY-DYNNR
      I_FN_BUK   = 'S_BUKRS-LOW'
      I_FN_AFABE = 'P_AFABE'
    IMPORTING
      E_AFABE    = P_AFABE.
ENDFORM.                    " FRM_REQUEST_AFABE
*&---------------------------------------------------------------------*
*&      Form  FRM_DEFUALT_GJAHR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DEFUALT_GJAHR .
  IF SY-DATLO+4(2) = '01'.
    P_GJAHR = SY-DATLO+0(4) - 1.
  ELSE.
    P_GJAHR = SY-DATLO+0(4).
  ENDIF.
ENDFORM.                    " FRM_DEFUALT_GJAHR
*&---------------------------------------------------------------------*
*&      Form  FRM_CHECK_DEPRECIATION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_CHECK_DEPRECIATION .
  DATA: LV_DATE      LIKE SY-DATUM,
        LV_GJAHR     TYPE GJAHR,
        LV_PERAF     TYPE PERAF,
        LV_FIELDNAME TYPE FIELDNAME,
        LV_FLAG      TYPE AS4FLAG,
        LV_TEXT      TYPE NATXT.
  FIELD-SYMBOLS: <FS_FLG> TYPE ICON_D.

  CALL FUNCTION 'CCM_GO_BACK_MONTHS'
    EXPORTING
      CURRDATE   = SY-DATLO
      BACKMONTHS = '1'
    IMPORTING
      NEWDATE    = LV_DATE.
  LV_GJAHR = LV_DATE+0(4).
  LV_PERAF = LV_DATE+4(2).
  CONCATENATE 'GS_OUTPUT-FLG_'  LV_PERAF INTO LV_FIELDNAME.
  ASSIGN (LV_FIELDNAME) TO <FS_FLG>.

  LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE GJAHR = LV_GJAHR.
    IF <FS_FLG> = '@5D@'.
      LV_FLAG = 'X'.
      EXIT.
    ENDIF.
  ENDLOOP.

  IF LV_FLAG = 'X'.
    CONCATENATE TEXT-T01 LV_GJAHR TEXT-T02 LV_PERAF TEXT-T03 INTO LV_TEXT.
    MESSAGE S000(/AIF/CUSTOM_FUNCTION) WITH LV_TEXT DISPLAY LIKE 'W'.
  ENDIF.
ENDFORM.                    " FRM_CHECK_DEPRECIATION
*Text elements
*----------------------------------------------------------
* 001 公司代码
* 002 资产编号
* 003 资产次级编号
* 004 资产名称
* 005 资产分类
* 006 资产分类名称
* 007 资产主号文本
* 008 转帐的原始资产
* 009 转帐的原始资产
* 010 数量
* 011 计量单位
* 012 成本中心
* 013 成本中心描述
* 014 成本中心负责人
* 015 内部订单
* 016 内部订单描述
* 017 供应商
* 018 供应商描述
* 019 资本化日期
* 020 折旧范围
* 021 折旧范围说明
* 022 折旧方法
* 023 折旧方法说明
* 024 开始折旧日期
* 025 计划使用年限
* 026 计划使用期间
* 027 已计提期间
* 028 剩余计提期间
* 029 原值
* 030 累计折旧
* 031 净值
* 032 残值
* 033 残值率(%)
* 034 时点已计提期间
* 035 时点剩余计提期间
* 036 时点原值
* 037 时点累计折旧
* 038 时点净值
* 039 科目定位码
* 040 原值科目
* 041 原值科目描述
* 042 累计折旧科目
* 043 累计折旧科目描述
* 044 折旧费科目
* 045 折旧费科目描述
* 046 资产财年
* 047 本年应计提折旧
* 048 1月份计提折旧
* 049 计划/记账
* 050 2月份计提折旧
* 051 计划/记账
* 052 3月份计提折旧
* 053 计划/记账
* 054 4月份计提折旧
* 055 计划/记账
* 056 5月份计提折旧
* 057 计划/记账
* 058 6月份计提折旧
* 059 计划/记账
* 060 7月份计提折旧
* 061 计划/记账
* 062 8月份计提折旧
* 063 计划/记账
* 064 9月份计提折旧
* 065 计划/记账
* 066 10月份计提折旧
* 067 计划/记账
* 068 11月份计提折旧
* 069 计划/记账
* 070 12月份计提折旧
* 071 计划/记账
* 072 货币
* 073 序列号
* 074 资产型号
* 075 库存注记
*Selection texts
*----------------------------------------------------------
* C_DEAKT         显示不活动的资产
* P_AFABE         实际折旧范围
* P_GJAHR         资产财年
* P_PERAF         资产时点价值
* P_RB1         资产明细清单
* P_RB2         按资产分类小计
* P_RB3         按资产分类汇总
* S_ANLKL         资产分类
* S_ANLN1         资产编号
* S_ANLN2         资产次级编号
* S_BUKRS         公司代码
* S_TXT50         资产描述
*Messages
*----------------------------------------------------------
*
* Message class: /AIF/CUSTOM_FUNCTION
*000   &1 &2 &3 &4 &5
*
* Message class: AA
*048   对于 & & & & 无权限
*
* Message class: Hard coded
*   没有权限使用此公司代码
"EXTRACTED BY DIRECT DOWNLOAD ENTERPRISE VERSION 1.3.1 - E.G.MELLODEW. 1998-2005 UK. SAP RELEASE 754

 

posted @ 2023-09-06 08:38  萧静默  阅读(250)  评论(0编辑  收藏  举报