DATA(lv_gjahr) = p_gjahr - 1. SELECT anla~bukrs, anla~anln1, anla~anln2, anla~anlkl, anla~txt50, anla~txa50, anla~menge, anla~meins, anlz~kostl, anlz~kostlv, anlz~ps_psp_pnr2, anla~posnr, anla~lifnr, but000~name_org1, anla~herst, anla~ord42, anla~ord41, anla~deakt, ztps005~zzxmbm, ztps005~zzcwzcbm, ztps005~zzcwzcbm1, ztps005~zzbdfs, ztps005~zzksrq, ztps005~zzzcwz, ztps005~zzzycz, ztps005~zzcs, ztps005~zzcsmc, ztps005~zzzqid, ztps005~zzzcbgr, ztps005~zzzcbgrmc, ztps005~zzzcsyr, ztps005~zzzcsyrmc, ztps005~zzzlqjf, ztps005~zzzlqjt, anla~aktiv, anlb~ndjar, anlb~ndper, anlc~kansw, anlc~answl, anlc~nafag, anlc~aafag, anlb~afasl, "折旧码 anlb~schrw, ( anlc~knafa + anlc~kaafa ) AS knafa,"期初累计折旧 * ( anlc~nafag + anlc~aafag ) AS nafag, befor~kaufw AS kaufw_b, anlc~aufwp AS kaufw_t, ( anlc~nafav + anlc~aafav + anlc~nafal + anlc~aafal ) AS netwr FROM anla INNER JOIN anlb ON anlb~bukrs EQ anla~bukrs AND anlb~anln1 EQ anla~anln1 AND anlb~anln2 EQ anla~anln2 AND anlb~afabe EQ '01' INNER JOIN anlc ON anlc~bukrs EQ anla~bukrs AND anlc~anln1 EQ anla~anln1 AND anlc~anln2 EQ anla~anln2 AND anlc~afabe EQ '01' LEFT JOIN anlc AS befor ON befor~bukrs EQ anla~bukrs AND befor~anln1 EQ anla~anln1 AND befor~anln2 EQ anla~anln2 AND befor~afabe EQ '01' AND befor~gjahr EQ @lv_gjahr INNER JOIN anlz ON anlz~bukrs EQ anla~bukrs AND anlz~anln1 EQ anla~anln1 AND anlz~anln2 EQ anla~anln2 LEFT JOIN ztps005 ON ztps005~bukrs EQ anla~bukrs AND ztps005~anln1 EQ anla~anln1 AND ztps005~anln2 EQ anla~anln2 * INNER JOIN anlt ON anlt~bukrs EQ anla~bukrs * AND anlt~anln1 EQ anla~anln1 * AND anlt~anln2 EQ anla~anln2 * AND anlt~spras EQ @sy-langu LEFT JOIN but000 ON but000~partner EQ anla~lifnr INTO CORRESPONDING FIELDS OF TABLE @gt_data WHERE anla~bukrs IN @s_bukrs AND anla~anln1 IN @s_anln1 AND anla~anln2 IN @s_anln2 AND anlc~gjahr EQ @p_gjahr AND anla~txt50 IN @s_txt50 AND anla~anlkl IN @s_anlkl AND anlz~kostl IN @s_kostl. IF gt_data IS INITIAL. MESSAGE '查询无数据' TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. SELECT bukrs, anln1, anln2, SUM( anbtr ) AS anbtr FROM anep WHERE bukrs IN @s_bukrs AND anln1 IN @s_anln1 AND anln2 IN @s_anln2 AND gjahr EQ @p_gjahr AND afabe EQ '01' AND ( bwasl LIKE '2%' OR bwasl LIKE 'Z2%' ) GROUP BY bukrs,anln1,anln2 INTO TABLE @DATA(lt_anep). SORT lt_anep BY bukrs anln1 anln2. SELECT bukrs, anln1, anln2, ( nafaz + aafaz ) AS nafaz INTO TABLE @DATA(lt_anlp) FROM anlp WHERE bukrs IN @s_bukrs AND anln1 IN @s_anln1 AND anln2 IN @s_anln2 AND afaber EQ '01' AND gjahr EQ @p_gjahr AND peraf EQ @p_peraf. SORT lt_anlp BY bukrs anln1 anln2. *****ADD BY ZJ 20240218 S 增加字段逻辑 "期初减值逻辑 "根据公司代码+资产号分别ANLC-KAUFN值(期初以前年度累计重估折旧)、 "ANEP-AUFNZ(期初本年重估折旧)的累计数据为A WITH +i AS ( SELECT DISTINCT bukrs,anln1,anln2 FROM @gt_data AS k ) SELECT i~bukrs,i~anln1,i~anln2, SUM( a~kaufn + a~aufnv ) AS anbtr FROM +i AS i LEFT JOIN anlc AS a ON i~bukrs EQ a~bukrs AND i~anln1 EQ a~anln1 AND i~anln2 EQ a~anln2 AND a~afabe EQ '01' AND a~gjahr EQ @p_gjahr GROUP BY i~bukrs,i~anln1,i~anln2 INTO TABLE @DATA(lt_qcjzzj1). SORT lt_qcjzzj1 BY bukrs anln1 anln2. "根据界面公司代码+资产号取ANEP-BWASL=Z11、Z12且年度期间小于等于输入年度+期间行的ANBTR值; "按行金额+年度+期间计算截止每月折旧额, WITH +i AS ( SELECT DISTINCT bukrs,anln1,anln2 FROM @gt_data AS k ) SELECT i~bukrs,i~anln1,i~anln2, a~anbtr AS anbtr,a~bzdat FROM +i AS i LEFT JOIN anep AS a ON i~bukrs EQ a~bukrs AND i~anln1 EQ a~anln1 AND i~anln2 EQ a~anln2 AND a~afabe EQ '01' AND ( a~bwasl EQ 'Z11' OR a~bwasl EQ 'Z12' ) AND ( a~gjahr LT @p_gjahr OR ( a~gjahr EQ @p_gjahr AND a~peraf LE @p_peraf ) ) INTO TABLE @DATA(lt_qcjzzj2). SORT lt_qcjzzj2 BY bukrs anln1 anln2. DATA:lt_anlb TYPE TABLE OF gty_anlb. "取开始折旧期间,折旧期间 WITH +i AS ( SELECT DISTINCT bukrs,anln1,anln2 FROM @gt_data AS k ) SELECT i~bukrs,i~anln1,i~anln2, a~afabg,a~ndjar,a~ndper FROM +i AS i LEFT JOIN anlb AS a ON i~bukrs EQ a~bukrs AND i~anln1 EQ a~anln1 AND i~anln2 EQ a~anln2 AND a~afabe EQ '01' INTO TABLE @lt_anlb. SORT lt_anlb BY bukrs anln1 anln2. *****ADD BY ZJ 20240218 E 增加字段逻辑 DATA:lv_anbtr2 TYPE anlc-kaufn, lv_anbtr_a TYPE anlc-kaufn. gv_date = |{ sy-datum(4) - 1 }1201|. gv_date2 = |{ p_gjahr }{ p_peraf+1(2) }01|. gv_date3 = |{ p_gjahr }0101|. LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<fs_data>). READ TABLE lt_anep INTO DATA(lw_anep) WITH KEY bukrs = <fs_data>-bukrs anln1 = <fs_data>-anln1 anln2 = <fs_data>-anln2 BINARY SEARCH. IF sy-subrc EQ 0. <fs_data>-bqjsyz = lw_anep-anbtr. ENDIF. <fs_data>-qmzcyz = <fs_data>-kansw + <fs_data>-answl - <fs_data>-bqjsyz. "残值 IF <fs_data>-schrw IS INITIAL AND <fs_data>-afasl = 'Z005'. <fs_data>-schrw = <fs_data>-qmzcyz * '0.05'."残值 ELSEIF <fs_data>-schrw IS NOT INITIAL. <fs_data>-schrw = <fs_data>-schrw. ENDIF. "残值率 IF <fs_data>-afasl = 'Z005'. <fs_data>-schrw_proz = '0.05'. ELSEIF <fs_data>-afasl EQ 'Z010'. <fs_data>-schrw_proz = '0.10'. ENDIF. "ANLA-DEAKT为空时 IF <fs_data>-deakt IS INITIAL. <fs_data>-answl = <fs_data>-answl."取ANLC- ANSWL,作为本期增加资产原值 <fs_data>-nafag = <fs_data>-nafag + <fs_data>-aafag. "本期增加累计折旧 ELSE. <fs_data>-zbqjszj = <fs_data>-nafag + <fs_data>-aafag."本期减少累计折旧 ENDIF. READ TABLE lt_anlp INTO DATA(lw_anlp) WITH KEY bukrs = <fs_data>-bukrs anln1 = <fs_data>-anln1 anln2 = <fs_data>-anln2 BINARY SEARCH. IF sy-subrc EQ 0. <fs_data>-nafaz = lw_anlp-nafaz."本月折旧 ENDIF. "期末累计折旧=期初累计折旧+本期增加累计折旧-本期减少累计折旧 <fs_data>-qmljzj = <fs_data>-knafa + <fs_data>-nafag - <fs_data>-zbqjszj. * "账面价值 * <fs_data>-netwr = <fs_data>-netwr + <fs_data>-qmzcyz + <fs_data>-qmljzj - <fs_data>-kaufw_b + <fs_data>-kaufw_t. **************ADD BY ZJ 20240218 S 增加字段逻辑 "以前年度重估折旧 CLEAR:lv_anbtr_a. READ TABLE lt_qcjzzj1 INTO DATA(ls_qcjzzj1) WITH KEY bukrs = <fs_data>-bukrs anln1 = <fs_data>-anln1 anln2 = <fs_data>-anln2 BINARY SEARCH. IF sy-subrc EQ 0. lv_anbtr_a = ls_qcjzzj1-anbtr. ENDIF. CLEAR:lv_anbtr2. LOOP AT lt_qcjzzj2 INTO DATA(ls_qcjzzj2) WHERE bukrs = <fs_data>-bukrs AND anln1 = <fs_data>-anln1 AND anln2 = <fs_data>-anln2. READ TABLE lt_anlb INTO DATA(ls_anlb) WITH KEY bukrs = <fs_data>-bukrs anln1 = <fs_data>-anln1 anln2 = <fs_data>-anln2 BINARY SEARCH. PERFORM frm_cal_jzzj USING ls_qcjzzj2-anbtr ls_anlb <fs_data>-deakt ls_qcjzzj2-bzdat CHANGING lv_anbtr2."计算减值折旧金额 CLEAR:ls_qcjzzj2,ls_anlb. ENDLOOP. "期初减值折旧= 以前年度重估折旧额 + 以前年度重估折旧 <fs_data>-qcjzzj = lv_anbtr_a + lv_anbtr2. IF <fs_data>-deakt IS NOT INITIAL. "当资产报废时填写,即ANLA-DEAKT不等于空时取本期增加减值折旧 <fs_data>-bqjsjzzj = <fs_data>-bqzjjzzj. "当资产报废时填写,即ANLA-DEAKT不等于空时,取处置该资产时转出当年期初减值金额(固定资产清理)即等于本年度重估价值金额 <fs_data>-bqjsjz = <fs_data>-kaufw_t. ENDIF. "期末减值折旧 = 期初减值折旧+本期增加减值折旧-本期减少减值折旧 <fs_data>-qmjzzj = <fs_data>-qcjzzj + <fs_data>-bqzjjzzj - <fs_data>-bqjsjzzj. "期末减值 = 以前年度重估价值+本年度重估价值金额-本期减少减值 <fs_data>-qmjz = <fs_data>-kaufw_b + <fs_data>-kaufw_t - <fs_data>-bqjsjz. **************ADD BY ZJ 20240218 E 增加字段逻辑 "选择屏幕期间大于等于报废期间的话 净值这里就是0 ** IF gv_date2(6) GE <fs_data>-deakt(6). ** <fs_data>-netwr = 0. ** ENDIF. "账面价值 <fs_data>-netwr = <fs_data>-netwr + <fs_data>-qmzcyz + <fs_data>-qmljzj - <fs_data>-kaufw_b + <fs_data>-kaufw_t + <fs_data>-qmjzzj. "取公司名称 SELECT SINGLE butxt FROM t001 INTO <fs_data>-butxt WHERE bukrs = <fs_data>-bukrs AND spras = sy-langu. "取成本中心描述 SELECT SINGLE name1 FROM csks INTO <fs_data>-name1 WHERE kostl = <fs_data>-kostl AND spras = sy-langu. "取变动方式名称 SELECT SINGLE zzbdfsmc FROM ztps113 INTO <fs_data>-zzbdfsmc WHERE zzbdfs = <fs_data>-zzbdfs. ENDLOOP. END-OF-SELECTION. CLEAR gs_layout. REFRESH gt_fieldcat. gs_layout-cwidth_opt = 'X'."最优列宽 gs_layout-zebra = 'X'."“显示成斑马纹样式 * gs_layout-box_fname = 'SEL'. "创建动态内表 PERFORM frm_insert_structure USING: 'bukrs' '公司代码', 'butxt' '公司名称', 'anln1 ' '主要资产编号', 'anln2 ' '资产子编号', 'anlkl ' '资产类', 'txt50 ' '资产描述', 'txa50 ' '附加资产描述(规格型号)', 'menge ' '数量', 'meins ' '计量单位', 'kostl ' '成本中心', 'name1 ' '成本中心描述', 'kostlv ' '责任成本中心', 'ps_psp_pnr2 ' 'WBS 要素 (成本)', 'posnr ' 'WBS元素号(投建项目号)', 'lifnr ' '供应商', 'name_org1 ' '供应商名称', 'herst ' '制造商', 'ord42 ' '资产状态', 'ord41 ' '卡片来源', 'zzxmbm ' '第三方项目编码', 'zzcwzcbm ' '资产编码', 'zzcwzcbm1 ' 'EAM资产编码', 'zzbdfs ' '变动方式', 'zzbdfsmc ' '变动方式名称', 'zzksrq ' '开始使用日期', 'zzzcwz ' '资产位置', 'zzzycz ' '自用还是出租', 'zzcs ' '城市', 'zzcsmc ' '城市名称', 'zzzqid ' '桩群ID', 'zzzcbgr ' '资产保管人', 'zzzcbgrmc ' '资产保管人名称', 'zzzcsyr ' '资产使用人', 'zzzcsyrmc ' '资产使用人名称', 'zzzlqjf ' '租赁期间从', 'zzzlqjt ' '租赁期间到', 'aktiv ' '入账日期', 'ndjar ' '计划使用寿命(年)', 'ndper ' '计划使用寿命(月)', 'schrw_proz ' '残值率', 'kansw ' '期初资产原值', 'answl ' '本期增加资产原值', 'bqjsyz ' '本期减少原值', 'qmzcyz ' '期末资产原值', 'schrw ' '残值', 'knafa ' '期初累计折旧', 'nafag ' '本期增加累计折旧', 'zbqjszj ' '本期减少累计折旧', 'nafaz ' '本月折旧', 'qmljzj ' '期末累计折旧', 'netwr ' '账面价值', 'kaufw_b ' '期初资产减值', 'kaufw_t ' '本期增加资产减值', 'qcjzzj ' '期初减值折旧', 'bqzjjzzj ' '本期增加减值折旧', 'bqjsjzzj ' '本期减少减值折旧', 'qmjzzj ' '期末减值折旧', 'bqjsjz ' '本期减少减值', 'qmjz ' '期末减值', 'deakt ' '资产处置日期'.
标签:anla,报表,代码,折旧,明细,anln1,anln2,EQ,bukrs From: https://www.cnblogs.com/hw19970918/p/18123261