function ALV

自我ALV 理解学习,集有 回车事件 ,自定义按钮,ALV网格颜色。

REPORT ZALV_TEST.
TYPE-POOLS:ZSLIS.

DATA:BEGIN OF GT_DATA OCCURS 0,  "显示数据内表。
     MATNR LIKE MARA-MATNR,  "物料
     MATKL LIKE MARA-MATKL,  "物料组
     BISMT LIKE MARA-BISMT,  "旧物料
     MEINS LIKE MARA-MEINS,  "基本单位
     COLOR(4) TYPE C,
  END OF GT_DATA.

DATA: BEGIN OF GT_DATA2 OCCURS 0.
        INCLUDE STRUCTURE GT_DATA.
DATA: CE_COLOR TYPE SLIS_T_SPECIALCOL_ALV.
DATA: END OF GT_DATA2.

DATA:GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: GS_LAYOUT   TYPE SLIS_LAYOUT_ALV.

DATA: GIT_EVENTS TYPE SLIS_T_EVENT.     "ALV 事件
DATA TEM_GRID  TYPE REF TO CL_GUI_ALV_GRID.

*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.
    " 回车事件
    METHODS HANDLE_MODIFY
    FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID
    IMPORTING  E_MODIFIED ET_GOOD_CELLS.

    " 鼠标离开事件
    METHODS    HANDLE_DATA_CHANGED
           FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
               IMPORTING ER_DATA_CHANGED E_ONF4 E_ONF4_BEFORE E_ONF4_AFTER E_UCOMM.
ENDCLASS.                    "LCL_EVENT_RECEIVER DEFINITION

*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_MODIFY.
    MESSAGE: S000(Z001) WITH ‘回车‘.
  ENDMETHOD.                    "HANDLE_MODIFY

  METHOD HANDLE_DATA_CHANGED.
    DATA STBL TYPE LVC_S_STBL.
    PERFORM HANDLE_DATA_CHANGED  USING ER_DATA_CHANGED.  "处理受变化的数据

*   稳定刷新
    STBL-ROW = ‘X‘." 基于行的稳定刷新
    STBL-COL = ‘X‘." 基于列稳定刷新
    CALL METHOD TEM_GRID->REFRESH_TABLE_DISPLAY
      EXPORTING
        IS_STABLE = STBL.
  ENDMETHOD.                    "HANDLE_MODIFY
ENDCLASS.                    "LCL_EVENT_RECEIVER IMPLEMENTATION

DATA GT_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER .   " 定义类

START-OF-SELECTION.

  PERFORM GET_DATA.  "
  PERFORM SET_FIELDCAT.
  " PERFORM ALV_LAYOUT.   " 设置行颜色
  PERFORM GET_EVENT.      " 设置事件
  PERFORM ALV_SHOW.

  "PERFORM SET_COLOR.  "设置单元格颜色

*&---------------------------------------------------------------------*
*&      Form  get_event
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GET_EVENT.

  DATA FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE ‘FRM_TOP_OF_PAGE‘.
  DATA L_EVENTS TYPE LINE OF SLIS_T_EVENT.

  CALL FUNCTION ‘REUSE_ALV_EVENTS_GET‘
    EXPORTING
      I_LIST_TYPE     = 0
    IMPORTING
      ET_EVENTS       = GIT_EVENTS
    EXCEPTIONS
      LIST_TYPE_WRONG = 1
      OTHERS          = 2.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CLEAR L_EVENTS.

  READ TABLE GIT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE INTO L_EVENTS.
  L_EVENTS-NAME = ‘CALLER_EXIT‘.   "事件名
  L_EVENTS-FORM = ‘FM_BUTTON‘.     "处理事件FORM
  APPEND L_EVENTS TO GIT_EVENTS.

ENDFORM.                    "get_event

*&---------------------------------------------------------------------*
*&      Form  fm_button
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->E_GRID     text
*----------------------------------------------------------------------*
FORM FM_BUTTON USING E_GRID TYPE SLIS_DATA_CALLER_EXIT.

  " 得到当前的 ALV
  CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR‘
*   EXPORTING
*     IR_SALV_FULLSCREEN_ADAPTER       =
      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.

* 设置 单光标焦点移开被修改单元格后既触发事件
  CALL METHOD TEM_GRID->REGISTER_EDIT_EVENT
    EXPORTING
      I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED
    EXCEPTIONS
      ERROR      = 1
      OTHERS     = 2.

  "创建类对象
  CREATE OBJECT GT_EVENT_RECEIVER.
  " 设置方法
  SET HANDLER GT_EVENT_RECEIVER->HANDLE_MODIFY FOR TEM_GRID.
  SET HANDLER GT_EVENT_RECEIVER->HANDLE_DATA_CHANGED FOR TEM_GRID.
