分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
*&---------------------------------------------------------------------*
*& Report ZFIX_ASSET
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZFIX_ASSET.
TABLES :
ANLA,"资产主记录段
ANLH,"主资产号
ANKT,"资产类别描述
T087S, "评估组8测试表位置
ANLZ,"时间相关资产分配
ANLC,"资产值字段
ANLB,"折旧期限
ANLP,"资产期间价值
FIAA_DPOST,"已记帐价值的显示结构
BSID,"会计核算:客户的第二次索引
ANEP,"资产行项目
CSKS."成本中心主数据
DATA : BEGIN OF ITAB OCCURS 0,
GJAHR LIKE ANLP-GJAHR,"会计年度
BUKRS LIKE ANLA-BUKRS,"公司代码
ANLN1 LIKE ANLA-ANLN1,"主资产号
TXT50 LIKE ANLA-TXT50,"资产描述
TXA50 LIKE ANLA-TXA50,"附加资产描述
ANLN2 LIKE ANLA-ANLN2,"次资产号
ANLHTXT LIKE ANLH-ANLHTXT,"主资产号描述
KFZKZ LIKE ANLZ-KFZKZ,"执照牌号
MCOAL LIKE M_AANLA-MCOA1,"次资产号描述
ANLKL LIKE ANLA-ANLKL,"资产种类
TXK20 LIKE ANKT-TXK20,"资产种类描述
GDLGRP LIKE ANLA-GDLGRP,"资产小类
GDLGRP_TXT LIKE T087S-GDLGRP_TXT,"资产小类描述
NAFAG LIKE ANLC-NAFAG,"记帐在当前年的正常折旧
KNAFA LIKE ANLC-KNAFA,"累计正常折旧
KOSTL LIKE ANLZ-KOSTL,"成本中心
SERNR LIKE ANLA-SERNR,"实际卡片编号
AIBN1 LIKE ANLA-AIBN1,"来源资产编号
ORD41 LIKE ANLA-ORD41,"资产小类
LIFNR LIKE ANLA-LIFNR,"供应商科目编号(其他关键字)
LIEFE LIKE ANLA-LIEFE,"资产提供者名
ORDTX1 LIKE T087T-ORDTX,"资产小类名称
ORD42 LIKE ANLA-ORD42, "评审小组2
ORDTX2 LIKE T087T-ORDTX,"评审小组:短描述
KTEXTL LIKE CSKT-KTEXT,"一般姓名
AFASL LIKE ANLB-AFASL,"折旧码
YZ LIKE ANLC-KANSW,"累积购置和生产费用
KANSW LIKE ANLC-KANSW,"累积购置和生产费用
KAUFW LIKE ANLC-KAUFW,"重置价值的累计重估
ANBTR LIKE ANEP-ANBTR,"记帐金额
AKTIV LIKE ANLA-AKTIV,"资产资本化日期
DEAKT LIKE ANLA-DEAKT,"不激活的日期
NDJAR LIKE ANLB-NDJAR,"计划年使用期
NDPER LIKE ANLB-NDPER,"计划使用期间
YJCZ LIKE ANLC-KANSW,"累积购置和生产费用
NAFAZ LIKE ANLP-NAFAZ,"记帐的正常折旧
AAFAZ LIKE ANLP-AAFAZ,"待过帐的计划外折旧
LJPTZJ LIKE ANLP-NAFAZ,"记帐的正常折旧
NAFAV LIKE ANLC-NAFAV,"比例累积正常折旧
NAFAL LIKE ANLC-NAFAL,"此年的比例正常折旧
PERAF LIKE ANLP-PERAF,"折旧计算期
AAFAP LIKE ANLP-AAFAP,"年内已预定的未计划折旧
JZ LIKE ANLP-AAFAP,"净值 = 原值-累计普通折旧-累计计划外折旧
AFBNR LIKE ANLP-AFBNR,"此期间折旧记帐运行的顺序号
GSBER LIKE ANLZ-GSBER,"业务范围
GTEXT LIKE TGSBT-GTEXT,"业务部门描述
PRCTR LIKE CSKS-PRCTR,"利润中心
PKTEXT LIKE CEPCT-KTEXT,"
CSHZJ LIKE ANLP-AAFAP,"年内已预定的未计划折旧
AUFWB LIKE ANLC-AUFWB,"重置价值的重估记帐
AUFNG LIKE ANLC-AUFNG,"有关累积正常折旧的记帐评估
AFABG LIKE ANLB-AFABG,"折旧计算开始日期
XFABG LIKE KOMP-ANZ_MONATE,"月数
XFABG1 TYPE I,"
SEL(1) TYPE C,"
END OF ITAB.
DATA : ITAB1 LIKE TABLE OF ITAB WITH HEADER LINE .
DATA : P_NUM TYPE VBRK-NETWR,
XL_SUM TYPE I,
FLAG TYPE CHAR01.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_BUKRS LIKE ANLA-BUKRS OBLIGATORY DEFAULT '1200',
P_GJAHR LIKE ANLC-GJAHR OBLIGATORY ,"DEFAULT SY-DATUM+0(4),
P_PERAF LIKE ANLP-PERAF OBLIGATORY ."DEFAULT SY-DATUM+4(2).
SELECT-OPTIONS : S_GSBER FOR ANLZ-GSBER,
S_PRCTR FOR CSKS-PRCTR OBLIGATORY ,
S_ANLN1 FOR ANLA-ANLN1,
S_ANLKL FOR ANLA-ANLKL,
S_KOSTL FOR ANLZ-KOSTL,
S_ORD41 FOR ANLA-ORD41.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN END OF BLOCK B1.
RANGES : S_HKONT FOR BSEG-HKONT.
DATA : P_AFBNR LIKE ANLP-AFBNR.
TYPE-POOLS : SLIS.
DATA : IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
IT_EVENT TYPE SLIS_T_EVENT,
IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
START-OF-SELECTION.
PERFORM FRM_GET_DATA.
END-OF-SELECTION.
DEFINE INITIAL_FIELD.
WA_FIELDCAT-SELTEXT_L = &1.
WA_FIELDCAT-SELTEXT_M = &1.
WA_FIELDCAT-SELTEXT_S = &1.
WA_FIELDCAT-FIELDNAME = &2.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
END-OF-DEFINITION.
INITIAL_FIELD '会计年度' 'GJAHR'.
INITIAL_FIELD '公司代码' 'BUKRS'.
INITIAL_FIELD '成本中心' 'KOSTL'.
INITIAL_FIELD '成本中心描述' 'KTEXT'.
INITIAL_FIELD '业务范围' 'GSBER'.
INITIAL_FIELD '业务范围描述' 'GTEXT'.
INITIAL_FIELD '利润中心' 'PRCTR'.
INITIAL_FIELD '利润中心描述' 'PKTEXT'.
INITIAL_FIELD '资产大类' 'ANLKL'.
INITIAL_FIELD '资产大类名称' 'TXK20'.
INITIAL_FIELD '主资产编号' 'ANLN1'.
INITIAL_FIELD '资产名称' 'TXT50'.
INITIAL_FIELD '资产名称2' 'TXA50'.
INITIAL_FIELD '存放地点' 'ANLHTXT'.
INITIAL_FIELD '使用人/保管人' 'KFZKZ'.
INITIAL_FIELD '规格' 'SERNR'.
INITIAL_FIELD '来源资产卡片编号' 'AIBN1'.
INITIAL_FIELD '资产小类编码' 'ORD41'.
INITIAL_FIELD '资产小类名称' 'ORDTX1'.
INITIAL_FIELD '资本化日期' 'AKTIV'.
INITIAL_FIELD '已折旧月份' 'XFABG1'.
INITIAL_FIELD '不活动日期' 'DEAKT'.
INITIAL_FIELD '折旧期限-年' 'NDJAR'.
INITIAL_FIELD '折旧期限-月' 'NDPER'.
INITIAL_FIELD '折旧码' 'AFASL'.
INITIAL_FIELD '原值' 'YZ'.
INITIAL_FIELD '预计净残值' 'YJCZ'.
INITIAL_FIELD '本月折旧' 'NAFAZ'.
INITIAL_FIELD '本月计划外折旧' 'AAFAZ'.
INITIAL_FIELD '累计普通折旧' 'LJPTZJ'.
INITIAL_FIELD '累计计划外折旧' 'AAFAP'.
INITIAL_FIELD '净值' 'JZ'.
INITIAL_FIELD '初始化折旧' 'CSHZJ'.
INITIAL_FIELD '供应商代码' 'LIFNR'.
INITIAL_FIELD '供应商名称' 'LIEFE'.
IT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_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 = IT_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = ITAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
*查询固定资产
SELECT
ANLA~ANLN1
ANLA~TXT50
ANLA~TXA50
ANLH~ANLHTXT
ANLA~ANLKL
ANKT~TXK20
ANLA~ANLN2
ANLA~GDLGRP
T087S~GDLGRP_TXT
ANLZ~KOSTL
CSKT~KTEXT
ANLA~SERNR
ANLA~AIBN1
ANLA~ORD41
ANLA~LIFNR
T087T1~ORDTX AS ORDTX1
ANLB~NDPER
ANLC~KANSW
ANLC~KAUFW
ANLA~AKTIV
ANLA~DEAKT
ANLB~NDJAR
ANLB~AFABG
ANLB~AFASL
ANLC~ANLN1
ANLC~KNAFA
ANLP~PERAF
ANLC~GJAHR
ANLA~BUKRS
ANLZ~GSBER
TGSBT~GTEXT
ANLC~NAFAG
ANLC~KNAFA
ANLC~AUFWB
ANLC~AUFNG
ANLC~NAFAV
ANLC~NAFAL
ANLZ~KFZKZ
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM ANLA
INNER JOIN ANLH
ON ANLH~BUKRS = ANLA~BUKRS AND
ANLH~ANLN1 = ANLA~ANLN1
LEFT JOIN T087S
ON T087S~GDLGRP = ANLA~GDLGRP AND
T087S~SPRAS = SY-LANGU
LEFT JOIN T087T AS T087T1
ON T087T1~ORDNR = '1' AND
T087T1~ORD4X = ANLA~ORD41 AND
T087T1~SPRAS = SY-LANGU
LEFT JOIN T087T AS T087T2
ON T087T2~ORDNR = '2' AND
T087T2~ORD4X = ANLA~ORD42 AND
T087T2~SPRAS = SY-LANGU
INNER JOIN ANLZ
ON ANLZ~BUKRS = ANLA~BUKRS AND
ANLZ~ANLN1 = ANLA~ANLN1 AND
ANLZ~ANLN2 = ANLA~ANLN2 AND
ANLZ~BDATU = '99991231'
INNER JOIN ANKT
ON ANKT~SPRAS = SY-LANGU AND
ANKT~ANLKL = ANLA~ANLKL
INNER JOIN ANLC
ON ANLC~BUKRS = ANLA~BUKRS AND
ANLC~ANLN1 = ANLA~ANLN1 AND
ANLC~ANLN2 = ANLA~ANLN2 AND
ANLC~AFABE = '01'
INNER JOIN ANLB
ON ANLB~BUKRS = ANLA~BUKRS AND
ANLB~ANLN1 = ANLA~ANLN1 AND
ANLB~ANLN2 = ANLA~ANLN2 AND
ANLB~AFABE = '01' AND
ANLB~BDATU = '99991231'
LEFT JOIN ANLP
ON ANLP~BUKRS = ANLA~BUKRS AND
ANLP~PERAF = P_PERAF AND
ANLP~ANLN1 = ANLA~ANLN1 AND
ANLP~ANLN2 = ANLA~ANLN2 AND
ANLP~AFABER = '01'
LEFT JOIN TGSBT
ON ANLZ~GSBER = TGSBT~GSBER
LEFT JOIN CSKT
ON ANLZ~KOSTL = CSKT~KOSTL AND
CSKT~SPRAS = SY-LANGU AND
CSKT~DATBI = '99991231' AND
CSKT~KOKRS = 'ZSUN'
WHERE ANLA~BUKRS = P_BUKRS
AND ANLC~GJAHR = P_GJAHR
AND ANLA~ANLN1 IN S_ANLN1
AND ANLA~ANLKL IN S_ANLKL
AND ANLZ~KOSTL IN S_KOSTL
AND ANLA~ORD41 IN S_ORD41
AND ANLZ~GSBER IN S_GSBER.
SORT ITAB BY GJAHR BUKRS ANLN1 ANLKL GDLGRP KOSTL.
DELETE ADJACENT DUPLICATES FROM ITAB
COMPARING GJAHR BUKRS ANLN1 ANLKL GDLGRP KOSTL.
LOOP AT ITAB.
"根据成本中心获取利润中心
SELECT SINGLE PRCTR
INTO ITAB-PRCTR
FROM CSKS
WHERE KOSTL = ITAB-KOSTL AND
KOKRS = 'ZSUN'.
"从供应商信息视图获取供应商名称
SELECT SINGLE MCOD1"匹配码搜索的搜索条件
INTO ITAB-LIEFE
FROM M_KREDI"生成匹配码ID KRED-I的视图
WHERE LIFNR = ITAB-LIFNR AND
BUKRS = P_BUKRS AND
LAND1 = 'CN'.
"删除非利润中心查询条件内的固定资产查询结果
IF ITAB-PRCTR NOT IN S_PRCTR.
DELETE ITAB.
CONTINUE.
ENDIF.
"获取利润中心的名称
IF ITAB-PRCTR IS NOT INITIAL.
SELECT SINGLE KTEXT
INTO ITAB-PKTEXT
FROM CEPCT"利润中心主数据文本
WHERE PRCTR = ITAB-PRCTR AND
SPRAS = SY-LANGU AND
KOKRS = 'ZSUN'.
ENDIF.
"获取当前期间的累计值
DATA : N TYPE I,
NC TYPE STRING.
DATA : F_ANBTR LIKE ANEP-ANBTR, "记账金额
F_BEGIN LIKE SY-DATUM,
F_END LIKE SY-DATUM.
N = P_PERAF.
NC = N.
IF N < 10.
CONCATENATE P_GJAHR '0' NC '01' INTO F_BEGIN.
ELSE.
CONCATENATE P_GJAHR NC '01' INTO F_BEGIN.
ENDIF.
"该函数获取某月的最后一天
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = F_BEGIN
IMPORTING
LAST_DAY_OF_MONTH = F_END
EXCEPTIONS
DAY_IN_NO_DATE = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
"计算某段期间内的记账金额,可以通过abep-bwasl来指定资产业务类型,提高查询
CLEAR : F_ANBTR.
SELECT SINGLE SUM( ANBTR )
INTO F_ANBTR
FROM ANEP"资产行项目
WHERE BUKRS = P_BUKRS
AND GJAHR = P_GJAHR
AND ANLN1 = ITAB-ANLN1
AND BZDAT BETWEEN '1900101' AND F_END
AND ANEP~AFABE = '01'.
"计算资产原值,为购置和生产费用(KANSW)资产重置费用(KAUFW)以及累计记账之和
ITAB-YZ = ITAB-KANSW + ITAB-KAUFW + F_ANBTR.
*折旧率----具体看公司了
"检查是否存在资产折旧记录,若有,则根据折旧码来推算扣除折旧的资产余值
SELECT SINGLE *
FROM ANLB"折旧期限
WHERE ANLN1 = ITAB-ANLN1 AND
BUKRS = P_BUKRS.
*707 ZSUN 0000 X 无折旧也无利息
*707 ZSUN DG20 X 2倍余额递减折旧法
*707 ZSUN DG25 X 2.5倍余额递减折旧法
*707 ZSUN DG30 X 3倍余额递减折旧法
*707 ZSUN GL20 X 建筑物直线法 2%
*707 ZSUN&
*& Report ZFIX_ASSET
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZFIX_ASSET.
TABLES :
ANLA,"资产主记录段
ANLH,"主资产号
ANKT,"资产类别描述
T087S, "评估组8测试表位置
ANLZ,"时间相关资产分配
ANLC,"资产值字段
ANLB,"折旧期限
ANLP,"资产期间价值
FIAA_DPOST,"已记帐价值的显示结构
BSID,"会计核算:客户的第二次索引
ANEP,"资产行项目
CSKS."成本中心主数据
DATA : BEGIN OF ITAB OCCURS 0,
GJAHR LIKE ANLP-GJAHR,"会计年度
BUKRS LIKE ANLA-BUKRS,"公司代码
ANLN1 LIKE ANLA-ANLN1,"主资产号
TXT50 LIKE ANLA-TXT50,"资产描述
TXA50 LIKE ANLA-TXA50,"附加资产描述
ANLN2 LIKE ANLA-ANLN2,"次资产号
ANLHTXT LIKE ANLH-ANLHTXT,"主资产号描述
KFZKZ LIKE ANLZ-KFZKZ,"执照牌号
MCOAL LIKE M_AANLA-MCOA1,"次资产号描述
ANLKL LIKE ANLA-ANLKL,"资产种类
TXK20 LIKE ANKT-TXK20,"资产种类描述
GDLGRP LIKE ANLA-GDLGRP,"资产小类
GDLGRP_TXT LIKE T087S-GDLGRP_TXT,"资产小类描述
NAFAG LIKE ANLC-NAFAG,"记帐在当前年的正常折旧
KNAFA LIKE ANLC-KNAFA,"累计正常折旧
KOSTL LIKE ANLZ-KOSTL,"成本中心
SERNR LIKE ANLA-SERNR,"实际卡片编号
AIBN1 LIKE ANLA-AIBN1,"来源资产编号
ORD41 LIKE ANLA-ORD41,"资产小类
LIFNR LIKE ANLA-LIFNR,"供应商科目编号(其他关键字)
LIEFE LIKE ANLA-LIEFE,"资产提供者名
ORDTX1 LIKE T087T-ORDTX,"资产小类名称
ORD42 LIKE ANLA-ORD42, "评审小组2
ORDTX2 LIKE T087T-ORDTX,"评审小组:短描述
KTEXTL LIKE CSKT-KTEXT,"一般姓名
AFASL LIKE ANLB-AFASL,"折旧码
YZ LIKE ANLC-KANSW,"累积购置和生产费用
KANSW LIKE ANLC-KANSW,"累积购置和生产费用
KAUFW LIKE ANLC-KAUFW,"重置价值的累计重估
ANBTR LIKE ANEP-ANBTR,"记帐金额
AKTIV LIKE ANLA-AKTIV,"资产资本化日期
DEAKT LIKE ANLA-DEAKT,"不激活的日期
NDJAR LIKE ANLB-NDJAR,"计划年使用期
NDPER LIKE ANLB-NDPER,"计划使用期间
YJCZ LIKE ANLC-KANSW,"累积购置和生产费用
NAFAZ LIKE ANLP-NAFAZ,"记帐的正常折旧
AAFAZ LIKE ANLP-AAFAZ,"待过帐的计划外折旧
LJPTZJ LIKE ANLP-NAFAZ,"记帐的正常折旧
NAFAV LIKE ANLC-NAFAV,"比例累积正常折旧
NAFAL LIKE ANLC-NAFAL,"此年的比例正常折旧
PERAF LIKE ANLP-PERAF,"折旧计算期
AAFAP LIKE ANLP-AAFAP,"年内已预定的未计划折旧
JZ LIKE ANLP-AAFAP,"净值 = 原值-累计普通折旧-累计计划外折旧
AFBNR LIKE ANLP-AFBNR,"此期间折旧记帐运行的顺序号
GSBER LIKE ANLZ-GSBER,"业务范围
GTEXT LIKE TGSBT-GTEXT,"业务部门描述
PRCTR LIKE CSKS-PRCTR,"利润中心
PKTEXT LIKE CEPCT-KTEXT,"
CSHZJ LIKE ANLP-AAFAP,"年内已预定的未计划折旧
AUFWB LIKE ANLC-AUFWB,"重置价值的重估记帐
AUFNG LIKE ANLC-AUFNG,"有关累积正常折旧的记帐评估
AFABG LIKE ANLB-AFABG,"折旧计算开始日期
XFABG LIKE KOMP-ANZ_MONATE,"月数
XFABG1 TYPE I,"
SEL(1) TYPE C,"
END OF ITAB.
DATA : ITAB1 LIKE TABLE OF ITAB WITH HEADER LINE .
DATA : P_NUM TYPE VBRK-NETWR,
XL_SUM TYPE I,
FLAG TYPE CHAR01.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS : P_BUKRS LIKE ANLA-BUKRS OBLIGATORY DEFAULT '1200',
P_GJAHR LIKE ANLC-GJAHR OBLIGATORY ,"DEFAULT SY-DATUM+0(4),
P_PERAF LIKE ANLP-PERAF OBLIGATORY ."DEFAULT SY-DATUM+4(2).
SELECT-OPTIONS : S_GSBER FOR ANLZ-GSBER,
S_PRCTR FOR CSKS-PRCTR OBLIGATORY ,
S_ANLN1 FOR ANLA-ANLN1,
S_ANLKL FOR ANLA-ANLKL,
S_KOSTL FOR ANLZ-KOSTL,
S_ORD41 FOR ANLA-ORD41.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN END OF BLOCK B1.
RANGES : S_HKONT FOR BSEG-HKONT.
DATA : P_AFBNR LIKE ANLP-AFBNR.
TYPE-POOLS : SLIS.
DATA : IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
IT_EVENT TYPE SLIS_T_EVENT,
IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
START-OF-SELECTION.
PERFORM FRM_GET_DATA.
END-OF-SELECTION.
DEFINE INITIAL_FIELD.
WA_FIELDCAT-SELTEXT_L = &1.
WA_FIELDCAT-SELTEXT_M = &1.
WA_FIELDCAT-SELTEXT_S = &1.
WA_FIELDCAT-FIELDNAME = &2.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
END-OF-DEFINITION.
INITIAL_FIELD '会计年度' 'GJAHR'.
INITIAL_FIELD '公司代码' 'BUKRS'.
INITIAL_FIELD '成本中心' 'KOSTL'.
INITIAL_FIELD '成本中心描述' 'KTEXT'.
INITIAL_FIELD '业务范围' 'GSBER'.
INITIAL_FIELD '业务范围描述' 'GTEXT'.
INITIAL_FIELD '利润中心' 'PRCTR'.
INITIAL_FIELD '利润中心描述' 'PKTEXT'.
INITIAL_FIELD '资产大类' 'ANLKL'.
INITIAL_FIELD '资产大类名称' 'TXK20'.
INITIAL_FIELD '主资产编号' 'ANLN1'.
INITIAL_FIELD '资产名称' 'TXT50'.
INITIAL_FIELD '资产名称2' 'TXA50'.
INITIAL_FIELD '存放地点' 'ANLHTXT'.
INITIAL_FIELD '使用人/保管人' 'KFZKZ'.
INITIAL_FIELD '规格' 'SERNR'.
INITIAL_FIELD '来源资产卡片编号' 'AIBN1'.
INITIAL_FIELD '资产小类编码' 'ORD41'.
INITIAL_FIELD '资产小类名称' 'ORDTX1'.
INITIAL_FIELD '资本化日期' 'AKTIV'.
INITIAL_FIELD '已折旧月份' 'XFABG1'.
INITIAL_FIELD '不活动日期' 'DEAKT'.
INITIAL_FIELD '折旧期限-年' 'NDJAR'.
INITIAL_FIELD '折旧期限-月' 'NDPER'.
INITIAL_FIELD '折旧码' 'AFASL'.
INITIAL_FIELD '原值' 'YZ'.
INITIAL_FIELD '预计净残值' 'YJCZ'.
INITIAL_FIELD '本月折旧' 'NAFAZ'.
INITIAL_FIELD '本月计划外折旧' 'AAFAZ'.
INITIAL_FIELD '累计普通折旧' 'LJPTZJ'.
INITIAL_FIELD '累计计划外折旧' 'AAFAP'.
INITIAL_FIELD '净值' 'JZ'.
INITIAL_FIELD '初始化折旧' 'CSHZJ'.
INITIAL_FIELD '供应商代码' 'LIFNR'.
INITIAL_FIELD '供应商名称' 'LIEFE'.
IT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_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 = IT_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = ITAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
*查询固定资产
SELECT
ANLA~ANLN1
ANLA~TXT50
ANLA~TXA50
ANLH~ANLHTXT
ANLA~ANLKL
ANKT~TXK20
ANLA~ANLN2
ANLA~GDLGRP
T087S~GDLGRP_TXT
ANLZ~KOSTL
CSKT~KTEXT
ANLA~SERNR
ANLA~AIBN1
ANLA~ORD41
ANLA~LIFNR
T087T1~ORDTX AS ORDTX1
ANLB~NDPER
ANLC~KANSW
ANLC~KAUFW
ANLA~AKTIV
ANLA~DEAKT
ANLB~NDJAR
ANLB~AFABG
ANLB~AFASL
ANLC~ANLN1
ANLC~KNAFA
ANLP~PERAF
ANLC~GJAHR
ANLA~BUKRS
ANLZ~GSBER
TGSBT~GTEXT
ANLC~NAFAG
ANLC~KNAFA
ANLC~AUFWB
ANLC~AUFNG
ANLC~NAFAV
ANLC~NAFAL
ANLZ~KFZKZ
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM ANLA
INNER JOIN ANLH
ON ANLH~BUKRS = ANLA~BUKRS AND
ANLH~ANLN1 = ANLA~ANLN1
LEFT JOIN T087S
ON T087S~GDLGRP = ANLA~GDLGRP AND
T087S~SPRAS = SY-LANGU
LEFT JOIN T087T AS T087T1
ON T087T1~ORDNR = '1' AND
T087T1~ORD4X = ANLA~ORD41 AND
T087T1~SPRAS = SY-LANGU
LEFT JOIN T087T AS T087T2
ON T087T2~ORDNR = '2' AND
T087T2~ORD4X = ANLA~ORD42 AND
T087T2~SPRAS = SY-LANGU
INNER JOIN ANLZ
ON ANLZ~BUKRS = ANLA~BUKRS AND
ANLZ~ANLN1 = ANLA~ANLN1 AND
ANLZ~ANLN2 = ANLA~ANLN2 AND
ANLZ~BDATU = '99991231'
INNER JOIN ANKT
ON ANKT~SPRAS = SY-LANGU AND
ANKT~ANLKL = ANLA~ANLKL
INNER JOIN ANLC
ON ANLC~BUKRS = ANLA~BUKRS AND
ANLC~ANLN1 = ANLA~ANLN1 AND
ANLC~ANLN2 = ANLA~ANLN2 AND
ANLC~AFABE = '01'
INNER JOIN ANLB
ON ANLB~BUKRS = ANLA~BUKRS AND
ANLB~ANLN1 = ANLA~ANLN1 AND
ANLB~ANLN2 = ANLA~ANLN2 AND
ANLB~AFABE = '01' AND
ANLB~BDATU = '99991231'
LEFT JOIN ANLP
ON ANLP~BUKRS = ANLA~BUKRS AND
ANLP~PERAF = P_PERAF AND
ANLP~ANLN1 = ANLA~ANLN1 AND
ANLP~ANLN2 = ANLA~ANLN2 AND
ANLP~AFABER = '01'
LEFT JOIN TGSBT
ON ANLZ~GSBER = TGSBT~GSBER
LEFT JOIN CSKT
ON ANLZ~KOSTL = CSKT~KOSTL AND
CSKT~SPRAS = SY-LANGU AND
CSKT~DATBI = '99991231' AND
CSKT~KOKRS = 'ZSUN'
WHERE ANLA~BUKRS = P_BUKRS
AND ANLC~GJAHR = P_GJAHR
AND ANLA~ANLN1 IN S_ANLN1
AND ANLA~ANLKL IN S_ANLKL
AND ANLZ~KOSTL IN S_KOSTL
AND ANLA~ORD41 IN S_ORD41
AND ANLZ~GSBER IN S_GSBER.
SORT ITAB BY GJAHR BUKRS ANLN1 ANLKL GDLGRP KOSTL.
DELETE ADJACENT DUPLICATES FROM ITAB
COMPARING GJAHR BUKRS ANLN1 ANLKL GDLGRP KOSTL.
LOOP AT ITAB.
"根据成本中心获取利润中心
SELECT SINGLE PRCTR
INTO ITAB-PRCTR
FROM CSKS
WHERE KOSTL = ITAB-KOSTL AND
KOKRS = 'ZSUN'.
"从供应商信息视图获取供应商名称
SELECT SINGLE MCOD1"匹配码搜索的搜索条件
INTO ITAB-LIEFE
FROM M_KREDI"生成匹配码ID KRED-I的视图
WHERE LIFNR = ITAB-LIFNR AND
BUKRS = P_BUKRS AND
LAND1 = 'CN'.
"删除非利润中心查询条件内的固定资产查询结果
IF ITAB-PRCTR NOT IN S_PRCTR.
DELETE ITAB.
CONTINUE.
ENDIF.
"获取利润中心的名称
IF ITAB-PRCTR IS NOT INITIAL.
SELECT SINGLE KTEXT
INTO ITAB-PKTEXT
FROM CEPCT"利润中心主数据文本
WHERE PRCTR = ITAB-PRCTR AND
SPRAS = SY-LANGU AND
KOKRS = 'ZSUN'.
ENDIF.
"获取当前期间的累计值
DATA : N TYPE I,
NC TYPE STRING.
DATA : F_ANBTR LIKE ANEP-ANBTR, "记账金额
F_BEGIN LIKE SY-DATUM,
F_END LIKE SY-DATUM.
N = P_PERAF.
NC = N.
IF N < 10.
CONCATENATE P_GJAHR '0' NC '01' INTO F_BEGIN.
ELSE.
CONCATENATE P_GJAHR NC '01' INTO F_BEGIN.
ENDIF.
"该函数获取某月的最后一天
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = F_BEGIN
IMPORTING
LAST_DAY_OF_MONTH = F_END
EXCEPTIONS
DAY_IN_NO_DATE = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
"计算某段期间内的记账金额,可以通过abep-bwasl来指定资产业务类型,提高查询
CLEAR : F_ANBTR.
SELECT SINGLE SUM( ANBTR )
INTO F_ANBTR
FROM ANEP"资产行项目
WHERE BUKRS = P_BUKRS
AND GJAHR = P_GJAHR
AND ANLN1 = ITAB-ANLN1
AND BZDAT BETWEEN '1900101' AND F_END
AND ANEP~AFABE = '01'.
"计算资产原值,为购置和生产费用(KANSW)资产重置费用(KAUFW)以及累计记账之和
ITAB-YZ = ITAB-KANSW + ITAB-KAUFW + F_ANBTR.
*折旧率----具体看公司了
"检查是否存在资产折旧记录,若有,则根据折旧码来推算扣除折旧的资产余值
SELECT SINGLE *
FROM ANLB"折旧期限
WHERE ANLN1 = ITAB-ANLN1 AND
BUKRS = P_BUKRS.
*707 ZSUN 0000 X 无折旧也无利息
*707 ZSUN DG20 X 2倍余额递减折旧法
*707 ZSUN DG25 X 2.5倍余额递减折旧法
*707 ZSUN DG30 X 3倍余额递减折旧法
*707 ZSUN GL20 X 建筑物直线法 2%
*707 ZSUN&