*&---------------------------------------------------------------------*
*& Report ZSDR010
*&
*&---------------------------------------------------------------------*
*&程序名称:承运路单
*&事物代码:ZSD030
*&导入模板:无
*&作者:
*&时间:2016/3/2
*&更新时间:2016/3/2
*&--------------------------------------------------------------------
REPORT zsdr010.
INCLUDE zsdr010_inc.
TYPE-POOLS: slis.
TABLES:likp, kna1, lips ,vttp ,vttk.
TYPES: BEGIN OF ty_all,
tknum LIKE vttk-tknum, "运单号
tplst LIKE vttk-tplst, "装运点
tdlnr LIKE vttk-tdlnr, "物流公司
erdat LIKE vttk-erdat, "装运日期
route LIKE vttk-route, "路线
distz LIKE vttk-distz, "里程
add01 LIKE vttk-add01, "车主、车号
add02 LIKE vttk-add02, "司机
bfart LIKE vttk-bfart, "车型
ernam LIKE vttk-ernam, "创建者
shtyp LIKE vttk-shtyp, "装运类型
btgew_sum LIKE likp-btgew, "总重量
tpnum LIKE vttp-tpnum, "项目号
vbeln LIKE vttp-vbeln, "交货单号
kunnr LIKE likp-kunnr, "客户代码
name1 LIKE kna1-name1, "客户名称
btgew LIKE likp-btgew, "重量
gewei LIKE likp-gewei, "重量单位
volum LIKE likp-volum, "体积
voleh LIKE likp-voleh, "体积单位
beizhu(20) TYPE c , "备注
END OF ty_all.
TYPES:BEGIN OF ty_header,
tknum LIKE vttk-tknum, "运单号
tplst LIKE vttk-tplst, "装运点
tplst_text LIKE ttdst-bezei,"装运点描述
tdlnr LIKE vttk-tdlnr, "物流公司
tdlnr_text LIKE lfa1-name1, "物流公司描述
erdat LIKE vttk-erdat, "装运日期
route LIKE vttk-route, "路线
route_text LIKE tvrot-bezei,"路线描述
distz LIKE vttk-distz, "里程
add01 LIKE vttk-add01, "车主、车号
add02 LIKE vttk-add02, "司机
bfart LIKE vttk-bfart, "车型
ernam LIKE vttk-ernam, "创建者
shtyp LIKE vttk-shtyp, "装运类型
btgew_sum LIKE likp-btgew, "总重量
beizhu(20) TYPE c , "备注
END OF ty_header.
TYPES:BEGIN OF ty_items,
tknum LIKE vttk-tknum, "运单号
tpnum LIKE vttp-tpnum, "项目号
vbeln LIKE vttp-vbeln, "交货单号
kunnr LIKE likp-kunnr, "客户代码
name1 LIKE kna1-name1, "客户名称
btgew LIKE likp-btgew, "重量
gewei LIKE likp-gewei, "重量单位
volum LIKE likp-volum, "体积
voleh LIKE likp-voleh, "体积单位
beizhu(20) TYPE c , "备注
END OF ty_items.
DATA:wa_all TYPE ty_all,
gt_all TYPE ty_all OCCURS 0.
DATA:wa_header TYPE ty_header,
gt_header TYPE ty_header OCCURS 0.
DATA:wa_items TYPE ty_items,
gt_items TYPE ty_items OCCURS 0.
*定义传入到smartforms的变量开始
DATA:fm_name TYPE rs38l_fnam.
DATA:itemsname(32) TYPE c.
DATA:headername(32) TYPE c.
*定义传入到smartforms的变量结束
*定义存储ALV向smartforms传入数据的内表开始
DATA:gt_header_temp TYPE ty_header OCCURS 0.
DATA:gt_items_temp TYPE ty_items OCCURS 0.
DATA:gt_all_temp TYPE ty_all OCCURS 0.
*定义存储ALV向smartforms传入数据的内表结束
*ALV显示头数据开始
DATA:gt_header_show TYPE ty_header OCCURS 0.
DATA:gt_items_show TYPE ty_items OCCURS 0.
*ALV显示头数据结束
"控制smartforms参数声明开始
DATA :control_parameters TYPE ssfctrlop.
"控制smartforms参数声明结束
DATA: gs_fcat TYPE lvc_s_fcat,
gt_fcat TYPE lvc_t_fcat,
gs_layo TYPE lvc_s_layo,
gs_grid TYPE lvc_s_glay.
DATA: gt_event TYPE slis_t_event WITH HEADER LINE,
gt_event_exit TYPE slis_t_event_exit WITH HEADER LINE.
DATA: ref_grid TYPE REF TO cl_gui_alv_grid .
START-OF-SELECTION.
SELECT-OPTIONS: p_tknum FOR vttk-tknum , "运单号
p_shtyp FOR vttk-shtyp,"装运类型
p_tdlnr FOR vttk-tdlnr ,"服务代理
p_route FOR vttk-route,"装运线路
p_ernam FOR vttk-ernam,"创建者
p_erdat FOR vttk-erdat . "装运日期
"P_TPLST FOR VTTK-TPLST ,
"P_ERNAM FOR VTTK-ERNAM ,
"P_ROUTE FOR VTTK-ROUTE .
PERFORM frm_get_data.
PERFORM display_data .
END-OF-SELECTION.
"当屏幕失去焦点时,自动刷新声明类开始
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS handle_modify
FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified et_good_cells.
ENDCLASS.
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_modify.
* PERFORM refresh.
DATA stbl TYPE lvc_s_stbl.
stbl-row = 'X'." 基于行的稳定刷新
stbl-col = 'X'." 基于列稳定刷新
CALL METHOD ref_grid->refresh_table_display
EXPORTING
is_stable = stbl.
ENDMETHOD. "HANDLE_MODIFY
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
DATA gt_event_receiver TYPE REF TO lcl_event_receiver .
"当屏幕失去焦点时,自动刷新声明类结束
FORM frm_get_data .
TYPES: BEGIN OF ty_tknum ,"存储动态显示列的内表结构
tknum LIKE vttk-tknum , "运单号
btgew LIKE likp-btgew, "一个运单对应的重量
END OF ty_tknum.
DATA : hs_tknum TYPE HASHED TABLE OF ty_tknum WITH UNIQUE KEY tknum WITH HEADER LINE .
SELECT vk~tknum vk~tplst vk~tdlnr vk~erdat vk~route vk~distz
vk~add01 vk~add02 vk~bfart vk~ernam vk~shtyp
vp~tpnum vp~vbeln lp~kunnr k~name1 lp~btgew lp~gewei
lp~volum lp~voleh
FROM vttk AS vk
INNER JOIN vttp AS vp
ON vk~tknum = vp~tknum
INNER JOIN likp AS lp
ON vp~vbeln = lp~vbeln
INNER
JOIN kna1 AS k
ON k~kunnr = lp~kunnr
INTO CORRESPONDING FIELDS OF TABLE gt_all
WHERE ( vk~tknum IN p_tknum
AND vk~erdat IN p_erdat
AND vk~route IN p_route
AND vk~tdlnr IN p_tdlnr
AND vk~ernam IN p_ernam
AND vk~shtyp IN p_shtyp ).
LOOP AT gt_all INTO wa_all.
IF wa_all-gewei NE 'KG'.
CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
EXPORTING
input = wa_all-btgew
round_sign
= 'X'
unit_in
= 'G'
unit_out
= 'KG'
IMPORTING
output = wa_all-btgew
EXCEPTIONS
conversion_not_found
= 01
division_by_zero
= 02
input_invalid
= 03.
ENDIF.
hs_tknum
-tknum = wa_all-tknum.
hs_tknum
-btgew = wa_all-btgew.
COLLECT hs_tknum.
ENDLOOP.
SORT gt_all ASCENDING BY tknum ."BUDAT_MKPF CPUTM_MKPF.
MOVE-CORRESPONDING gt_all TO gt_header_show.
MOVE-CORRESPONDING gt_all TO gt_items_show.
DELETE ADJACENT DUPLICATES FROM gt_header_show COMPARING tknum.
SORT gt_items_show BY tknum tpnum.
CLEAR wa_header.
LOOP AT gt_header_show INTO wa_header.
READ TABLE hs_tknum WITH KEY tknum = wa_header-tknum.
wa_header
-btgew_sum = hs_tknum-btgew.
SELECT SINGLE bezei FROM ttdst INTO wa_header-tplst_text
WHERE tplst eq wa_header-tplst.
SELECT SINGLE bezei FROM tvrot INTO wa_header-route_text
WHERE route eq wa_header-route.
SELECT SINGLE name1 FROM lfa1 INTO wa_header-tdlnr_text
WHERE lifnr eq wa_header-tdlnr.
MODIFY gt_header_show FROM wa_header.
CLEAR wa_header.
ENDLOOP.
ENDFORM.
FORM display_data .
PERFORM set_fcat.
PERFORM set_layout.
PERFORM show_alv TABLES gt_fcat gt_header_show[]
USING gs_layo.
ENDFORM. " DISPLAY_DATA
*&---------------------------------------------------------------------*
FORM set_fcat .
PERFORM csalv_set_fcat USING:
" 'Field' 'Text' 'Edit' 'Zero' 'Type' 'Qfieldname' 'Key' 'Hostspot' 'Emphasize' 'Checkbox'
'TKNUM' '运单号' '' '' '' '' '' '' '' '' '' '' '' '10',
'TPLST' '装运点' '' '' '' '' '' '' '' '' '' '' '' '5',
'TPLST_TEXT' '装运点名称' '' '' '' '' '' '' '' '' '' '' '' '30',
'TDLNR' '物流公司代码' '' '' '' '' '' '' '' '' '' '' '' '15',
'TDLNR_TEXT' '物流公司' '' '' '' '' '' '' '' '' '' '' '' '30',
'ERDAT' '装运日期' '' '' '' '' '' '' '' '' '' '' '' '10',
'ROUTE' '装运线路' '' '' '' '' '' '' '' '' '' '' '' '10',
'ROUTE_TEXT' '装运线路描述' '' '' '' '' '' '' '' '' '' '' '' '30',
'SHTYP' '装运类型' '' '' '' '' '' '' '' '' '' '' '' '5',
'BTGEW_SUM' '总重量(KG)' '' '' '' '' '' '' '' '' '' '' '' '10',
'DISTZ' '里程' '' '' '' '' '' '' '' '' '' '' '' '10',
'ADD02' '司机' '' '' '' '' '' '' '' '' '' '' '' '10',
'BFART' '车型' '' '' '' '' '' '' '' '' '' '' '' '5',
'ERNAM' '创建者' '' '' '' '' '' '' '' '' '' '' '' '20',
'BEIZHU' '备注' 'X' '' '' '' '' '' '' '' '' '' 'X' ''.
ENDFORM. " SET_FCAT
*&---------------------------------------------------------------------*
FORM set_layout .
gs_layo
-zebra = 'X'.
* gs_layout-stylefname = 'FIELD_STYLE'.
gs_layo
-CWIDTH_OPT = 'X'.
ENDFORM. " SET_LAYOUT
*&---------------------------------------------------------------------*
FORM csalv_set_fcat USING
p_name
p_text
p_edit
p_zero
p_type
p_qfieldname
p_key
p_hotspot
p_emphasize
p_checkbox
p_do_sum
p_decimals_out
p_no_out
p_outputlen
.
gs_fcat
-fieldname = p_name.
* gs_fcat-reptext_l =
* gs_fcat-selddictxt =
gs_fcat
-reptext = p_text.
gs_fcat
-edit = p_edit.
gs_fcat
-no_zero = p_zero.
gs_fcat
-datatype = p_type.
gs_fcat
-qfieldname = p_qfieldname.
gs_fcat
-key = p_key.
gs_fcat
-hotspot = p_hotspot.
gs_fcat
-emphasize = p_emphasize.
gs_fcat
-checkbox = p_checkbox.
gs_fcat
-do_sum = p_do_sum.
gs_fcat
-decimals_o = p_decimals_out.
gs_fcat
-no_out = p_no_out.
gs_fcat
-outputlen = p_outputlen.
APPEND gs_fcat TO gt_fcat.
ENDFORM. "csalv_set_fcat
*&---------------------------------------------------------------------*
FORM show_alv TABLES pt_fcat
pt_tab
USING ps_layout.
gs_grid
-edt_cll_cb = 'X'."当屏幕失去焦点时,自动刷新
gt_event
-name = 'CALLER_EXIT'. "slis_ev_caller_exit_at_start事件
gt_event
-form = 'FM_BUTTON'.
APPEND gt_event .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program
= sy-repid
i_callback_user_command
= 'USER_COMMAND'
i_grid_settings
= gs_grid
i_callback_pf_status_set
= 'SET_PF_STATUS'
is_layout_lvc
= gs_layo
it_fieldcat_lvc
= pt_fcat[]
it_events
= gt_event[]
i_save
= 'X'
* it_event_exit = gt_event_exit[]
TABLES
t_outtab
= pt_tab
EXCEPTIONS
program_error
= 1
OTHERS = 2.
ENDFORM. "csalv_set_fcat
FORM print.
DATA:ptr_count(10) TYPE c.
DATA: lines TYPE i."获取往smartforms传入的要打印的行数目
DATA: insertrows TYPE i."需要再插入多少空行
DATA: rows TYPE i VALUE 22."一页要打印的行数
CLEAR gt_all_temp.
CLEAR gt_header.
CLEAR gt_items.
CLEAR gt_header_temp.
CLEAR gt_items_temp.
DATA count LIKE lips-brgew VALUE 0.
DATA:ls_row TYPE lvc_s_row,
lt_rows
TYPE lvc_t_row.
"CLEAR GT_HEADER.
"CLEAR GT_ITEMS.
CALL METHOD ref_grid->get_selected_rows
IMPORTING
et_index_rows
= lt_rows
* et_row_no =
.
LOOP AT lt_rows INTO ls_row.
READ TABLE gt_header_show INTO wa_header INDEX ls_row-index.
APPEND wa_header TO gt_header.
LOOP AT gt_items_show INTO wa_items.
IF ( wa_header-tknum EQ wa_items-tknum ).
APPEND wa_items TO gt_items.
ENDIF.
ENDLOOP.
ENDLOOP.
CLEAR: control_parameters.
control_parameters
-preview = 'X'.
control_parameters
-no_open = 'X'.
control_parameters
-no_close = 'X'.
CALL FUNCTION 'SSF_OPEN'
EXPORTING
control_parameters
= control_parameters
EXCEPTIONS
formatting_error
= 1
internal_error
= 2
send_error
= 3
user_canceled
= 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
LOOP AT gt_header INTO wa_header.
APPEND wa_header TO gt_header_temp.
LOOP AT gt_items INTO wa_items.
IF ( wa_header-tknum EQ wa_items-tknum ) .
APPEND wa_items TO gt_items_temp.
ENDIF.
ENDLOOP.
"WA_HEADER-TOTAL_BRGEW = COUNT.
"MODIFY TABLE gt_header_temp FROM wa_header.
CLEAR wa_items.
CLEAR wa_header.
CLEAR count.
IF gt_items_temp IS INITIAL.
MESSAGE i000(0k) WITH '请选中要打印的内容!'.
EXIT .
ENDIF.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname
= 'ZSDSF003'
IMPORTING
fm_name
= fm_name
EXCEPTIONS
no_form
= 1
no_function_module
= 2
OTHERS = 3.
"SET HANDLER gt_event_receiver->handle_modify FOR ref_grid.
DESCRIBE TABLE gt_items_temp LINES lines.
insertrows
= lines MOD rows .
insertrows
= rows - insertrows.
DO insertrows TIMES.
APPEND wa_items TO gt_items_temp.
ENDDO.
PERFORM frm_print_data."每一个表头数据向smartforms传入数据
ENDLOOP.
CALL FUNCTION 'SSF_CLOSE'
EXCEPTIONS
formatting_error
= 1
internal_error
= 2
send_error
= 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.
FORM frm_print_data.
CONCATENATE 'ZDDITEMMM' sy-uzeit INTO itemsname.
CONCATENATE 'ZDDHEADER' sy-uzeit INTO headername.
savebuffer gt_items_temp itemsname
.
savebuffer gt_header_temp headername
.
* PTR_COUNT = GV_COUNT .
*调用 smartForms
CALL FUNCTION fm_name
EXPORTING
control_parameters
= control_parameters
ptr_items
= itemsname
ptr_header
= headername
* PTR_TOTAL = GV_COUNT
EXCEPTIONS
formatting_error
= 1
internal_error
= 2
send_error
= 3
user_canceled
= 4.
clearbuffer itemsname
.
clearbuffer headername
.
CLEAR gt_header_temp.
CLEAR gt_items_temp.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_UCOMM text
* -->PS_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield
TYPE slis_selfield.
CASE r_ucomm.
WHEN '&DATA_SAVE'.
WHEN '&PRINT' OR '&PRT'.
PERFORM print.
WHEN OTHERS.
LEAVE PROGRAM.
ENDCASE.
ENDFORM. "user_command
*&---------------------------------------------------------------------*
*& Form SET_PF_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM set_pf_status USING rt_extab TYPE slis_t_extab..
SET PF-STATUS 'STANDARD'.
ENDFORM. "SET_PF_STATUS
*&---------------------------------------------------------------------*
*& Form fm_button
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->E_GRID text
*----------------------------------------------------------------------*
FORM fm_button USING e_grid TYPE slis_data_caller_exit.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
* EXPORTING
* IR_SALV_FULLSCREEN_ADAPTER =
IMPORTING
* ET_EXCLUDING =
* E_REPID =
* E_CALLBACK_PROGRAM =
* E_CALLBACK_ROUTINE =
e_grid
= ref_grid
* ET_FIELDCAT_LVC =
* ER_TRACE =
* E_FLG_NO_HTML =
* ES_LAYOUT_KKBLO =
* ES_SEL_HIDE =
* ET_EVENT_EXIT =
* ER_FORM_TOL =
* ER_FORM_EOL =
.
* CALL METHOD ref_grid->check_changed_data.
* 设置enter事件
CALL METHOD ref_grid->register_edit_event
EXPORTING
i_event_id
= cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error
= 1
OTHERS = 2.
CREATE OBJECT gt_event_receiver.
SET HANDLER gt_event_receiver->handle_modify FOR ref_grid.
ENDFORM. "FM_BUTTON