计算逻辑:
**资产原值 = ANLC-ANSWL + ANLC-KANSW
* ANLC-ANSWL 往年累计购置价值
* NNLC-KANSW 本年资产变动价值
**往年累计折旧 = ANLC-KNAFA + ANLC-KSAFA + ANLC-KAAFA + ANLC–NAFAV + ANLC-SAFAV + ANLC-AAFAV + ANLC-NAFAL + ANLC-SAFAL + ANLC-AAFAL
* ANLC-KNAFA 累计普通折旧(以前年)
* ANLC-KSAFA 累计特殊折旧(以前年)
* ANLC-KAAFA 累计计划外折旧(以前年)
* ANLC-NAFAV 比例累计特别折旧
* ANLC-SAFAV 比例累计正常折旧
* ANLC-AAFAV 前年计划外折旧
* ANLC-NAFAL 正常折旧(本年)
* ANLC-SAFAL 特殊折旧(本年)
* ANLC-AAFAL 计划外折旧(本年)
**本年折旧 = NAFAZ + SAFAZ + AAFAZ
* AM_SHOW_POST_DEPR函数计算每月折旧额汇总(查询1月到当前所在月份值汇总)
* NAFAZ 记帐的正常折旧
* SAFAZ 待过帐的特殊折旧
* AAFAZ 待过帐的计划外折旧
**资产净值 = 资产原值 - 往年累计折旧 - 本年折旧
DATA: Z_ZJ LIKE ANLC-KNAFA.
DATA: GS_ANLC LIKE TABLE OF ANLC WITH HEADER LINE.
DATA: GS_ANLA TYPE ANLA.
DATA: GT_AFAPOST TYPE TABLE OF FIAA_DPOST.
DATA: GS_AFAPOST TYPE FIAA_DPOST.
DATA: GT_ANLC TYPE TABLE OF ANLC.
DATA: GT_ANLB TYPE TABLE OF ANLB.
DATA: GT_ANEP TYPE TABLE OF ANEP.
DATA: GT_ANEA TYPE TABLE OF ANEA.
DATA: GT_ANEK TYPE TABLE OF ANEK.
CLEAR: GS_ANLC.
REFRESH: GS_ANLC.
SELECT * INTO CORRESPONDING FIELDS OF TABLE GS_ANLC
FROM ANLC
WHERE BUKRS = ITAB-BUKRS
AND ANLN1 = ITAB-ANLN1.
IF SY-SUBRC = 0.
SORT GS_ANLC BY GJAHR DESCENDING.
READ TABLE GS_ANLC WITH KEY GJAHR = P_GJAHR. "按年份取
IF SY-SUBRC = 0.
**资产原值
ITAB-YZ = GS_ANLC-KANSW + GS_ANLC-ANSWL.
**往年累计折旧
ITAB-PRE_ZJ = GS_ANLC-KNAFA + GS_ANLC-KSAFA + GS_ANLC-KAAFA + GS_ANLC-NAFAV + GS_ANLC-SAFAV + GS_ANLC-AAFAV + GS_ANLC-NAFAL + GS_ANLC-SAFAL + GS_ANLC-AAFAL.
**本年折旧
CLEAR: GS_ANLA.
SELECT SINGLE * INTO GS_ANLA
FROM ANLA
WHERE BUKRS = ITAB-BUKRS
AND ANLN1 = ITAB-ANLN1.
IF SY-SUBRC = 0.
CALL FUNCTION 'AM_SHOW_POST_DEPR'
EXPORTING
I_ANLA = GS_ANLA
I_AFABE = '01' "账面折旧
I_GJAHR = P_GJAHR
TABLES
T_DPOST = GT_AFAPOST[]
T_ANLB = GT_ANLB[]
T_ANLC = GT_ANLC[]
T_ANEP = GT_ANEP[]
T_ANEA = GT_ANEA[]
T_ANEK = GT_ANEK[]
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
CLEAR: Z_ZJ, GS_AFAPOST.
LOOP AT GT_AFAPOST INTO GS_AFAPOST.
Z_ZJ = GS_AFAPOST-NAFAZ + GS_AFAPOST-SAFAZ + GS_AFAPOST-AAFAZ.
ITAB-NOW_ZJ = ITAB-NOW_ZJ + Z_ZJ.
ENDLOOP.
ENDIF.
**净值
ITAB-JZ = ITAB-YZ + ITAB-PRE_ZJ + ITAB-NOW_ZJ.
ELSE.
READ TABLE GS_ANLC INDEX 1. "取最近的一笔
**资产原值
ITAB-YZ = GS_ANLC-KANSW + GS_ANLC-ANSWL.
**往年累计折旧
ITAB-PRE_ZJ = GS_ANLC-KNAFA + GS_ANLC-KSAFA + GS_ANLC-KAAFA + GS_ANLC-NAFAV + GS_ANLC-SAFAV + GS_ANLC-AAFAV + GS_ANLC-NAFAL + GS_ANLC-SAFAL + GS_ANLC-AAFAL.
**本年折旧
CLEAR: GS_ANLA.
SELECT SINGLE * INTO GS_ANLA
FROM ANLA
WHERE BUKRS = ITAB-BUKRS
AND ANLN1 = ITAB-ANLN1.
IF SY-SUBRC = 0.
CALL FUNCTION 'AM_SHOW_POST_DEPR'
EXPORTING
I_ANLA = GS_ANLA
I_AFABE = '01' "账面折旧
I_GJAHR = GS_ANLC-GJAHR
TABLES
T_DPOST = GT_AFAPOST[]
T_ANLB = GT_ANLB[]
T_ANLC = GT_ANLC[]
T_ANEP = GT_ANEP[]
T_ANEA = GT_ANEA[]
T_ANEK = GT_ANEK[]
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
CLEAR: Z_ZJ, GS_AFAPOST.
LOOP AT GT_AFAPOST INTO GS_AFAPOST.
Z_ZJ = GS_AFAPOST-NAFAZ + GS_AFAPOST-SAFAZ + GS_AFAPOST-AAFAZ.
ITAB-NOW_ZJ = ITAB-NOW_ZJ + Z_ZJ.
ENDLOOP.
ENDIF.
**净值
ITAB-JZ = ITAB-YZ + ITAB-PRE_ZJ + ITAB-NOW_ZJ.
ENDIF.
ENDIF.
以上~~