Be a simple man
分类:
2007-11-29 09:42:29
*& Program Name : ZFI_RP032
*& Title : 燃料成本因素分析表(当月)
*& Module Name : FI
*& Sub-Module :
*& Author : Jason Zhang
REPORT zfi_rp032 NO STANDARD PAGE HEADING
LINE-SIZE 400
LINE-COUNT 200(0)
MESSAGE-ID zfimeg.
*----------------------------------------------------------------------*
* 声明引用数据表
*----------------------------------------------------------------------*
TABLES: t001,cosr,coep.
*----------------------------------------------------------------------*
* 宏定义
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* 变量定义
*----------------------------------------------------------------------*
DATA:BEGIN OF gt_ys OCCURS 0,
bukrs LIKE t001-bukrs, "公司代码
ysgdl LIKE cosr-sme001, "预算供电量
ysgdmh LIKE cosr-sme001, "预算供电煤耗
ysgdbml LIKE cosr-sme001, "预算供电标煤量
yssrl LIKE cosr-sme001, "预算售热量
ysgrmh LIKE cosr-sme001, "预算供热煤耗
ysgrbml LIKE cosr-sme001, "预算供热标煤量
ysbmlzj LIKE cosr-sme001, "预算标煤量总计
ysbmdj LIKE cosr-sme001, "预算标煤单价
ysrlf LIKE cosr-sme001, "预算燃料费
END OF gt_ys.
*最终结果内表
DATA:BEGIN OF gt_table OCCURS 0,
xh(2), "序号
bukrs LIKE t001-bukrs,
butxt LIKE t001-butxt, "公司描述
ysgdl LIKE cosr-sme001, "预算供电量
ysgdmh LIKE cosr-sme001, "预算供电煤耗
ysgdbml LIKE cosr-sme001, "预算供电标煤量
yssrl LIKE cosr-sme001, "预算售热量
ysgrmh LIKE cosr-sme001, "预算供热煤耗
ysgrbml LIKE cosr-sme001, "预算供热标煤量
ysbmlzj LIKE cosr-sme001, "预算标煤量总计
ysbmdj LIKE cosr-sme001, "预算标煤单价
ysrlf LIKE cosr-sme001, "预算燃料费
sjgdl LIKE cosr-sme001, "实际供电量
sjgdmh LIKE cosr-sme001, "实际供电煤耗
sjgdbml LIKE cosr-sme001, "实际供电标煤量
sjsrl LIKE cosr-sme001, "实际售热量
sjgrmh LIKE cosr-sme001, "实际供热煤耗
sjgrbml LIKE cosr-sme001, "实际供热标煤量
sjbmlzj LIKE cosr-sme001, "实际标煤量总计
sjbmdj LIKE cosr-sme001, "实际标煤单价
sjrlf LIKE cosr-sme001, "实际燃料费
gdzb_gdlce LIKE cosr-sme001, "供电指标供电量差额
gdzb_gdmh LIKE cosr-sme001, "供电指标供电煤耗
gdzb_gdbml LIKE cosr-sme001, "供电指标供电标煤量
gdzb_yxrlf LIKE cosr-sme001, "供电指标影响燃料费
gdzb_sjgdl LIKE cosr-sme001, "供电指标实际供电量
gdzb_gdmhce LIKE cosr-sme001, "供电指标供电煤耗差额
gdzb_yxgdbml LIKE cosr-sme001, "供电指标影响供电标煤量
gdzb_yxrlf2 LIKE cosr-sme001, "供电指标影响燃料费2
grzb_xslce LIKE cosr-sme001, "供热指标售热量差额
grzb_grmh LIKE cosr-sme001, "供热指标供热煤耗
grzb_yxgrbml LIKE cosr-sme001, "供热指标影响供热标煤量
grzb_yxrlf LIKE cosr-sme001, "供热指标影响燃料费
grzb_sjsrl LIKE cosr-sme001, "供热指标实际售热量
grzb_grmhce LIKE cosr-sme001, "供热指标供热煤耗差额
grzb_grbml LIKE cosr-sme001, "供热指标影响供电标煤量
grzb_yxrlf2 LIKE cosr-sme001, "供热指标影响燃料费2
bmdj_sjzhbml LIKE cosr-sme001, "标煤单价实际综合标煤量
bmdj_bmdjce LIKE cosr-sme001, "标煤单价标煤单价差额
bmdj_yxrlf LIKE cosr-sme001, "标煤单价影响燃料费
gxyshjyx_yxrlf LIKE cosr-sme001, "各项因素合计影响-影响燃料费
gxyshjyxcy_yxrlf LIKE cosr-sme001, "各项因素合计影响差异-影响燃料费
END OF gt_table.
*----------------------------------------------------------------------*
* 屏幕查询条件定义
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: p_bukrs FOR bkpf-bukrs OBLIGATORY.
*PARAMETERS:p_bukrs LIKE bkpf-bukrs OBLIGATORY,
PARAMETERS:p_gjahr LIKE bkpf-gjahr OBLIGATORY DEFAULT sy-datum+0(4),
p_monat LIKE bkpf-monat OBLIGATORY DEFAULT sy-datum+4(2).
SELECTION-SCREEN END OF BLOCK blk1.
SELECTION-SCREEN BEGIN OF SCREEN 0500 TITLE text-002 AS WINDOW.
PARAMETERS:p_file LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF SCREEN 0500.
*PARAMETERS: r1 RADIOBUTTON GROUP r DEFAULT 'X',
* r2 RADIOBUTTON GROUP r.
AT SELECTION-SCREEN.
*权限检查
PERFORM bukrs_auth_check USING p_bukrs '03'.
IF sy-subrc NE 0.
MESSAGE i008 WITH p_bukrs.
STOP.
ENDIF.
INITIALIZATION.
CONCATENATE path 'ZFI_RP032\ZFI_RP032.XLS' INTO p_file.
START-OF-SELECTION.
PERFORM main.
*主程序
FORM main.
PERFORM get_data.
PERFORM down_to_excel.
ENDFORM. "MAIN
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data .
*定义变量,指针
DATA: n_point LIKE sy-index.
DATA: n_point_2 LIKE sy-index.
FIELD-SYMBOLS:
*cosr实际数
DATA: BEGIN OF gt_temp OCCURS 0,
objnr LIKE cosr-objnr,
stagr LIKE cosr-stagr,
sme001 LIKE cosr-sme001,
sme002 LIKE cosr-sme002,
sme003 LIKE cosr-sme003,
sme004 LIKE cosr-sme004,
sme005 LIKE cosr-sme005,
sme006 LIKE cosr-sme006,
sme007 LIKE cosr-sme007,
sme008 LIKE cosr-sme008,
sme009 LIKE cosr-sme009,
sme010 LIKE cosr-sme010,
sme011 LIKE cosr-sme011,
sme012 LIKE cosr-sme012,
sme013 LIKE cosr-sme013,
sme014 LIKE cosr-sme014,
sme015 LIKE cosr-sme015,
sme016 LIKE cosr-sme016,
END OF gt_temp.
DATA: BEGIN OF gt_temp2 OCCURS 0.
INCLUDE STRUCTURE gt_temp.
DATA: END OF gt_temp2.
*燃料费内表
DATA: BEGIN OF gt_faglflext OCCURS 0,
rbukrs LIKE faglflext-rbukrs,
hsl01 LIKE faglflext-hsl01,
hsl02 LIKE faglflext-hsl02,
hsl03 LIKE faglflext-hsl03,
hsl04 LIKE faglflext-hsl04,
hsl05 LIKE faglflext-hsl05,
hsl06 LIKE faglflext-hsl06,
hsl07 LIKE faglflext-hsl07,
hsl08 LIKE faglflext-hsl08,
hsl09 LIKE faglflext-hsl09,
hsl10 LIKE faglflext-hsl10,
hsl11 LIKE faglflext-hsl11,
hsl12 LIKE faglflext-hsl12,
hsl13 LIKE faglflext-hsl13,
hsl14 LIKE faglflext-hsl14,
hsl15 LIKE faglflext-hsl15,
hsl16 LIKE faglflext-hsl16,
END OF gt_faglflext.
*发电生产指标:供电量
SELECT objnr stagr
sme001 sme002 sme003 sme004 sme005 sme006 sme007
sme008 sme009 sme010 sme011 sme012 sme013 sme014
sme015 sme016
FROM cosr
INTO CORRESPONDING FIELDS OF TABLE gt_temp
WHERE wrttp = '04' AND
objnr LIKE 'KSNUPC00%' AND
stagr IN ('SD0003','SD0010','SR0002','SR0003') AND
gjahr = p_gjahr.
*实际燃料费:
SELECT rbukrs hsl01 hsl02 hsl03 hsl04 hsl05 hsl06 hsl07 hsl08
hsl09 hsl10 hsl11 hsl12 hsl13 hsl14 hsl15 hsl16
FROM faglflext
INTO CORRESPONDING FIELDS OF gt_faglflext
WHERE ryear = p_gjahr AND
racct IN ('4101010100','4101010200','4101010300') AND
rbukrs IN p_bukrs.
COLLECT gt_faglflext.
ENDSELECT.
*发电生产指标:供电量 为*9101-*9199
LOOP AT gt_temp WHERE objnr+14(2) = '00' OR objnr+12(2) <> '91'.
IF sy-subrc = 0.
DELETE gt_temp.
ENDIF.
ENDLOOP.
*截断累计:
SORT gt_temp BY objnr .
LOOP AT gt_temp.
gt_temp2-objnr = gt_temp-objnr+0(12).
gt_temp2-stagr = gt_temp-stagr.
gt_temp2-sme001 = gt_temp-sme001.
gt_temp2-sme002 = gt_temp-sme002.
gt_temp2-sme003 = gt_temp-sme003.
gt_temp2-sme004 = gt_temp-sme004.
gt_temp2-sme005 = gt_temp-sme005.
gt_temp2-sme006 = gt_temp-sme006.
gt_temp2-sme007 = gt_temp-sme007.
gt_temp2-sme008 = gt_temp-sme008.
gt_temp2-sme009 = gt_temp-sme009.
gt_temp2-sme010 = gt_temp-sme010.
gt_temp2-sme011 = gt_temp-sme011.
gt_temp2-sme012 = gt_temp-sme012.
gt_temp2-sme013 = gt_temp-sme013.
gt_temp2-sme014 = gt_temp-sme014.
gt_temp2-sme015 = gt_temp-sme015.
gt_temp2-sme016 = gt_temp-sme016.
COLLECT gt_temp2.
ENDLOOP.
*选择为输入公司代码的数据
LOOP AT gt_temp2.
IF gt_temp2-objnr+8(4) NOT IN p_bukrs.
DELETE gt_temp2.
ENDIF.
ENDLOOP.
*************将temp2的结果导入gt_table最终内表中,判断gt_table中是否存在该行项目,如果存在modify,新纪录append
n_point = p_monat + 2.
LOOP AT gt_temp2.
ASSIGN COMPONENT n_point OF STRUCTURE gt_temp2 TO
READ TABLE gt_table WITH KEY bukrs = gt_temp2-objnr+8(4).
IF sy-subrc = 0.
IF gt_temp2-stagr = 'SD0003'.
MOVE
ELSEIF gt_temp2-stagr = 'SD0010' .
MOVE
ELSEIF gt_temp2-stagr = 'SR0002'.
MOVE
ELSEIF gt_temp2-stagr = 'SR0003'.
MOVE
ENDIF.
MODIFY gt_table INDEX sy-tabix.
ELSE.
IF gt_temp2-stagr = 'SD0003'.
MOVE
ELSEIF gt_temp2-stagr = 'SD0010' .
MOVE
ELSEIF gt_temp2-stagr = 'SR0002'.
MOVE
ELSEIF gt_temp2-stagr = 'SR0003'.
MOVE
ENDIF.
gt_table-bukrs = gt_temp2-objnr+8(4).
APPEND gt_table.
ENDIF.
ENDLOOP.
*填充行号和公司代码,公司名称描述字段
LOOP AT gt_table.
gt_table-xh = sy-tabix .
SELECT SINGLE butxt FROM t001 INTO gt_table-butxt WHERE bukrs = gt_table-bukrs.
MODIFY gt_table.
ENDLOOP.
*将gt_faglflext导入gt_table
n_point_2 = p_monat + 1.
LOOP AT gt_faglflext.
ASSIGN COMPONENT n_point_2 OF STRUCTURE gt_faglflext TO
READ TABLE gt_table WITH KEY bukrs = gt_faglflext-rbukrs.
IF sy-subrc = 0.
MOVE
MODIFY gt_table INDEX sy-tabix.
ENDIF.
ENDLOOP.
*根据各公式计算:
LOOP AT gt_table.
gt_table-sjgdmh = gt_table-sjgdbml / gt_table-sjgdl * 1000.
gt_table-sjgrmh = gt_table-sjgrbml / gt_table-sjsrl * 1000.
gt_table-sjbmlzj = gt_table-sjgdbml + gt_table-sjgrbml.
gt_table-sjbmdj = gt_table-sjrlf / gt_table-sjbmlzj.
gt_table-gdzb_gdlce = gt_table-sjgdl - gt_table-ysgdl.
gt_table-gdzb_gdmh = gt_table-ysgdmh.
gt_table-gdzb_gdbml = gt_table-gdzb_gdlce * gt_table-gdzb_gdmh / 1000.
gt_table-gdzb_yxrlf = gt_table-gdzb_gdbml * gt_table-ysbmdj / 1000.
gt_table-gdzb_sjgdl = gt_table-sjgdl.
gt_table-gdzb_gdmhce = gt_table-sjgdmh - gt_table-ysgdmh.
gt_table-gdzb_yxgdbml = gt_table-gdzb_sjgdl * gt_table-gdzb_gdmhce / 1000.
gt_table-gdzb_yxrlf2 = gt_table-ysbmdj * gt_table-gdzb_yxgdbml / 1000.
gt_table-grzb_xslce = gt_table-sjsrl - gt_table-yssrl.
gt_table-grzb_grmh = gt_table-ysgrmh.
gt_table-grzb_yxgrbml = gt_table-grzb_xslce * gt_table-grzb_grmh / 1000.
gt_table-grzb_yxrlf = gt_table-grzb_yxgrbml * gt_table-ysbmdj / 1000.
gt_table-grzb_sjsrl = gt_table-sjsrl.
gt_table-grzb_grmhce = gt_table-sjgrmh - gt_table-ysgrmh.
gt_table-grzb_grbml = gt_table-grzb_sjsrl * gt_table-grzb_grmhce / 1000.
gt_table-grzb_yxrlf2 = gt_table-grzb_grbml * gt_table-ysbmdj / 1000.
gt_table-bmdj_sjzhbml = gt_table-sjbmlzj.
gt_table-bmdj_bmdjce = gt_table-sjbmdj - gt_table-ysbmdj.
gt_table-bmdj_yxrlf = gt_table-bmdj_sjzhbml * gt_table-bmdj_bmdjce / 1000.
gt_table-gxyshjyx_yxrlf = gt_table-gdzb_yxrlf + gt_table-gdzb_yxrlf2 + gt_table-grzb_yxrlf + gt_table-grzb_yxrlf2 + gt_table-bmdj_yxrlf.
* gxyshjyxcy_yxrlf
MODIFY gt_table.
ENDLOOP.
ENDFORM. " get_data