给生产部门做的作业任务看板是用TABLE CONTROL来实现的。但是这个TC有局限性,不能改变背景颜色,这也是生产部门多次要求的,根据不同的日期,数量等把任务显示为不同的颜色。经过测试ALV可以完成这样的功能,如果把工具条给加上,则功能远远强过TC。代码如下:
REPORT ztest_nyj2.
TABLES:zpp_die_use.
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
DATA wa_spfli TYPE TABLE OF spfli .
DATA:gt_itab1 LIKE zpp_die_use OCCURS 0 WITH HEADER LINE.
DATA:BEGIN OF gt_itab OCCURS 0 .
INCLUDE STRUCTURE zpp_die_use.
DATA:line_color(4) TYPE c. "颜色处理
DATA:END OF gt_itab.
* ALVDATA 是屏幕100中定义控制控件的名称
DATA: wa_container TYPE scrfname VALUE 'ALVDATA',
alv_grid TYPE REF TO cl_gui_alv_grid,
wa_custom_container TYPE REF TO cl_gui_custom_container.
DATA: lt_fcat TYPE lvc_t_fcat,
ls_layo TYPE lvc_s_layo,
ls_vari TYPE disvariant.
START-OF-SELECTION.
CALL SCREEN 9000.
*----------------------------------------------------------------------*
* MODULE status_9000 OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'FOR9000'.
IF wa_custom_container IS INITIAL.
CREATE OBJECT wa_custom_container
EXPORTING
container_name = wa_container.
CREATE OBJECT alv_grid
EXPORTING
i_parent = wa_custom_container.
ENDIF.
PERFORM d0100_set_grid_fcat CHANGING lt_fcat.
ls_vari-report = sy-repid.
ls_layo-zebra = 'X'."设定斑马线
ls_layo-no_toolbar = 'X'."设定隐藏工具条
ls_layo-cwidth_opt = 'X'."设定自动调整行的宽度
ls_layo-info_fname = 'LINE_COLOR'."设定行的颜色字段
CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
is_variant = ls_vari
i_save = 'A'"显示是否带有格式保存,上面已经设置了不显示工具条,这里设部设定都没有用了
is_layout = ls_layo
CHANGING
it_outtab = gt_itab[]"数据表
it_fieldcatalog = lt_fcat."显示的字段
CALL METHOD alv_grid->raise_event
* EXPORTING
* i_trace_item = 'EVENT: USER_COMMAND'
* ir_variant = m_cl_variant
* it_data = mt_data
* it_info = mt_info.
.
CALL METHOD alv_grid->set_user_command
EXPORTING
* i_trace_item = 'USER_COMMAND'
* ir_variant = 'USER_COMMAND'
* it_data = mt_data
* it_info = 'USER_COMMAND'
i_ucomm = '&IC1'.
ENDMODULE. " STATUS_9000 OUTPUT
*----------------------------------------------------------------------*
* MODULE user_command_9000 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'DIS'.
REFRESH gt_itab.
CLEAR lt_fcat.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_itab FROM zpp_die_use
WHERE usenub > gt_itab-usenub.
LOOP AT gt_itab.
IF gt_itab-usenub > '10000010' AND gt_itab-usenub < '10000100'.
gt_itab-line_color = 'C100'.
ENDIF.
IF gt_itab-usenub > '10000300' AND gt_itab-usenub < '10000400'.
gt_itab-line_color = 'C610'.
ENDIF.
IF gt_itab-usenub > '10000400' AND gt_itab-usenub < '10000600'.
gt_itab-line_color = 'C300'.
ENDIF.
MODIFY gt_itab.
ENDLOOP.
ENDCASE.
ENDMODULE. " USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
*& Form d0100_set_grid_fcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->CT_FCAT text
*----------------------------------------------------------------------*
FORM d0100_set_grid_fcat CHANGING ct_fcat TYPE lvc_t_fcat.
DATA: ls_fcat TYPE lvc_s_fcat,
l_lin TYPE i.
DESCRIBE TABLE ct_fcat LINES l_lin.
ADD 1 TO l_lin.
CLEAR ls_fcat.
ls_fcat-tabname = '1'.
ls_fcat-fieldname = 'USENUB'.
.
ls_fcat-datatype = 'NUMC'.
ls_fcat-intlen = 1.
ls_fcat-col_pos = l_lin.
ls_fcat-scrtext_s = '流水号'."ls_fcat-fieldname.
ls_fcat-scrtext_m = '流水号'."ls_fcat-fieldname.
ls_fcat-scrtext_l = '流水号'."ls_fcat-fieldname.
APPEND ls_fcat TO ct_fcat.
ADD 1 TO l_lin.
CLEAR ls_fcat.
ls_fcat-tabname = '1'.
ls_fcat-fieldname = 'ALUM'.
ls_fcat-inttype = 'CHAR'.
ls_fcat-intlen = 10.
ls_fcat-col_pos = l_lin.
ls_fcat-scrtext_s = '物料号'."ls_fcat-fieldname.
ls_fcat-scrtext_m = '物料号'."lls_fcat-fieldname.
ls_fcat-scrtext_l = '物料号'."lls_fcat-fieldname.
ls_fcat-hotspot = 'X'.
APPEND ls_fcat TO ct_fcat.
ADD 1 TO l_lin.
CLEAR ls_fcat.
ls_fcat-tabname = '1'.
ls_fcat-fieldname = 'RECDATE'.
ls_fcat-inttype = 'DATS'.
ls_fcat-intlen = 10.
ls_fcat-col_pos = l_lin.
ls_fcat-scrtext_s = '记录日期'."ls_fcat-fieldname.
ls_fcat-scrtext_m = '记录日期'."lls_fcat-fieldname.
ls_fcat-scrtext_l = '记录日期'."lls_fcat-fieldname.
APPEND ls_fcat TO ct_fcat.
ADD 1 TO l_lin.
CLEAR ls_fcat.
MODIFY ct_fcat FROM ls_fcat TRANSPORTING no_init_ch
WHERE no_init_ch EQ space.
ENDFORM. " d0100_set_grid_fcatRECDATE
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->UCOM text
* -->SELFD text
*----------------------------------------------------------------------*
FORM user_command USING ucom LIKE sy-ucomm
selfd TYPE slis_selfield.
DATA: fname LIKE rlgrap-filename.
DATA: data_type(4).
CASE ucom.
WHEN '&IC1'.
IF selfd-fieldname = 'ALUM'.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDFORM. "USER_COMMAND
阅读(1229) | 评论(0) | 转发(0) |