首页 > 其他分享 >ABAP 简单ALV 按钮+隐藏和显示

ABAP 简单ALV 按钮+隐藏和显示

时间:2024-03-29 11:04:23浏览次数:22  
标签:GT GS FIELDCAT EVENT ABAP 按钮 ALV TYPE SPFLI

结果

代码


REPORT  ZGUO_TEST.
*调用数据表
TABLES: SPFLI.
*定义、申明变量
TYPE-POOLS: SLIS.
DATA:GT_FIELDCAT TYPE LVC_T_FCAT,GS_FIELDCAT TYPE LVC_S_FCAT,ITEM TYPE I,
     LS_LAYOUT   TYPE LVC_S_LAYO,
     GT_EVENT    TYPE SLIS_T_EVENT WITH HEADER LINE.
DATA:LT_EDIT     TYPE LVC_T_STYL, LS_STYLE TYPE LVC_S_STYL.
DATA:GV_GRID     TYPE REF TO CL_GUI_ALV_GRID,LS_STABLE TYPE LVC_S_STBL.
DATA:COLOR       TYPE SLIS_T_SPECIALCOL_ALV WITH HEADER LINE.

TYPES:BEGIN OF SSPFLI .
        INCLUDE TYPE SPFLI.
TYPES:AMATNR     TYPE C LENGTH 5,
      BING       TYPE C LENGTH 5,
      COLOR(4)   TYPE C,
      CELLSTYLES TYPE LVC_T_STYL,
      ITEM       TYPE I,"隐藏/显示 ID
  END OF SSPFLI.

DATA:T_SPFLI  TYPE TABLE OF SSPFLI WITH HEADER LINE,
     T_SPFLI1 TYPE TABLE OF SPFLI WITH HEADER LINE.

*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.
    METHODS:
    HANDLE_BUTTON_CLICK
      FOR EVENT BUTTON_CLICK OF CL_GUI_ALV_GRID
      IMPORTING ES_COL_ID ES_ROW_NO.
ENDCLASS.                    "LCL_EVENT_RECEIVER DEFINITION

*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_BUTTON_CLICK.

    PERFORM BUTTON_CLICK USING ES_COL_ID ES_ROW_NO .

  ENDMETHOD.                    "HANDLE_BUTTON_CLICK
ENDCLASS.                    "LCL_EVENT_RECEIVER IMPLEMENTATION

DATA GT_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER .

INITIALIZATION.

START-OF-SELECTION.
  PERFORM FRM_LOAD_DATA.
*&---------------------------------------------------------------------*
*&      Form  FRM_LOAD_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FRM_LOAD_DATA.
  PERFORM FRM_FIELD.
  CLEAR T_SPFLI.REFRESH T_SPFLI.
  SELECT * INTO CORRESPONDING FIELDS OF TABLE T_SPFLI FROM SPFLI.

  LS_LAYOUT-INFO_FNAME = 'COLOR'.
  LS_LAYOUT-STYLEFNAME = 'CELLSTYLES'.
  GT_EVENT-NAME = 'CALLER_EXIT'.   "slis_ev_caller_exit_at_start事件
  GT_EVENT-FORM = 'FM_BUTTON'. "FROM 事件
  APPEND GT_EVENT .

  SORT T_SPFLI BY CARRID.
  DELETE ADJACENT DUPLICATES FROM T_SPFLI COMPARING CARRID.

  CLEAR:LT_EDIT,ITEM.REFRESH LT_EDIT.
  LOOP AT T_SPFLI.
    ITEM = ITEM + 1.
    T_SPFLI-BING = '>'.
    T_SPFLI-ITEM = ITEM.
    CLEAR T_SPFLI-CITYTO.

    LS_STYLE-FIELDNAME = 'AMATNR' .
    LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON .
    INSERT LS_STYLE INTO TABLE LT_EDIT .
    T_SPFLI-CELLSTYLES = LT_EDIT .
    T_SPFLI-AMATNR = '+'.
    MODIFY T_SPFLI TRANSPORTING CELLSTYLES BING AMATNR CITYTO ITEM.

  ENDLOOP.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      IS_LAYOUT_LVC      = LS_LAYOUT
      IT_FIELDCAT_LVC    = GT_FIELDCAT
      IT_EVENTS          = GT_EVENT[]
    TABLES
      T_OUTTAB           = T_SPFLI[]
    EXCEPTIONS
      PROGRAM_ERROR      = 1
      OTHERS             = 2.
ENDFORM.                    "FRM_LOAD_DATA

*显示栏位
FORM FRM_FIELD.

  REFRESH: GT_FIELDCAT.
  CLEAR: GT_FIELDCAT.

