ALV自动刷新,字段搜索帮助
2016-04-28 本文已影响276人
SmalltalkVoice
*&---------------------------------------------------------------------*
*& Report ZMM006
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zmm213.
TYPE-POOLS: slis.
TABLES:resb,rkpf,makt,t001l,cskt,mara.
*一、数据声明
DATA: BEGIN OF item OCCURS 0,
mark(1), "选择记录
ztt(10),
zt(2),
rsnum LIKE rkpf-rsnum, "预留单号
lgort LIKE resb-lgort, "发料仓库
lgobe LIKE t001l-lgobe, "发料仓库描述
lgpbe LIKE mard-lgpbe, "仓管员
kostl LIKE rkpf-kostl, "成本中心
ktext LIKE cskt-ktext,
matnr LIKE resb-matnr, "物料编码
maktx LIKE makt-maktx, "物料描述
meins LIKE resb-meins, "单位
bdmng LIKE resb-bdmng, "需求数量
bdter LIKE resb-bdter, "需求日期
bwart LIKE rkpf-bwart, "移动类型
werks LIKE resb-werks, "工厂
rspos LIKE resb-rspos, "行项目
ebelx(3), "序号
enmng LIKE resb-enmng, "提货数量
zbdmng LIKE resb-enmng, "实际需求数量
zdbls LIKE zsjlst-zdbls, "流水号
usnam LIKE rkpf-usnam,
sjdlb(12),
name LIKE usrefus-useralias,
name1 LIKE usrefus-useralias,
ztbdmng LIKE resb-bdmng,
lifnr LIKE mkol-lifnr,
name2 LIKE lfa1-name1,
lgfsb LIKE marc-lgfsb, "接收仓库
slabs LIKE mkol-slabs,
END OF item.
DATA: gd_repid LIKE sy-repid.
DATA: i_grid_settings TYPE lvc_s_glay .
DATA: lt_h LIKE TABLE OF item WITH HEADER LINE.
DATA: wa_lt LIKE TABLE OF item WITH HEADER LINE.
DATA: wb_lt LIKE TABLE OF item WITH HEADER LINE.
DATA: wa_item LIKE item.
DATA: lft_h LIKE TABLE OF item WITH HEADER LINE. "输出到sf 的抬头数据
DATA: lft_i LIKE TABLE OF item WITH HEADER LINE. "输出到sf 的项目数据
DATA: is_i LIKE TABLE OF item WITH HEADER LINE.
DATA: l_zdbls LIKE zjlst-zdbls,l_con(30),l_num TYPE numc4.
DATA: p_zjlst LIKE TABLE OF zjlst WITH HEADER LINE.
DATA: p_ztlsdh LIKE TABLE OF ztlsdh WITH HEADER LINE.
DATA: s_zzscdj LIKE TABLE OF zzscdj WITH HEADER LINE.
DATA: lt_mkol LIKE TABLE OF mkol WITH HEADER LINE.
DATA: afield TYPE slis_fieldcat_alv.
DATA: fieldcat TYPE TABLE OF slis_fieldcat_alv WITH HEADER LINE.
DATA: layout TYPE slis_layout_alv.
DATA: gt_events TYPE slis_t_event.
DATA: l_pos TYPE i VALUE 1.
DATA: s_i TYPE i ,
wl_answer(1) TYPE c.
DATA: BEGIN OF it_save OCCURS 0.
INCLUDE STRUCTURE zrmm204t1.
DATA: color(4) TYPE c,
makts LIKE makt-maktx,
name1 LIKE lfa1-name1,
dispo LIKE zrmm204t2-dispo,
chck.
DATA: END OF it_save.
DATA: BEGIN OF it_header OCCURS 0,
lifnr LIKE it_save-lifnr,
werks LIKE it_save-werks,
umlgo LIKE it_save-umlgo,
lgpbe LIKE it_save-lgpbe,
END OF it_header.
DATA tem_grid TYPE REF TO cl_gui_alv_grid.
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
update_delta_tables
FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified et_good_cells.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD update_delta_tables.
LOOP AT item INTO wa_item." WHERE lifnr IS NOT INITIAL.
CLEAR:wa_item-name2,wa_item-slabs.
SELECT SINGLE name1 INTO wa_item-name2
FROM lfa1 WHERE lifnr = wa_item-lifnr.
SELECT SINGLE slabs INTO wa_item-slabs
FROM mkol WHERE matnr = wa_item-matnr AND werks = wa_item-werks
AND lgort = wa_item-lgort
AND sobkz = 'K'
AND lifnr = wa_item-lifnr.
MODIFY item FROM wa_item TRANSPORTING name2 slabs.
ENDLOOP.
DATA stbl TYPE lvc_s_stbl.
* 稳定刷新
stbl-row = 'X'." 基于行的稳定刷新
stbl-col = 'X'." 基于列稳定刷新
CALL METHOD tem_grid->refresh_table_display
EXPORTING
is_stable = stbl.
ENDMETHOD. "update_delta_tables
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
DATA gt_event_receiver TYPE REF TO lcl_event_receiver .
*宏的定义
DEFINE fill.
afield-col_pos = l_pos.
afield-fieldname = &1.
afield-seltext_l = &2.
afield-no_zero = &3.
afield-key = &4.
afield-edit = &5.
append afield to fieldcat.
clear afield.
l_pos = l_pos + 1.
END-OF-DEFINITION.
*二、声明查询屏幕
SELECTION-SCREEN BEGIN OF BLOCK blc WITH FRAME TITLE text-001.
PARAMETERS: p_werks LIKE resb-werks OBLIGATORY DEFAULT '6000'.
SELECT-OPTIONS : p_lgort FOR resb-lgort .
SELECT-OPTIONS : p_rsnum FOR rkpf-rsnum.
SELECT-OPTIONS : p_kostl FOR rkpf-kostl.
SELECT-OPTIONS : p_bdter FOR resb-bdter.
SELECTION-SCREEN END OF BLOCK blc.
*五、取数
START-OF-SELECTION.
PERFORM frm_get_event.
PERFORM frm_get_data. "获取数据
IF item[] IS NOT INITIAL.
PERFORM frm_show_data.
ELSE.
MESSAGE s001(00) WITH '没有查询到数据'.
ENDIF.
FORM frm_get_data .
*SQL取数
SELECT rkpf~rsnum resb~lgort rkpf~kostl resb~matnr
resb~meins resb~bdmng resb~bdter resb~werks rkpf~bwart
resb~enmng resb~rspos rkpf~usnam
INTO CORRESPONDING FIELDS OF TABLE item
FROM rkpf
INNER JOIN resb ON ( rkpf~rsnum = resb~rsnum AND resb~xloek = '' AND resb~kzear = '' )
WHERE rkpf~bwart IN ('201','Z35') AND rkpf~rsnum IN p_rsnum
AND rkpf~kostl IN p_kostl AND resb~bdter IN p_bdter AND resb~lgort IN p_lgort AND resb~werks = p_werks.
SORT item BY rsnum lgort kostl rspos matnr DESCENDING.
*获取其他字段
LOOP AT item.
item-lgfsb = item-lgort. "接收库存地
CASE item-lgort.
WHEN '4002'.
item-lgort = '4020'. "发出库存地
WHEN '4015'.
item-lgort = '4019'. "发出库存地
ENDCASE.
*获取仓库描述
* SELECT SINGLE lgobe INTO item-lgobe FROM t001l WHERE lgort = item-lgort AND werks = p_werks.
"获取仓管员
SELECT SINGLE lgpbe INTO item-lgpbe FROM mard WHERE lgort = item-lgort AND werks = p_werks AND matnr = item-matnr.
*物料描述
SELECT SINGLE maktx INTO item-maktx
FROM makt WHERE matnr = item-matnr.
*实际需求数量
item-zbdmng = item-bdmng - item-enmng.
*领用部门 KTEXT
SELECT SINGLE ktext INTO item-ktext FROM cskt WHERE kostl = item-kostl AND spras = '1' AND kokrs = 'BVAC'.
SELECT SINGLE useralias INTO item-name FROM usrefus WHERE bname = sy-uname.
SELECT SINGLE useralias INTO item-name1 FROM usrefus WHERE bname = item-usnam.
**更新内表!
**供应商库存
CLEAR lt_mkol[].
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_mkol
FROM mkol WHERE matnr = item-matnr AND werks = p_werks
AND lgort = item-lgort
AND sobkz = 'K'.
SORT lt_mkol BY slabs DESCENDING.
READ TABLE lt_mkol INDEX 1.
IF sy-subrc = 0.
item-lifnr = lt_mkol-lifnr.
SELECT SINGLE name1 INTO item-name2
FROM lfa1 WHERE lifnr = item-lifnr.
item-slabs = lt_mkol-slabs.
ENDIF.
MODIFY item .
ENDLOOP.
SORT item BY rsnum lgort lgpbe kostl rspos matnr DESCENDING.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SHOW_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_show_data .
i_grid_settings-edt_cll_cb = 'X' . "显示界面可编辑字段上修改了数据,回车后就会立即将内表的数据也修改
layout-colwidth_optimize = 'X'. "设置字段列宽自适应
layout-zebra = 'X'.
CLEAR afield.
REFRESH fieldcat.
fill 'MARK' '选择' '' 'X' 'X'.
fieldcat-checkbox = 'X'.
fieldcat-hotspot = ''.
MODIFY fieldcat INDEX 1 TRANSPORTING checkbox hotspot.
fill 'RSNUM' '预留单号' '' '' ''.
fill 'NAME1' '预留创建人' '' '' ''.
fill 'RSPOS' '行项目' '' '' ''.
fill 'BWART' '移动类型' '' '' ''.
fill 'KOSTL' '成本中心' '' '' ''.
fill 'KTEXT ' '部门' '' '' ''.
fill 'BDTER' '需求日期' '' '' ''.
fill 'MATNR' '物料编码' '' '' ''.
fill 'MAKTX' '物料描述' '' '' ''.
fill 'MEINS' '单位' '' '' ''.
fill 'LGORT' '发出仓库' '' '' 'X'.
fill 'LGFSB' '接收仓库' '' '' 'X'.
fill 'ZBDMNG' '数量' '' '' ''.
fill 'ZTBDMNG' '实发数量' 'X' '' 'X'.
fill 'LGPBE' '仓管员' '' '' ''.
fill 'LIFNR' '供应商' '' '' 'X'.
fill 'NAME2' '供应商名称' '' '' ''.
fill 'SLABS' '寄售库存' '' '' ''.
fieldcat-inttype = 'C'.
fieldcat-datatype = 'QUAN'.
MODIFY fieldcat INDEX 15 TRANSPORTING inttype datatype.
fieldcat-ref_tabname = 'LFA1'.
fieldcat-ref_fieldname = 'LIFNR'.
MODIFY fieldcat INDEX 17 TRANSPORTING ref_tabname ref_fieldname.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_grid_settings = i_grid_settings "显示界面可编辑字段上修改了数据,回车后就会立即将内表的数据也修改
i_callback_program = sy-cprog "sy-repid "标记当前程序
it_fieldcat = fieldcat[]
is_layout = layout
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_STATUS'
it_events = gt_events
TABLES
t_outtab = item.
ENDFORM. " FRM_SHOW_DATA
*
FORM set_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZMMZT'.
ENDFORM.
FORM user_command USING rf_ucomm LIKE sy-ucomm
rs TYPE slis_selfield .
rs-refresh = 'X'.
CASE rf_ucomm.
WHEN '&IC1'.
READ TABLE item INDEX rs-tabindex.
* IF rs-fieldname = 'ZDYCS'.
* PERFORM frm_show_dymx. "显示打印明细
** SET PARAMETER ID 'BES' FIELD lt_h-ebeln .
** CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
* ENDIF.
WHEN '&ZZPT'.
READ TABLE item WITH KEY mark = 'X'.
IF sy-subrc <> 0.
MESSAGE s001(00) WITH '请选择记录' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
LOOP AT item WHERE mark IS NOT INITIAL.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = item-matnr
IMPORTING
output = item-matnr.
IF item-ztbdmng = 0 OR item-ztbdmng = ''.
MESSAGE s001(00) WITH '行' sy-tabix '未输入数据,不能打印!' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
IF item-ztbdmng > item-zbdmng .
MESSAGE s001(00) WITH '行' sy-tabix '数据小于可领料数量' DISPLAY LIKE 'E'.
item-ztbdmng = ''.
MODIFY item.
RETURN.
ENDIF.
IF item-lifnr IS INITIAL.
MESSAGE s001(00) WITH '行' sy-tabix '供应商为空,不能打印!' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
IF item-slabs = 0.
MESSAGE s001(00) WITH '行' sy-tabix '供应商寄售库存为0,不能打印!' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
IF item-lgort IS INITIAL OR item-lgfsb IS INITIAL.
MESSAGE s001(00) WITH '行' sy-tabix '仓库为空,不能打印!' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
CLEAR:mara.
SELECT SINGLE * FROM mara WHERE matnr = item-matnr.
IF mara-mtart = 'ZR02' OR mara-mtart = 'ZR03' OR mara-mtart = 'ZR05'.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = '将打印数据中存在标准件或辅料,是否打印?'
text_button_1 = '确定'
text_button_2 = '退出'
default_button = '2'
display_cancel_button = 'X'
start_column = 25
start_row = 6
IMPORTING
answer = wl_answer
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
EXIT.
ENDIF.
ENDLOOP.
IF wl_answer = '1' OR wl_answer IS INITIAL.
PERFORM savedata.
PERFORM printdata.
LEAVE PROGRAM.
ENDIF.
WHEN '&ZALL'.
LOOP AT item WHERE mark IS INITIAL .
item-mark = 'X'.
MODIFY item TRANSPORTING mark.
ENDLOOP.
WHEN '&ZSAL'.
LOOP AT item WHERE mark IS NOT INITIAL .
item-mark = ''.
MODIFY item TRANSPORTING mark.
ENDLOOP.
ENDCASE.
ENDFORM. "user_command
*&---------------------------------------------------------------------*
*& Form FRM_GET_EVENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_get_event .
DATA l_events TYPE LINE OF slis_t_event.
CLEAR l_events.
l_events-name = 'CALLER_EXIT'.
l_events-form = 'FM_BUTTON'.
APPEND l_events TO gt_events.
ENDFORM. " FRM_GET_EVENT
*&---------------------------------------------------------------------*
*& 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'
IMPORTING
e_grid = tem_grid.
* 设置enter事件
CALL METHOD tem_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
DATA: gt_event_receiver TYPE REF TO lcl_event_receiver .
CREATE OBJECT gt_event_receiver.
SET HANDLER gt_event_receiver->update_delta_tables FOR tem_grid. "更新内表itab
ENDFORM. "FM_BUTTON
*&---------------------------------------------------------------------*
*& Form SAVEDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM savedata .
DATA: numc(4) TYPE n.
*将item数据对应到it_save
CLEAR:it_save,it_save[].
LOOP AT item WHERE mark IS NOT INITIAL.
it_save-lifnr = item-lifnr.
it_save-werks = item-werks.
it_save-umlgo = item-lgfsb.
it_save-lgpbe = item-lgpbe.
it_save-matnr = item-matnr.
it_save-bdmng = item-ztbdmng.
it_save-meins = item-meins.
it_save-lgort = item-lgort.
it_save-makts = item-maktx.
it_save-name1 = item-name2.
APPEND it_save.
ENDLOOP.
SORT it_save .
LOOP AT it_save WHERE lifnr <> ''.
AT NEW lgpbe.
CALL FUNCTION 'ZNUMC4_GET_NEXT'
EXPORTING
subobject = '02'
IMPORTING
number = numc
EXCEPTIONS
OTHERS = 9.
it_save-zdydh = 'ZC' && sy-datum+2(6) && numc.
MODIFY it_save TRANSPORTING zdydh
WHERE lifnr = it_save-lifnr AND
werks = it_save-werks AND
umlgo = it_save-umlgo AND
lgpbe = it_save-lgpbe.
ENDAT.
MOVE-CORRESPONDING it_save TO it_header.
COLLECT it_header.
ENDLOOP.
CALL FUNCTION 'ZNUMC4_GET_NEXT'
EXPORTING
subobject = '02'
IMPORTING
number = numc
EXCEPTIONS
OTHERS = 9.
it_save-zjsdh = sy-datum && numc.
MODIFY it_save TRANSPORTING zjsdh WHERE zjsdh = ''.
LOOP AT it_save.
it_save-zjsdi = sy-tabix.
it_save-erdat = sy-datum.
it_save-erzet = sy-uzeit.
it_save-ernam = sy-uname.
it_save-wllyc = '05'.
MODIFY it_save.
ENDLOOP.
INSERT zrmm204t1 FROM TABLE it_save.
COMMIT WORK.
ENDFORM. " SAVEDATA
*&---------------------------------------------------------------------*
*& Form PRINTDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM printdata .
DATA: fmname TYPE rs38l_fnam.
DATA: ctlpara TYPE ssfctrlop.
DATA: outopt TYPE ssfcresop.
DATA: jobinfo TYPE ssfcrescl.
DATA: itab LIKE it_save[] WITH HEADER LINE.
DATA: ls_composer_param TYPE ssfcompop.
ctlpara-langu = '1'.
ctlpara-no_open = 'X'.
ctlpara-no_close = 'X'.
ls_composer_param-tdimmed = 'X'.
ls_composer_param-tddelete = 'X'.
ls_composer_param-tdiexit = 'X'.
CALL FUNCTION 'SSF_OPEN'
EXPORTING
control_parameters = ctlpara
output_options = ls_composer_param
IMPORTING
job_output_options = outopt
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.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZRMM213'
IMPORTING
fm_name = fmname
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE 'Call SSF_FUNCTION_MODULE_NAME Error' TYPE 'E'.
ENDIF.
LOOP AT it_header.
CLEAR itab[].
LOOP AT it_save WHERE lifnr = it_header-lifnr AND
werks = it_header-werks AND
umlgo = it_header-umlgo AND
lgpbe = it_header-lgpbe.
itab = it_save.
APPEND itab.
ENDLOOP.
CALL FUNCTION fmname
EXPORTING
control_parameters = ctlpara
user_settings = ' '
TABLES
intab = itab
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE 'Call SmartForms Error' TYPE 'E'.
ENDIF.
ENDLOOP.
IF sy-subrc <> 0. "单独重新打印某个打印单号
CALL FUNCTION fmname
EXPORTING
control_parameters = ctlpara
user_settings = ' '
TABLES
intab = it_save
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE 'Call SmartForms Error' TYPE 'E'.
ENDIF.
ENDIF.
CALL FUNCTION 'SSF_CLOSE'
IMPORTING
job_output_info = jobinfo
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.
IF jobinfo-outputdone = 'X'. "打印了
LOOP AT it_save.
UPDATE zrmm204t1 SET druck = 'X'
WHERE zdydh = it_save-zdydh.
ENDLOOP.
COMMIT WORK.
ENDIF.
ENDFORM. " PRINTDATA