在我要做的程序中,它显示每个公司代码的信息。例如:
Fiscal Year | 4030 | 4020 | 4040 | 4050 | 4070 | TOTAL
1/2010 | 423.12 | 89.79 ..... | ......| .... | .....
2/2010 |234.00 | 04.38 ..... | ...... | .... |.....
3/2010 |432.652 | 98.80 ..... | ...... | .... | .....
.
.
12/2010 |978.687 | 089.787 .... | ...... | .... | .....
我的问题是我如何对字段中的所有数据求和fkdat
日期和dmbtr
金额? 因为在字段fkdat
中有很多相同的日期。我想做的只是汇总所有相同的日期和数量,以便我可以在每个工厂代码中显示信息和数量。我怎样才能在侧面循环中做到这一点?
SELECT-OPTIONS:
BUKRS for wa_zfi_vbrp_bseg_1-BUKRS OBLIGATORY NO INTERVALS.
PARAMETERS:
p_gjahr LIKE zfi_vbrp_bseg-gjahr OBLIGATORY.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 10(15) text-005.
SELECTION-SCREEN POSITION 35.
select-options: p_perde for ce1osgc-perde no-display.
SELECTION-SCREEN END OF LINE.
START-OF-SELECTION.
SELECT
zf~gjahr
zf~bukrs
zf~dmbtr
zf~monat
zf~vbeln
zf~hkont
fi~fkdat
vb~werks
INTO CORRESPONDING FIELDS OF TABLE it_zfi_vbrp_bseg_1
FROM zfi_vbrp_bseg as zf
INNER JOIN vbrp as vb ON vb~vbeln EQ zf~vbeln
INNER JOIN zfi_vbrp as fi ON zf~vbeln EQ fi~vbeln
WHERE zf~bukrs in bukrs
AND zf~gjahr EQ p_gjahr
GROUP BY
zf~gjahr
zf~bukrs
zf~dmbtr
zf~monat
zf~vbeln
zf~hkont
fi~fkdat
"zf-perio
vb~werks.
"-------------------------------------------------------------------------------------------------------------
DATA:" l_budat TYPE budat,
date TYPE string,
date1 TYPE string,
date2 TYPE STRING,
out TYPE string,
vvdcs TYPE ce1osgc-vvdcs.
DATA: pos TYPE i VALUE 40,
pos2 TYPE i VALUE 57,
pos3 TYPE i VALUE 75,
pos4 TYPE i VALUE 93,
pos5 TYPE i VALUE 110.
IF SY-SUBRC EQ 0.
LOOP AT it_zfi_vbrp_bseg_1 INTO wa_zfi_vbrp_bseg_1.
AT FIRST.
WRITE: /01(150) SY-ULINE,
/01 SY-VLINE,
11 'Fiscal Year', 36 SY-VLINE,
40 '4030', 55 SY-VLINE,
57 '4020', 73 SY-VLINE,
75 '4050', 91 SY-VLINE,
93 '4040', 108 SY-VLINE,
110 '4070', 127 SY-VLINE,
129 'Total', 140 SY-VLINE,
(150) SY-ULINE.
ENDAT.
IF wa_zfi_vbrp_bseg_1-werks EQ '4030'.
WRITE AT pos wa_zfi_vbrp_bseg_1-dmbtr.
ENDIF.
IF wa_zfi_vbrp_bseg_1-werks EQ '4020'.
WRITE AT pos2 wa_zfi_vbrp_bseg_1-dmbtr.
ENDIF.
IF wa_zfi_vbrp_bseg_1-werks EQ '4050'.
WRITE AT pos3 wa_zfi_vbrp_bseg_1-dmbtr.
ENDIF.
IF wa_zfi_vbrp_bseg_1-werks EQ '4040'.
WRITE AT pos4 wa_zfi_vbrp_bseg_1-dmbtr.
ENDIF.
IF wa_zfi_vbrp_bseg_1-werks EQ '4070'.
WRITE AT pos5 wa_zfi_vbrp_bseg_1-dmbtr.
ENDIF.
ENDLOOP.
ENDIF.
尝试在循环中使用COLLECT
。
检查如何使用 COLLECT 语句:
LOOP AT it_zfi_vbrp_bseg_1 INTO wa_zfi_vbrp_bseg_1.
COLLECT wa_zfi_vbrp_bseg_1 INTO it_zfi_vbrp_bseg_2. " You have to declear a new internal table.
ENDLOOP.
LOOP AT it_zfi_vbrp_bseg_2 INTO wa_zfi_vbrp_bseg_1.
WRITE Causes......
.........
ENDLOOP.