*显示数据表格ALV的栏位
  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'CARRID'.
  GS_FIELDCAT-COLTEXT = 'Airline'.
  GS_FIELDCAT-OUTPUTLEN = 8.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'CONNID'.
  GS_FIELDCAT-COLTEXT = 'Connection Number'.
  GS_FIELDCAT-OUTPUTLEN = 8.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'COUNTRYFR'.
  GS_FIELDCAT-COLTEXT = 'Country Key'.
  GS_FIELDCAT-OUTPUTLEN = 6.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'CITYFROM'.
  GS_FIELDCAT-COLTEXT = 'Departure city'.
  GS_FIELDCAT-OUTPUTLEN = 12.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'AIRPFROM'.
  GS_FIELDCAT-COLTEXT = 'Departure airport'.
  GS_FIELDCAT-OUTPUTLEN = 12.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'AMATNR'.
  GS_FIELDCAT-COLTEXT = '隐藏/显示'.
  GS_FIELDCAT-OUTPUTLEN = 9.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'BING'.
  GS_FIELDCAT-COLTEXT = ''.
  GS_FIELDCAT-OUTPUTLEN = 5.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = 'CITYTO'.
  GS_FIELDCAT-COLTEXT = 'Arrival city'.
  GS_FIELDCAT-OUTPUTLEN = 15.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.

ENDFORM.                    "FRM_FIELD

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

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = GV_GRID.

*   CALL METHOD ref_grid->check_changed_data.

* 设置enter事件

  CALL METHOD GV_GRID->REGISTER_EDIT_EVENT
    EXPORTING
      I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED"MC_EVT_ENTER
    EXCEPTIONS
      ERROR      = 1
      OTHERS     = 2.

  CREATE OBJECT GT_EVENT_RECEIVER.

  SET HANDLER GT_EVENT_RECEIVER->HANDLE_BUTTON_CLICK FOR GV_GRID.

ENDFORM.                    "FM_BUTTON

*&---------------------------------------------------------------------*
*&      Form  BUTTON_CLICK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_COL_ID   text
*      -->P_ROW_NO   text
*----------------------------------------------------------------------*
FORM BUTTON_CLICK USING P_COL_ID
                        P_ROW_NO TYPE LVC_S_ROID.

  DATA:STRTABIX TYPE I,STRTABIX1 TYPE I.

  IF P_COL_ID = 'AMATNR'.
    CLEAR:T_SPFLI .CLEAR LT_EDIT.REFRESH LT_EDIT.
    READ TABLE T_SPFLI INDEX P_ROW_NO-ROW_ID.
    IF SY-SUBRC = 0 AND T_SPFLI-AMATNR = '+'."点击按钮 ,显示隐藏数据
      STRTABIX = P_ROW_NO-ROW_ID.

      CLEAR T_SPFLI1.REFRESH T_SPFLI1.
      SELECT * INTO CORRESPONDING FIELDS OF TABLE T_SPFLI1 FROM SPFLI WHERE CARRID = T_SPFLI-CARRID .

      LOOP AT T_SPFLI1 .
        STRTABIX = STRTABIX + 1.
        STRTABIX1 = STRTABIX1 + 1.

        CLEAR T_SPFLI.
        T_SPFLI-BING  = '>>'.
        IF STRTABIX1 = 1."渐变颜色
          T_SPFLI-COLOR = 'C300'.
        ELSE.
          T_SPFLI-COLOR = 'C700'.
          CLEAR STRTABIX1.
        ENDIF.
        T_SPFLI-CARRID = T_SPFLI1-CARRID .
        T_SPFLI-CITYTO = T_SPFLI1-CITYTO.

        INSERT T_SPFLI INTO T_SPFLI INDEX STRTABIX.
      ENDLOOP.

      LS_STYLE-FIELDNAME = 'AMATNR' .
      LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON .
      INSERT LS_STYLE INTO TABLE LT_EDIT .
      T_SPFLI-CELLSTYLES = LT_EDIT .
      T_SPFLI-AMATNR = '-'.
      T_SPFLI-BING  = '>'.
      MODIFY T_SPFLI INDEX P_ROW_NO-ROW_ID TRANSPORTING CELLSTYLES AMATNR BING.
    ELSEIF SY-SUBRC = 0 AND T_SPFLI-AMATNR = '-'."隐藏数据
      DELETE T_SPFLI WHERE CARRID = T_SPFLI-CARRID AND ITEM = 0.

      CLEAR LT_EDIT.REFRESH LT_EDIT.
      LS_STYLE-FIELDNAME = 'AMATNR' .
      LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON .
      INSERT LS_STYLE INTO TABLE LT_EDIT .
      T_SPFLI-CELLSTYLES = LT_EDIT .
      T_SPFLI-AMATNR = '+'.
      T_SPFLI-BING   = '>'.
      MODIFY T_SPFLI INDEX P_ROW_NO-ROW_ID TRANSPORTING CELLSTYLES AMATNR BING.
    ENDIF.

  ENDIF.

  LS_STABLE-ROW = 'X'." 基于行的稳定刷新
  LS_STABLE-COL = 'X'." 基于列稳定刷新
  CALL METHOD GV_GRID->REFRESH_TABLE_DISPLAY
    EXPORTING
      IS_STABLE = LS_STABLE.
