ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ALV OO 的单元格编辑控制

ALV OO 的单元格编辑控制

原创 Linux操作系统 作者:hzq2010 时间:2011-05-03 22:00:15 0 删除 编辑
REPORT  ZALV_CELL                          .
DATA: OK_CODE LIKE SY-UCOMM.
*ALV OO 的必要定义.
DATA: GRID TYPE REF TO CL_GUI_ALV_GRID,                    ”定义ALV对象
      CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. “ 定义一个容器
DATA: L_ALV_FILED    TYPE  LVC_S_FCAT,                  "ALV OO 的字段抬头的workarea
      L_ALV_FILEDCAT LIKE  LVC_S_FCAT OCCURS 1,         "ALV OO 的字段抬头内表
      L_ALV_LAYOUT   TYPE  LVC_S_LAYO.                  "ALV OO 的布局WROKAREA
*输出内表工作区
DATA: BEGIN OF WA_GT_LIST ,
        A    LIKE SY-INDEX,
        B    LIKE SY-INDEX,
        CELLSTYLE. TYPE LVC_T_STYL ,
 END OF WA_GT_LIST.
*输出内表
DATA: GT_LIST LIKE STANDARD TABLE OF WA_GT_LIST WITH HEADER LINE.
START-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS '100'.
  SET TITLEBAR '100'.

  PERFORM. GET_DATA.                         "添加数据

  PERFORM. CELL_CTRL.                        "单元格属性控制
  PERFORM. ALV_SET.                          "设置ALV 参数
  PERFORM. EXIT.
ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. GET_DATA .
  DO 10 TIMES .
    WA_GT_LIST-A = SY-INDEX .
    WA_GT_LIST-B = SY-INDEX ** 2 .
    APPEND WA_GT_LIST TO GT_LIST  .
  ENDDO .
ENDFORM.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  ALV_SET
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. ALV_SET .
  L_ALV_FILED-FIELDNAME = 'A'.
  L_ALV_FILED-COLTEXT   = 'AAAA'.
  APPEND L_ALV_FILED TO L_ALV_FILEDCAT.
  L_ALV_FILED-FIELDNAME = 'B'.
  L_ALV_FILED-COLTEXT   = 'BBBB'.
  APPEND L_ALV_FILED TO L_ALV_FILEDCAT.
  IF CUSTOM_CONTAINER IS INITIAL.
    CREATE OBJECT CUSTOM_CONTAINER
      EXPORTING
        CONTAINER_NAME = 'CON'.
    CREATE OBJECT GRID
      EXPORTING
        I_PARENT = CUSTOM_CONTAINER.
  ENDIF.
   L_ALV_LAYOUT-stylefname = 'CELLSTYLE'.          ”在ALV布局中设置单元格属性
  CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
               EXPORTING

                  IS_LAYOUT = L_ALV_LAYOUT
               CHANGING
                 IT_FIELDCATALOG = L_ALV_FILEDCAT
                 IT_OUTTAB       = GT_LIST[].
  REFRESH: L_ALV_FILEDCAT.
  CLEAR:   L_ALV_LAYOUT.
*编辑状态的设置
        CALL METHOD GRID->SET_READY_FOR_INPUT
          EXPORTING
            I_READY_FOR_INPUT = 1.
ENDFORM.                    " ALV_SET
*&---------------------------------------------------------------------*
*&      Form  EXIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. EXIT .
  CASE OK_CODE.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      LEAVE TO SCREEN 0.
  ENDCASE.
  CLEAR OK_CODE.
ENDFORM.                    " EXIT
*&---------------------------------------------------------------------*
*&      Form  CELL_CTRL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. CELL_CTRL .
  DATA LS_STYLEROW TYPE LVC_S_STYL .
  DATA LT_STYLETAB TYPE LVC_T_STYL .
  LOOP AT GT_LIST INTO WA_GT_LIST.
    CLEAR:   LS_STYLEROW.
    REFRESH: LT_STYLETAB.

    IF WA_GT_LIST-A = '3' or
       WA_GT_LIST-A = '5' or
       WA_GT_LIST-A = '7'.

      LS_STYLEROW-FIELDNAME = 'B'.
      LS_STYLEROW-STYLE. = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
      INSERT LS_STYLEROW INTO TABLE LT_STYLETAB.
    ENDIF.
    WA_GT_LIST-CELLSTYLE. = LT_STYLETAB.
    MODIFY GT_LIST FROM WA_GT_LIST.
  ENDLOOP.
ENDFORM.                    " CELL_CTRL

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23495244/viewspace-694376/,如需转载,请注明出处,否则将追究法律责任。

上一篇: ABAP System Tables
请登录后发表评论 登录
全部评论

注册时间:2010-03-11

  • 博文量
    196
  • 访问量
    172116