data: begin of it_date occurs 0,
lv_date like vbak-vdatu,
end of it_date.
data: begin of it_month occurs 0,
month(8) type c,
end of it_month.
获取每个SO的所有交货日期(yyyymm)
select j_3arqda
into table it_date
from vbap
for all entries in it_so
where vbeln = it_so-vbeln.
sort it_date by lv_date.
DELETE ADJACENT DUPLICATES FROM it_date.
describe table it_date lines lv_line.
if lv_line <> 0.
read table it_date index lv_line.
lv_max = it_date-lv_date.
read table it_date index 1.
lv_min = it_date-lv_date.
endif.
append lines of it_date to it_month.
loop at it_month.
it_month-month = it_month-month+0(6).
modify it_month index sy-tabix.
endloop.
sort it_month by month.
DELETE ADJACENT DUPLICATES FROM it_month.
delete it_month where month = '000000'.
获取每个日期(yyyymm)下订单总数量
data wa_field(14) type c.
data wa_tabix type I.
data no(2) type c.
data tmp(15) type p decimals 2.
field-symbols: <f_qty>.
field-symbols: <f_qty2>.
loop at it_month.
no = sy-tabix.
if wa_tabix < 10.
concatenate 'it_tab-field' '0' no into wa_field.
else.
concatenate 'it_tab-field' no into wa_field.
endif.
perform get_rdate using it_month-month.
select sum( kwmeng ) into tmp from vbap
where vbeln = it_tab-vbeln
and abgru = space
and j_3arqda in r_date.
assign (wa_field) to <f_qty>.
<f_qty> = tmp.
it_tab-ttl_qty = it_tab-ttl_qty + tmp.
clear: tmp, wa_field.
endloop.
FORM GET_RDATE USING p_date.
data p_from like vbak-vdatu.
data p_to like vbak-vdatu.
concatenate p_date+0(6) '01' into p_from.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = p_from
IMPORTING
LAST_DAY_OF_MONTH = p_to.
clear r_date.
refresh r_date.
r_date-sign = 'I'.
r_date-option = 'BT'.
r_date-low = p_from.
r_date-high = p_to.
append r_date.
clear: p_from,p_to.
ENDFORM. " GET_RDATE
控制ALV表头中日期部分动态输出:
data: t_atwrt(15) type c value 'IT_TAB'.
data: t_atwrt2(15) type c value 'IT_TAB'.
data: t_atwrt3(25) type c value 'IT_TAB'.
field-symbols: <f_atwrt>.
field-symbols: <f_atwrt2>.
t_atwrt+0(12) = 'IT_TAB-FIELD'.
t_atwrt3+0(20) = 'IT_qty_month-FIELD'.
clear lv_tabix.
data no(2) type c.
loop at it_month.
lv_tabix = sy-tabix.
if lv_tabix < 10.
no = lv_tabix.
concatenate '0' no into no.
t_atwrt3+19(2) = no.
t_atwrt+12(2) = no.
else.
t_atwrt3+19(2) = no.
t_atwrt+12(2) = no.
endif.
assign t_atwrt to <f_atwrt>.
assign t_atwrt3 to <f_atwrt2>.
if <f_atwrt2> ne '0'.
clear fc_hier.
fc_hier-fieldname = t_atwrt+7(7).
fc_hier-tabname = 'IT_TAB'.
fc_hier-seltext_l = it_month-month.
append fc_hier.
endif.
clear no.
endloop.