ALV Checkbox 单行灰显

来源:互联网 发布:冰川网络最新国战手游 编辑:程序博客网 时间:2024/04/28 05:12
用 Function Module REUSE_ALV_GRID_DISPLAY 处理 ALV Checkbox 时,只能整列灰显Checkbox。
而用 Function Module REUSE_ALV_GRID_DISPLAY_LVC 以及 OO 的方法才能实现特定行的灰显Checkbox。
OO 方法实现可参考程序: BCALV_EDIT_05

用 Function Module REUSE_ALV_GRID_DISPLAY_LVC 的示例如下:


FORM frm_output_data .
  DATAlv_repid LIKE sy-repid.

  DATAlt_fieldcat TYPE lvc_t_fcat.
  DATAlv_fieldcat TYPE lvc_s_fcat.
  DATAlv_layout TYPE lvc_s_layo.
  DATAlt_events TYPE slis_t_event.
  DATAwa_grid_set TYPE lvc_s_glay.

  DEFINE p1f.
    if lt_fieldcat[] is initial.
      lv_fieldcat-col_pos 1.
    else.
      add 1 to lv_fieldcat-col_pos.
    endif.

    lv_fieldcat-fieldname  &1.
    lv_fieldcat-tabname 'IT_OUT'.
    lv_fieldcat-scrtext_l &2.
    lv_fieldcat-outputlen &3 .

    if lv_fieldcat-fieldname 'BOX'.
      lv_fieldcat-edit          'X'.
      lv_fieldcat-checkbox      'X'.
    else.
      clear lv_fieldcat-checkbox.
      clear lv_fieldcat-edit.
    endif.
    lv_fieldcat-fix_column ''.
    append lv_fieldcat to lt_fieldcat.
  END-OF-DEFINITION.

  "mark items that already exist in the table as pink,
  "and grey out the checkbox of items that already exist in the table or quantity equal zero.
  PERFORM display_color.

  lv_repid sy-repid.
  lv_layout-info_fname 'COLOR'    identify the field of color setting
  lv_layout-stylefname 'IT_STYLE' identify the sub internal table of style setting.

  REFRESH lt_fieldcat.
*Populate structure of ALV field category

  p1f 'BOX' '' 2.
  p1f 'MATNR' 'Material No.'     18.
  p1f 'MAKTX' 'Material Description'    40.
  p1f 'WERKS' 'Plant'   4.
  p1f 'LGORT' 'Storage Location'   4.
  p1f 'SERNR' 'Serial No.'   18.
  p1f 'SOBKZ' 'Special Stock'     1.
  p1f 'VBELN' 'Sales Order'   10.
  p1f 'POSNR' 'Item No.'   6.
  p1f 'KALAB' 'Quantity'   13.
  p1f 'MEINS' 'Unit'   3.

  wa_grid_set-edt_cll_cb 'X'.

*Call 'Reuse function module' to display list as ALV format, this function module can be used to grey out specified field.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program          lv_repid
      i_save                      'X'
      i_callback_pf_status_set    'SET_PF_STATUS'
      i_callback_user_command     'USER_COMMAND'
      is_layout_lvc               lv_layout
      it_fieldcat_lvc             lt_fieldcat
      i_callback_html_end_of_list 'FRM_END_OF_LIST'
     it_events                   lt_events
      I_GRID_SETTINGS             wa_grid_set
    TABLES
      t_outtab                    it_out
    EXCEPTIONS
      program_error               1
      OTHERS                      2.
  IF sy-subrc <> 0.

  ENDIF.

ENDFORM                   FRM_OUTPUT_DATA



FORM display_color .
  DATAwa_style TYPE lvc_s_styl.

  IF it_out[] IS NOT INITIAL.
    CLEARit_zrtnstc, it_zrtnstc[].
    SELECT *
      INTO TABLE it_zrtnstc
      FROM zrtnstc
      FOR ALL ENTRIES IN it_out
      WHERE matnr it_out-matnr
        AND sernr it_out-sernr.
    SORT it_zrtnstc BY matnr sernr.
  ENDIF.

  LOOP AT it_out.
    READ TABLE it_zrtnstc WITH KEY matnr it_out-matnr sernr it_out-sernr BINARY SEARCH.
    IF sy-subrc 0.
      IF it_zrtnstc-flag 'X'material by which the po was created don't need to be stored again.
        DELETE it_out.
        CONTINUE.
      ELSE.
        it_out-color 'C600'mark the items which are already in the table ZRTNSTC as pink.
        MODIFY it_out TRANSPORTING color.
      ENDIF.
    ENDIF.

    if quantity equals zero or already exist in the table, then grey out the check box.
    IF it_out-kalab 0 OR it_out-color IS NOT INITIAL.
      CLEARwa_style, it_out-it_style.
      wa_style-fieldname 'BOX'.
      wa_style-style cl_gui_alv_grid=>mc_style_disabled.
      APPEND wa_style TO it_out-it_style.
      MODIFY it_out TRANSPORTING it_style.
    ENDIF.
  ENDLOOP.
ENDFORM                   display_color



显示效果如下:
ALV <wbr>Checkbox <wbr>单行灰显
原创粉丝点击