全部博文(38)
分类: 信息化
2015-04-27 09:55:18
ALV CHECKBOX 变灰显示总结
——Thomas 梁建岗 2015-04-03
1. function alv reuse_alv_grid_display_lvc 函数实现效果
本例是将seatsmax的数量大于300的记录checkbox变灰不可编辑
REPORT ZTHOMAS_ALV_CHECKBOX_DISABLED.
"types declaration
TABLES sflight.
TYPES:BEGIN OF gs_sflight.
INCLUDE STRUCTURE sflight.
TYPES: checkbox TYPE c.
TYPES: style TYPE lvc_t_styl.
TYPES:END OF gs_sflight.
"internal table and work area declaraton
DATA:gt_sflight TYPE STANDARD TABLE OF gs_sflight,
gw_sflight TYPE gs_sflight.
"selection screen declaration
SELECT-OPTIONS:s_carr FOR sflight-carrid,
s_conn FOR sflight-connid.
"get data from sflight
SELECT * FROM sflight
INTO CORRESPONDING FIELDS OF TABLE gt_sflight
WHERE carrid IN s_carr
AND connid IN s_conn.
CHECK gt_sflight IS NOT INITIAL.
DATA: GT_FIELDCAT TYPE LVC_T_FCAT,
GS_LAYOUT TYPE LVC_S_LAYO.
DATA: LS_CELLTAB TYPE LVC_S_STYL.
PERFORM BUILD_layout CHANGING gs_layout.
PERFORM BUILD_FIELDCAT CHANGING GT_FIELDCAT.
LOOP AT gt_sflight INTO gw_sflight.
IF gw_sflight-seatsmax > 300.
* §B4.Switch the style to dis- or enable a cell for input
LS_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
APPEND LS_CELLTAB to gw_sflight-style.
ENDIF.
MODIFY gt_sflight FROM gw_sflight.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_USER_COMMAND = 'CALLBACK_UCOMM'
I_SAVE = '' "
IS_LAYOUT_LVC = gs_LAYOUT "
IT_FIELDCAT_LVC = GT_FIELDCAT
TABLES
T_OUTTAB = gt_sflight.
FORM BUILD_FIELDCAT CHANGING PT_FIELDCAT TYPE LVC_T_FCAT.
DATA LS_FCAT TYPE LVC_S_FCAT.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING
CT_FIELDCAT = PT_FIELDCAT.
*§A2.Add an entry for the checkbox in the fieldcatalog
CLEAR LS_FCAT.
LS_FCAT-FIELDNAME = 'CHECKBOX'.
* Essential: declare field as checkbox and
* mark it as editable field:
LS_FCAT-CHECKBOX = 'X'.
LS_FCAT-EDIT = 'X'.
* do not forget to provide texts for this extra field
LS_FCAT-COLTEXT = TEXT-F01.
* optional: set column width
LS_FCAT-OUTPUTLEN = 10.
*
APPEND LS_FCAT TO PT_FIELDCAT.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LS_LAYOUT text
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT CHANGING P_LS_LAYOUT TYPE LVC_S_LAYO.
P_LS_LAYOUT-STYLEFNAME = 'STYLE'. "灰显字段的设置
P_LS_LAYOUT-ZEBRA = 'X'.
ENDFORM. " BUILD_LAYOUT