ENDFORM.                    "BUTTON_CLICK

标签:GT,GS,FIELDCAT,EVENT,ABAP,按钮,ALV,TYPE,SPFLI
From: https://blog.csdn.net/ggl112233/article/details/137138302

相关文章

  • SAP:界面程序上的按钮、LABEL、Checkbox等说明在哪里定义
    环境:SAPECC6:1、界面程序上的按钮、LABEL、Checkbox等说明在哪里定义?在事务码T-CODE:SE80创建程序后(如:Z12_06),在工具菜单栏点击“其它对象...”按钮,选择”增强选项“,在对象选择窗口的,选择”程序”标签页的“文本元素”。在“文本符号”标签页里输入文本内容。字段说明:符......
  • Android Switch开关按钮使用和自定义样式
    最终效果minHeight,switchMinWidth调整switch开关高度、宽度android:thumb开关按钮上原型滑块的样式android:track开关按钮下面导轨的样式<Switchandroid:layout_width="48dp"android:layout_height="24dp"android:layout_marginEnd="21dp"......
  • 【无标题】idea 中 SpringBoot 点击运行没反应,按钮成灰色
    问题描述在使用SpringBoot开发项目时,可能会遇到一个问题:点击运行按钮后,控制台没有任何输出,项目界面也没有显示。这种情况可能是由多种原因导致的,本文将介绍一些常见的解决方法。解决方法首先看下Groovy插件是否选择,取消选择1.检查端口是否被占用首先,我们需要检查应用程......
  • SAP HCM ABAP 数据选择期间与个人选择期
    个人选择期间:个人选择期间和0001中的各项条件共同作用确定逻辑数据库可以抓到符合条件的人员。对应的字段:PN-BEGPS  PN-ENDPS对应的屏幕字段:PNPBEGPSPNPENDPS 数据选择期间:对应的字段是pn-begda和pn-endda,用户在选择屏幕中输入了数据选择期间的相关数值后,之所以起到......
  • WPF中自定义按钮实现最大化最小化动画过度效果
    需要使用WindowsAPI[DllImport("user32.dll",EntryPoint="SetWindowLong")]privatestaticexternintSetWindowLong32(HandleRefhWnd,intnIndex,intdwNewLong);[DllImport("user32.dll",EntryPoint="SetWindowLongPtr"......
  • 监控工具-jvisualvm.exe-入门,监控tomcat7的jmx、jstatd
    1、添加JMX1.1、catalina-jmx-remote.jar 放在Tomcat的 lib 目录下catalina-jmx-remote.jar 的确切位置可能因Tomcat版本和发行版而异,但通常它应该被放置在Tomcat的 lib 目录下 1.2、catalina.sh设置JVM参数对于Linux/Unix,编辑 catalina.sh 文件......
  • js/jquery:5行代码实现点击按钮复制文字到剪贴板
     方法1:<pid="p1">Hello,I'mTEXT1</p><buttononclick="copyToClipboard_js('p1')">复制文字1(js)</button><script>functioncopyToClipboard_js(element){vartemp=document.createElement(&quo......
  • css设置按钮心跳收缩后,按钮文字上下抖动,如何解决?
    如题,给一个按钮写一个css心跳收缩动画后,按钮中的文字会上下抖动,解决方案为   will-change:transform;代码如下://按键呼吸特效使用class="pulse"@keyframespulse{0%{transform:scale(1);}25%{transform:scale(0.95);}50%{transfo......
  • 问题解答:ABAP 关键字 ANY TABLE 的使用场合深入剖析
    本教程下面这篇讲述ABAP动态编程的文章,有朋友提问:127.答网友疑问:ABAPFunctionModule如何支持内表结构不确定的动态输入参数汪老师,我这边定义了一个ANYTABLE,但是报错,说是没有这个类型,我在SE38定义的时候也报错,只有用FIELD-symbols定义才不会报错,所以就很好奇为什......
  • 149. 如何在 SAPGUI 的 ABAP 报表里显示图片
    本教程前一篇步骤,我们学习了在SAPGUI里,将屏幕划分成若干个区域,每个区域分别放置GUI元素进行屏幕绘制的方法。148.使用SAPGUI的Docking控件将屏幕划分成若干子区域当时我们完成了一个例子,一个完整的屏幕,被划分成了左上,左下和右边三个区域,分别显示了三个TextEd......