ENDFORM.                    "fm_button

*&---------------------------------------------------------------------*
*&      Form  handle_data_changed
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_ER_DATA_CHANGED  text
*----------------------------------------------------------------------*
FORM HANDLE_DATA_CHANGED  USING P_ER_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
  DATA:MOD_DATA TYPE LVC_T_MODI,
       WA_MOD_DATA TYPE LVC_S_MODI.

  MOD_DATA = P_ER_DATA_CHANGED->MT_MOD_CELLS.      " 获取变更后列

  DATA:ROW_ID TYPE I,
       C_VALUE(130) TYPE C,  "变更后的值
       C_NAME(30) TYPE C.    "变更的列名

  CLEAR:ROW_ID, C_VALUE,C_NAME.

  LOOP AT MOD_DATA INTO WA_MOD_DATA.
    ROW_ID = WA_MOD_DATA-ROW_ID.
    C_NAME = WA_MOD_DATA-FIELDNAME.
    C_VALUE =  WA_MOD_DATA-VALUE.
  ENDLOOP.

  MESSAGE S000(Z001) WITH  ‘修改成功‘.

ENDFORM.                    "HANDLE_DATA_CHANGED

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GET_DATA.
  SELECT  MARA~MATNR  MARA~MATKL MARA~BISMT MARA~MEINS FROM MARA INTO TABLE GT_DATA  UP TO 100  ROWS.
ENDFORM.                    "get_data

*&---------------------------------------------------------------------*
*&      Form  SET_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM SET_FIELDCAT.
  DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

  LS_FIELDCAT-FIELDNAME  = ‘MATNR‘.
  LS_FIELDCAT-SELTEXT_L  = ‘物料‘.
  LS_FIELDCAT-KEY        = ‘X‘.  "关键列
  LS_FIELDCAT-EDIT        = ‘X‘.
  "  LS_FIELDCAT-EMPHASIZE  = ‘C100‘.  "列颜色
  APPEND LS_FIELDCAT TO GT_FIELDCAT.
  CLEAR: LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME  = ‘MATKL‘.
  LS_FIELDCAT-SELTEXT_L  = ‘物料组‘.
  "  LS_FIELDCAT-EMPHASIZE  = ‘C200‘.  "列颜色
  APPEND LS_FIELDCAT TO GT_FIELDCAT.
  CLEAR: LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME  = ‘BISMT‘.
  LS_FIELDCAT-SELTEXT_L  = ‘旧物料‘.
  "  LS_FIELDCAT-EMPHASIZE  = ‘C300‘.  "列颜色
  APPEND LS_FIELDCAT TO GT_FIELDCAT.
  CLEAR: LS_FIELDCAT.

  LS_FIELDCAT-FIELDNAME  = ‘MEINS‘.
  LS_FIELDCAT-SELTEXT_L  = ‘基本单位‘.
  "  LS_FIELDCAT-EMPHASIZE  = ‘C400‘.  "列颜色
  APPEND LS_FIELDCAT TO GT_FIELDCAT.
  CLEAR: LS_FIELDCAT.
ENDFORM.                    "SET_FIELDCAT

*&---------------------------------------------------------------------*
*&      Form  ALV_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM ALV_LAYOUT.

  DATA: L_COLOR(4) TYPE C,
        L_CHAR     TYPE C,
        I          TYPE I.

  LOOP AT GT_DATA.
    L_CHAR = SY-INDEX.
    IF SY-TABIX MOD 2 = 0.
      CONCATENATE ‘C‘  ‘101‘ INTO L_COLOR.
    ELSE.
      CONCATENATE ‘C‘  ‘210‘ INTO L_COLOR.
    ENDIF.
    GT_DATA-COLOR = L_COLOR.
    MODIFY GT_DATA.
  ENDLOOP.

  GS_LAYOUT-INFO_FIELDNAME = ‘COLOR‘.  "设置行的颜色
ENDFORM.                    "ALV_LAYOUT

