*&---------------------------------------------------------------------*
*& 包含 ZFIR090_TOP
*&---------------------------------------------------------------------*
TABLES:vbak,vbap,acdoca.
TYPE-POOLS:slis.
"OOALV-DEFINITION
DATA go_alv_grid TYPE REF TO cl_gui_alv_grid.
DATA lo_container TYPE REF TO cl_gui_custom_container.
DATA ok_code TYPE sy-ucomm.
DATA ok_save TYPE sy-ucomm.
TYPES: BEGIN OF gts_data,
kunnr TYPE vbak-kunnr, "客户;
name1 TYPE kna1-name1, "客户名称
matnr TYPE acdoca-matnr, "物料编码
zuonr TYPE acdoca-zuonr, "DN编号
zuonr_f TYPE char10, "DN编号前十位
zuonr_b TYPE char6, "DN编号后六位
wadat_ist TYPE likp-wadat_ist, "DN时间
msl TYPE acdoca-msl, "销售数量
werks TYPE acdoca-werks, "工厂
runit TYPE acdoca-runit, "单位
hsl TYPE acdoca-hsl, "发出商品金额
kdauf TYPE zdn_create_his-kdauf, "销售订单
kdpos TYPE zdn_create_his-kdpos, "销售订单项目
netpr TYPE vbap-netpr, "净价
kpein TYPE vbap-kpein, "定价单位
umzin TYPE vbap-umzin, "转换因子
umziz TYPE vbap-umziz, "转换因子
netsr TYPE vbap-netpr, "销售收入
END OF gts_data.
DATA: gt_data TYPE TABLE OF gts_data WITH HEADER LINE.
CONSTANTS:p_rldnr TYPE acdoca-rldnr VALUE '0L'.
CONSTANTS:p_rrcty TYPE acdoca-rrcty VALUE 0 .
CONSTANTS:p_racct TYPE acdoca-racct VALUE '1406010100'.
CONSTANTS:p_awtyp TYPE acdoca-awtyp VALUE 'BKPFF'.
CONSTANTS:selected VALUE 'X'.
DATA: controls_created.
DATA out_01 TYPE char30. "法人公司
DATA out_02 TYPE char30. "截止至日期
DATA out_03 TYPE char30. "编制人
DATA out_04 TYPE char30. "币别
DATA out_05 TYPE char16 VALUE '0'. "销售收入-期末金额
DATA out_06 TYPE char16 VALUE '0'. "销售收入-1月内
DATA out_07 TYPE char16 VALUE '0'. "销售收入-1~2月
DATA out_08 TYPE char16 VALUE '0'. "销售收入-2~3月
DATA out_09 TYPE char16 VALUE '0'. "销售收入-3~6月
DATA out_10 TYPE char16 VALUE '0'. "销售收入-超过6个月
DATA out_11 TYPE char16 VALUE '0'. "发出商品金额-期末金额
DATA out_12 TYPE char16 VALUE '0'. "发出商品金额-1月内
DATA out_13 TYPE char16 VALUE '0'. "发出商品金额-1~2月
DATA out_14 TYPE char16 VALUE '0'. "发出商品金额-2~3月
DATA out_15 TYPE char16 VALUE '0'. "发出商品金额-3~6月
DATA out_16 TYPE char16 VALUE '0'. "发出商品金额-超过6个月
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_rbukrs LIKE acdoca-rbukrs MODIF ID m1 OBLIGATORY . "公司代码
PARAMETERS: p_gjahr LIKE acdoca-gjahr MODIF ID m1 OBLIGATORY . "年度
PARAMETERS: p_budat LIKE acdoca-budat MODIF ID m1 OBLIGATORY . "截止日期
SELECTION-SCREEN END OF BLOCK b1.
*&---------------------------------------------------------------------*
*& 包含 ZFIR090_CLASS
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* CLASS cl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_event_receiver DEFINITION.
PUBLIC SECTION.
" 声明单击事件的方法
METHODS handle_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id.
" 声明双击事件方法
METHODS handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column.
" 声明TOOLBAR事件方法
METHODS handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
" 声明USER-COMMAND 事件方法
METHODS handle_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
"修改时触发
METHODS handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
ENDCLASS. "CL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_event_receiver IMPLEMENTATION.
" 单击事件方法的实现
METHOD handle_hotspot_click.
ENDMETHOD. "HANDLE_HOTSPOT_CLICK
" 双击事件方法的实现
METHOD handle_double_click.
ENDMETHOD. "HANDLE_DOUBLE_CLICK
" 实现TOOLBAR事件方法
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
DELETE e_object->mt_toolbar WHERE function = '&PRINT_BACK'.
CLEAR: ls_toolbar.
ls_toolbar-butn_type = 3. " 分隔符
APPEND ls_toolbar TO e_object->mt_toolbar.
* CLEAR: ls_toolbar.
* ls_toolbar-function = 'BT_8'. "功能码
* ls_toolbar-icon = icon_incomplete. " 图标名称
* ls_toolbar-text = '功能按钮1'. " 按钮上显示的文本
* ls_toolbar-quickinfo = '功能按钮'. " 图标的提示信息
* ls_toolbar-butn_type = 0. " 0表示正常按钮
* ls_toolbar-disabled = ''. " X表示灰色,不可用
* APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "HANDLE_TOOLBAR
" 实现USER-COMMAND 事件方法
METHOD handle_command.
DATA : lv_stable TYPE lvc_s_stbl. "刷新稳定性
lv_stable-row = '1'.
lv_stable-col = '1'.
CASE e_ucomm.
WHEN 'BT_8'.
* SORT gt_data[] BY bedat.
* CALL METHOD go_alv_grid->refresh_table_display "内表改变时刷新ALV
* EXPORTING
* is_stable = lv_stable.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "HANDLE_COMMAND
" 实现DATA_CHANGED 事件方法
METHOD handle_data_changed.
ENDMETHOD. "handle_data_changed
ENDCLASS. "cl_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------*
*& 包含 ZFIR090_FOM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form GET_MONTH_LASTDAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM get_month_lastday .
*取上个月最后一天
p_budat = sy-datum(6) && '01'.
p_budat = p_budat - 1 .
*取本月最后一天
* CALL FUNCTION 'BKK_GET_MONTH_LASTDAY'
* EXPORTING
* i_date = sy-datum
* IMPORTING
* e_date = p_budat
* .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SCREEN_SETTING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM screen_setting .
AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
ID 'BUKRS' FIELD p_rbukrs .
IF sy-subrc <> 0.
MESSAGE '您没有工厂:'&& p_rbukrs && ' 的权限!' TYPE 'E' .
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM fom_getdata .
DATA gv_zdn_create_his TYPE zdn_create_his .
DATA gv_zuonr TYPE acdoca-zuonr .
CLEAR gt_data[] .
IF p_rbukrs = '1010' OR p_rbukrs = '2010' OR p_rbukrs = '4010'.
SELECT
acdoca~hsl
acdoca~matnr
acdoca~werks
acdoca~zuonr
acdoca~msl
acdoca~runit
acdoca~zuonr
INTO CORRESPONDING FIELDS OF TABLE gt_data[]
FROM acdoca
WHERE acdoca~rbukrs = p_rbukrs
AND acdoca~gjahr = p_gjahr
AND acdoca~budat = p_budat
AND acdoca~rldnr = p_rldnr
AND acdoca~rrcty = p_rrcty
AND acdoca~racct = p_racct
AND acdoca~awtyp = p_awtyp
.
LOOP AT gt_data.
*分配(ACDOCA-ZUONR)的前十位为DN编号,第十一位开始取6为DN项目;
gt_data-zuonr_f = gt_data-zuonr(10) .
gt_data-zuonr_b = gt_data-zuonr+11(6) .
*DN编号是85开头的则对销售数量(ACDOCA-MSL)取负数
IF gt_data-zuonr_f(2) = '58'.
gt_data-msl = gt_data-msl * -1 .
ENDIF.
SELECT SINGLE wadat_ist INTO gt_data-wadat_ist FROM likp
WHERE vbeln = gt_data-zuonr_f .
*根据ZDN_CREATE_HIS-VBELN = DN编号、ZDN_CREATE_HIS-POSNR = DN项目、ZDN_CREATE_HIS-WERKS =工厂; 取销售订单(ZDN_CREATE_HIS-KDAUF)、项目(ZDN_CREATE_HIS-KDPOS),
SELECT SINGLE kdauf kdpos INTO ( gt_data-kdauf ,gt_data-kdpos ) FROM zdn_create_his
WHERE vbeln = gt_data-zuonr_f
AND posnr = gt_data-zuonr_b
AND werks = gt_data-werks
.
*如果不能取到值(指在表中不存在条目或在表中有条目但销售订单为空)则再根据 LIPS-VBELN = DN编号、LIPS-POSNR = DN项目,取销售订单(LIPS-VGBEL)及项目(LIPS-VGPOS);
IF sy-subrc <> 0.
SELECT SINGLE vgbel vgpos INTO ( gt_data-kdauf ,gt_data-kdpos ) FROM lips
WHERE vbeln = gt_data-zuonr_f
AND posnr = gt_data-zuonr_b
.
ENDIF.
SELECT SINGLE
vbak~kunnr
vbap~netpr
vbap~kpein
vbap~umzin
vbap~umziz
INTO CORRESPONDING FIELDS OF gt_data
FROM vbap
INNER JOIN vbak ON vbap~vbeln = vbak~vbeln
WHERE vbap~vbeln = gt_data-kdauf
AND vbap~posnr = gt_data-kdpos
.
*销售收入 = 净价(VBAP-NETPR) 除以 定价单位(VBAP-KPEIN) 乘以 转换因子(VBAP-UMZIN) 除以 转换因子(VBAP-UMZIZ) 乘以 销售数量(ACDOCA-MSL)
IF gt_data-kpein <> 0 AND gt_data-umziz <> 0.
gt_data-netsr = gt_data-netpr / gt_data-kpein * gt_data-umzin / gt_data-umziz * gt_data-msl .
ENDIF.
SELECT SINGLE name1 INTO gt_data-name1 FROM kna1
WHERE kunnr = gt_data-kunnr
AND spras = 1
.
MODIFY gt_data .
CLEAR gt_data .
ENDLOOP.
ELSEIF p_rbukrs = '1000'.
SELECT
acdoca~hsl
acdoca~matnr
acdoca~werks
acdoca~zuonr
acdoca~msl
acdoca~runit
acdoca~zuonr
INTO CORRESPONDING FIELDS OF TABLE gt_data[]
FROM acdoca
WHERE acdoca~rbukrs = p_rbukrs
AND acdoca~gjahr = p_gjahr
AND acdoca~budat = p_budat
AND acdoca~rldnr = p_rldnr
AND acdoca~rrcty = p_rrcty
AND acdoca~racct = p_racct
AND acdoca~awtyp = p_awtyp
.
LOOP AT gt_data.
gt_data-zuonr_f = gt_data-zuonr(10) .
gt_data-zuonr_b = gt_data-zuonr+11(6) .
*DN编号是85开头的则对销售数量(ACDOCA-MSL)取负数
IF gt_data-zuonr_f(2) = '58'.
gt_data-msl = gt_data-msl * -1 .
ENDIF.
SELECT SINGLE wadat_ist INTO gt_data-wadat_ist FROM likp
WHERE vbeln = gt_data-zuonr_f .
*取销售订单、行项目:LIPS-VBELN = DN编号、LIPS-POSNR = DN项目,取销售订单(LIPS-VGBEL)及项目(LIPS-VGPOS);
SELECT SINGLE vgbel vgpos INTO ( gt_data-kdauf ,gt_data-kdpos ) FROM lips
WHERE vbeln = gt_data-zuonr_f
AND posnr = gt_data-zuonr_b
.
SELECT SINGLE
vbak~kunnr
vbap~netpr
vbap~kpein
vbap~umzin
vbap~umziz
INTO CORRESPONDING FIELDS OF gt_data
FROM vbap
INNER JOIN vbak ON vbap~vbeln = vbak~vbeln
WHERE vbap~vbeln = gt_data-kdauf
AND vbap~posnr = gt_data-kdpos
.
*销售收入 等于 净价(VBAP-NETPR) 除以 定价单位(VBAP-KPEIN) 乘以 转换因子(VBAP-UMZIN) 除以 转换因子(VBAP-UMZIZ) 乘以 销售数量(ACDOCA-MSL)
IF gt_data-kpein <> 0 AND gt_data-umziz <> 0.
gt_data-netsr = gt_data-netpr / gt_data-kpein * gt_data-umzin / gt_data-umziz * gt_data-msl .
ENDIF.
SELECT SINGLE name1 INTO gt_data-name1 FROM kna1
WHERE kunnr = gt_data-kunnr
AND spras = 1
.
*取交货工厂的发出商品金额、DN时间:根据ZDN_CREATE_HIS-KDAUF =销售订单(LIPS-VGBEL)、ZDN_CREATE_HIS-KDPOS = 项目(LIPS-VGPOS);取公司代码(ZDN_CREATE_HIS-BUKRS)、交货(ZDN_CREATE_HIS-VBELN)、项 目(ZDN_CREATE_HIS-POSNR),
CLEAR gv_zdn_create_his .
SELECT SINGLE bukrs vbeln posnr INTO CORRESPONDING FIELDS OF gv_zdn_create_his FROM zdn_create_his
WHERE kdauf = gt_data-kdauf
AND kdpos = gt_data-kdpos
.
*如果取不到交货、项目的值,则发出商品金额用原来的ACDOCA-HSL、DN时间用原来的LIKP-WADAT_IST
IF gv_zdn_create_his-vbeln IS NOT INITIAL AND gv_zdn_create_his-posnr IS NOT INITIAL.
CLEAR gv_zuonr .
gv_zuonr = gv_zdn_create_his-vbeln && gv_zdn_create_his-posnr .
SELECT SINGLE
acdoca~hsl
INTO gt_data-hsl
FROM acdoca
WHERE acdoca~rbukrs = p_rbukrs
AND acdoca~gjahr = p_gjahr
AND acdoca~budat = p_budat
AND acdoca~rldnr = p_rldnr
AND acdoca~rrcty = p_rrcty
AND acdoca~racct = p_racct
AND acdoca~awtyp = p_awtyp
AND acdoca~zuonr = gv_zuonr
.
*根据交货(ZDN_CREATE_HIS-VBELN)取表LIKP的DN时间(LIKP-WADAT_IST)。
SELECT SINGLE wadat_ist INTO gt_data-wadat_ist FROM likp
WHERE vbeln = gv_zdn_create_his-vbeln .
ENDIF.
MODIFY gt_data .
CLEAR gt_data .
ENDLOOP.
ELSE."???
ENDIF.
SELECT SINGLE butxt waers INTO (out_01 ,out_04) FROM t001 WHERE bukrs = p_rbukrs AND spras = 1 .
out_02 = p_budat+(4) && '年' && p_budat+4(2) && '月' && p_budat+6(2) && '日'.
*账龄数据:屏幕截止日期 减去 DN时间,将0-30天内的各DN编号汇总销售收入、发出商品金额赋值给对应的1月内;31-60天赋值给1~2月、61-90天赋值给2~3月、91-180天赋值给3~6月、大于等于181天赋值给超过6个月。
LOOP AT gt_data .
IF p_budat - gt_data-wadat_ist <= 30.
out_06 = out_06 + gt_data-netsr .
out_12 = out_12 + gt_data-hsl .
ELSEIF p_budat - gt_data-wadat_ist <= 60.
out_07 = out_07 + gt_data-netsr .
out_13 = out_13 + gt_data-hsl .
ELSEIF p_budat - gt_data-wadat_ist <= 90.
out_08 = out_08 + gt_data-netsr .
out_14 = out_14 + gt_data-hsl .
ELSEIF p_budat - gt_data-wadat_ist <= 180.
out_09 = out_09 + gt_data-netsr .
out_15 = out_15 + gt_data-hsl .
ELSE.
out_10 = out_10 + gt_data-netsr .
out_16 = out_16 + gt_data-hsl .
ENDIF.
out_05 = out_05 + gt_data-netsr .
out_11 = out_11 + gt_data-hsl .
CLEAR gt_data .
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_INIT_0101
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM form_init_0101 .
DATA l_fcat_cache TYPE lvc_t_fcat.
DATA wa_layout_cache TYPE lvc_s_layo.
DATA wa_field TYPE lvc_s_fcat.
DATA lo_event TYPE REF TO cl_event_receiver.
CREATE OBJECT lo_container
EXPORTING
container_name = 'CONT01'.
CREATE OBJECT go_alv_grid
EXPORTING
i_parent = lo_container.
DEFINE fill_field.
wa_field-fieldname = &1.
wa_field-coltext = &2.
IF wa_field-fieldname = 'MSL'
OR wa_field-fieldname = 'NETSR'
OR wa_field-fieldname = 'HSL'.
wa_field-do_sum = 'X'.
ENDIF.
APPEND wa_field TO l_fcat_cache .
CLEAR wa_field.
END-OF-DEFINITION.
fill_field :
'KUNNR' '客户',
'NAME1' '客户名称',
'MATNR' '物料编码',
* 'ZUONR' 'DN编号&项目',
'ZUONR_F' 'DN编号',
'ZUONR_B' 'DN项目',
'WADAT_IST' 'DN时间',
'MSL' '销售数量',
* 'WERKS' '工厂',
'RUNIT' '销售单位',
'NETSR' '销售收入',
'HSL' '发出商品金额',
'KDAUF' '销售订单',
'KDPOS' '销售订单项目',
'NETPR' '净价',
'KPEIN' '定价单位',
'UMZIN' '定价单位',
'KDAUF' '转换因子',
'UMZIZ' '转换因子'.
CREATE OBJECT lo_event.
SET HANDLER lo_event->handle_toolbar FOR go_alv_grid.
SET HANDLER lo_event->handle_command FOR go_alv_grid.
* wa_layout_cache-grid_title = 'OO_TEST'."标题栏文本
wa_layout_cache-sel_mode = 'D'. "选择方式
wa_layout_cache-cwidth_opt = 'X'. "优化列宽
CALL METHOD go_alv_grid->set_table_for_first_display
EXPORTING
is_layout = wa_layout_cache
CHANGING
it_fieldcatalog = l_fcat_cache
it_outtab = gt_data[].
ENDFORM.
*&---------------------------------------------------------------------*
*& 包含 ZFIR090_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'PF_0100'.
SET TITLEBAR 'TITLE_0100'.
CHECK controls_created IS INITIAL.
CALL METHOD cl_gui_cfw=>flush."触发SAP GUI更新界面
PERFORM form_init_0101. "实例化ALV_GRID
controls_created = selected.
ENDMODULE.
*&---------------------------------------------------------------------*
*& 包含 ZFIR090_PAI
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module CANCEL INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE cancel INPUT.
LEAVE PROGRAM .
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
ok_save = sy-ucomm .
CLEAR sy-ucomm .
CLEAR ok_code .
CASE ok_save.
WHEN 'BACK' .
LEAVE TO SCREEN 0 .
WHEN OTHERS .
ENDCASE .
ENDMODULE.
INITIALIZATION .
PERFORM get_month_lastday.
AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN.
PERFORM screen_setting.
START-OF-SELECTION.
PERFORM fom_getdata .
CALL SCREEN 100.