*&---------------------------------------------------------------------*
*&      Form  set_COLOR
*&---------------------------------------------------------------------*
*       text  设置单元个颜色
*----------------------------------------------------------------------*
FORM SET_COLOR.
  DATA: COLOR_WA TYPE SLIS_T_SPECIALCOL_ALV WITH HEADER LINE."单元格颜色属性内表

  LOOP AT GT_DATA.
    MOVE-CORRESPONDING GT_DATA TO GT_DATA2. "转移数据到itab_test3内表

    REFRESH COLOR_WA.
    " 第一列颜色
    COLOR_WA-COLOR-COL = ‘2‘.  "颜色代码
    COLOR_WA-COLOR-INT = ‘0‘.
    COLOR_WA-COLOR-INV = ‘0‘.
    COLOR_WA-FIELDNAME = ‘MATNR‘.
    APPEND COLOR_WA.
    "    CONCATENATE L_CHAR ‘00‘ INTO ITAB_TEST3-COL1.
    " 第二列颜色
    COLOR_WA-COLOR-INT = ‘0‘.
    COLOR_WA-COLOR-INV = ‘1‘.
    COLOR_WA-FIELDNAME = ‘MATKL‘.
    APPEND COLOR_WA.
    "    CONCATENATE L_CHAR ‘01‘ INTO ITAB_TEST3-COL2.
    " 第三列颜色
    COLOR_WA-COLOR-INT = ‘1‘.
    COLOR_WA-COLOR-INV = ‘0‘.
    COLOR_WA-FIELDNAME = ‘BISMT‘.
    APPEND COLOR_WA.
    "    CONCATENATE L_CHAR ‘10‘ INTO ITAB_TEST3-COL3.
    GT_DATA2-CE_COLOR[] = COLOR_WA[].
    APPEND GT_DATA2.
  ENDLOOP.

  GS_LAYOUT-COLTAB_FIELDNAME = ‘CE_COLOR‘.

  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY‘
    EXPORTING
      IS_LAYOUT   = GS_LAYOUT
      IT_FIELDCAT = GT_FIELDCAT[]
    TABLES
      T_OUTTAB    = GT_DATA2.

ENDFORM.                    "set_COLOR

*&---------------------------------------------------------------------*
*&      Form  ALV_SHOW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM ALV_SHOW.
  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY‘
   EXPORTING
*     I_INTERFACE_CHECK                 = ‘ ‘
*     I_BYPASSING_BUFFER                = ‘ ‘
*     I_BUFFER_ACTIVE                   = ‘ ‘
     I_CALLBACK_PROGRAM                = SY-REPID  "返回的调用程序
     I_CALLBACK_PF_STATUS_SET          = ‘SET_PF_STATUS‘  "ALV状态栏
     I_CALLBACK_USER_COMMAND           = ‘USER_COMMAND‘   "按钮方法
*     I_CALLBACK_TOP_OF_PAGE            = ‘ ‘
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ‘ ‘
*     I_CALLBACK_HTML_END_OF_LIST       = ‘ ‘
*     I_STRUCTURE_NAME                  =
*     I_BACKGROUND_ID                   = ‘ ‘
*     I_GRID_TITLE                      =
*     I_GRID_SETTINGS                   =
      IS_LAYOUT                         =  GS_LAYOUT
      IT_FIELDCAT                       =  GT_FIELDCAT[]
*     IT_EXCLUDING                      =
*     IT_SPECIAL_GROUPS                 =
*     IT_SORT                           =
*     IT_FILTER                         =
*     IS_SEL_HIDE                       =
*     I_DEFAULT                         = ‘X‘
*     I_SAVE                            = ‘ ‘   "是否保存变式
*     IS_VARIANT                        =
     IT_EVENTS                         =    GIT_EVENTS
*     IT_EVENT_EXIT                     =
*     IS_PRINT                          =
*     IS_REPREP_ID                      =
*     I_SCREEN_START_COLUMN             = 0
*     I_SCREEN_START_LINE               = 0
*     I_SCREEN_END_COLUMN               = 0
*     I_SCREEN_END_LINE                 = 0
*     I_HTML_HEIGHT_TOP                 = 0
*     I_HTML_HEIGHT_END                 = 0
*     IT_ALV_GRAPHICS                   =
*     IT_HYPERLINK                      =
*     IT_ADD_FIELDCAT                   =
*     IT_EXCEPT_QINFO                   =
*     IR_SALV_FULLSCREEN_ADAPTER        =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER           =
*     ES_EXIT_CAUSED_BY_USER            =
    TABLES
      T_OUTTAB                          =  GT_DATA[]
*   EXCEPTIONS
*     PROGRAM_ERROR                     = 1
*     OTHERS                            = 2
            .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.

ENDFORM.                    "ALV_SHOW

*&---------------------------------------------------------------------*
*&      Form  SET_PF_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
  SET PF-STATUS ‘STANDARD‘.
ENDFORM.                    "SET_PF_STATUS

*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->UCOMM      text
*      -->FILECAT    text
*----------------------------------------------------------------------*
FORM USER_COMMAND   USING UCOMM TYPE SY-UCOMM
                          FILECAT TYPE SLIS_SELFIELD.
case ucomm.
  when ‘/&PRINT‘.
    MESSAGE S000(Z001) with ‘你点击了打印‘.
  endcase.

ENDFORM.                    "USER_COMMAND
时间: 2024-10-22 04:53:37

function ALV的相关文章

ALV详解:Function ALV(一)

声明:原创作品,转载时请注明文章来自SAP师太技术博客:www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将追究法律责任!原文链接:http://www.cnblogs.com/jiangzhengjun/p/4291337.html Function ALV.. 5 Layout结构... 5 Fieldcat结构... 7 ALV相关函数... 9 简单实例... 13 Fieldcat动态创建... 15 通过编程创建... 15 通过REUS

ALV详解:Function ALV(二)

声明:原创作品,转载时请注明文章来自SAP师太技术博客:www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将追究法律责任!原文链接:http://www.cnblogs.com/jiangzhengjun/p/4291344.html Function ALV.. 5 单元格数据修改后立即同步(即立即触发DATA_CHANGED事件)输出内表... 37 方法一:通过REUSE_ALV_GRID_DISPLAY 函数的i_grid_settings-

ALV详解:OO SALV

声明:原创作品,转载时请注明文章来自SAP师太技术博客:www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将追究法律责任!原文链接:http://www.cnblogs.com/jiangzhengjun/p/4291387.html OOSALV.. 123 三种显示模式... 123 全屏模式... 125 全屏经典列表模式... 126 可控模式... 126 CL_SALV_TABLE设置相关方法... 128 样式设置... 130 显示设

通过百度echarts实现数据图表展示功能

现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解echarts是个怎样技术的开发者来说,可以到echarts官网进行学习了解,官网有详细的API文档和实例供大家参考学习. 2.以下是我在工作中实现整理出来的实例源码: 公用的支持js文件 echarts.js.echarts.min.js,还有其他的图表需要支持的js文件也可以到官网下载 echa

帮同学做的大一大作业:《我的家乡—郑州》

---恢复内容开始--- 最近在上海上学的一个高中同学让我帮忙,帮她做她们的计算机课程大作业. 由于关系不错我也不好意思拒绝就帮忙做了,因为这个学期刚刚开始接触HTML5和css,所以制作过程中有很多不懂的,而且由于HTML5是选修课,一星期只有一节,所以做这个花费了比较多的时间,这个网站是我制作的第一个网站,比较有纪念意义,所以发在博客上,作为纪念. 通过去做这个作业,我了解到很多课上学不到的东西.因为没有美工,从头到尾,都是我一个人在臆想,刚开始的时候,根本无从下手,我去参考别人做的家乡网站

一个简单的alv双击行实现smartforms打印

利用alv显所有查询订单抬头信息,双击行实现一个订单详情的smartforms打印,smartforms实现一个强制分页,里面还有点乱,没怎么规划,主要用到EKKO与EKPO两张表. *&---------------------------------------------------------------------* *& Report  Z_SSX_TEST_ALV_01 *&*&-----------------------------------------

[ABAP技术总结]ALV

目录导航 声明:原创作品,转载时请注明文章来自SAP师太博客,并以超链接形式标明文章原始出处,否则将追究法律责任!原文出自: 7.      ALV. 70 7.1.           Layout重要字段... 70 7.2.           FIELDCATALOG重要字段... 70 7.3.           指定双击触发的FunCode. 71 7.4.           相关函数... 71 7.5.           重要参数接口... 71 7.6.         

abap alv multiple header using write

A standard SAP ALV list report will show only one line header, but there will be a requirement someday for you to create a multiple lines header in your ALV list report and in order to do this, you must first set the no_colhead property to "X" i

ALV行 列颜色设置

ALV的颜色设置分为3种:行.列.单元格. 1.列颜色的设置 在 slis_t_fieldcat_alv-emphasize 中,写入需要的颜色代码. Eg: DATA: fc TYPE slis_t_fieldcat_alv WITH HEADER LINE. fc-tabname = 'ITAB'. fc-fieldname = 'COL'. fc-emphasize = 'C100'. append fc. 2.行颜色的设置 a.在要输出的 itab 中,加入 color 列,类型为C(4