首页 > 其他分享 >function ALV 获取OO ALV event ID

function ALV 获取OO ALV event ID

时间:2024-04-10 09:22:26浏览次数:27  
标签:function OO f4 PERFORM alv grid ls ALV event

SAP ABAP ALV(LVC)的一个自定义事件(F4帮助事件,回车ENTER按钮事件)的一个实例

https://blog.csdn.net/zhongguomao/article/details/51775112

 

1. 定义和注册事件接受器类
*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED
*----------------------------------------------------------------------*
*       LCL_EVENT_RECEIVER
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA gv_flg  TYPE char01.
 
*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
*       lcl_event_receiver的类定义:
*----------------------------------------------------------------------*
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_f4
        FOR EVENT onf4 OF cl_gui_alv_grid
        IMPORTING e_fieldname
                  es_row_no
                  er_event_data
                  et_bad_cells.
 
ENDCLASS.                    "LCL_EVENT_RECEIVER DEFINITION
 
*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
 
  METHOD  handle_modify.
    DATA: lv_enter    TYPE REF TO cl_gui_event,
          lv_eventid  TYPE i.
 
*   获取当前事件
    lv_enter   = tem_grid->cur_event.
 
*   实例化成功的时候
    IF lv_enter IS NOT INITIAL.
      lv_eventid = lv_enter->eventid.
    ENDIF.
 
*   只有在[回车]事件的时候,再进行检查(19:代表回车事件)
    IF lv_eventid = 19
   AND sy-ucomm   = ''.
 
      IF p_mmvds = 'X'.
*       设置供应商描述字段和物料描述字段
        PERFORM set_name1_maktx.
 
*       设置后,alv稳定刷新
        PERFORM refresh_table_alv.
 
*       添加行项目检查(多频次包装基础表)
        PERFORM check_line_mmvds.
 
      ELSEIF p_detail = 'X'.
*       添加行项目检查(窗口时间表)
        PERFORM check_line_dtdetail.
 
      ELSEIF p_vds = 'X'.
*       设置供应商描述字段(供应商供货信息基础表)
        PERFORM set_name1_vds.
 
*       设置后,alv稳定刷新
        PERFORM refresh_table_alv.
 
*       添加行项目检查(供应商供货信息基础表)
        PERFORM check_line_vds.
      ENDIF.
 
    ENDIF.
 
*   设置后,alv稳定刷新
    PERFORM refresh_table_alv.
 
  ENDMETHOD.                    "HANDLE_MODIFY
 
 
  METHOD  handle_f4.
*   供应商供货信息基础表的情况
    IF p_vds = 'X'.
*     窗口时间参数的自定义f4检索帮助
      PERFORM f4_help_zsjcs USING e_fieldname
                                  es_row_no.
 
*     设置后,alv稳定刷新
      PERFORM refresh_table_alv.
 
    ENDIF.
 
  ENDMETHOD.                    "HANDLE_F4
 
ENDCLASS.                    "LCL_EVENT_RECEIVER IMPLEMENTATION
2. 调用alv函数

**EVENT LAYOUT
  DATA: ls_events     TYPE slis_alv_event,
        lt_event      TYPE slis_t_event,
        ls_layout     TYPE lvc_s_layo.
 
  ls_events-name = 'CALLER_EXIT'.
  ls_events-form = 'FM_BUTTON'.
  APPEND ls_events TO lt_event.
 
  ls_layout-stylefname = 'FIELD_STYL'.
  ls_layout-zebra      = 'X'.
  ls_layout-box_fname  = 'CHK_BOX'.
  ls_layout-cwidth_opt = 'X'.
 
 
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'PF_STATUS_SET'
      i_callback_user_command  = 'USER_COMMAND'
      is_layout_lvc            = ls_layout
      it_fieldcat_lvc          = gt_fieldcat_lvc
      i_save                   = 'X'
      it_events                = lt_event
    TABLES
      t_outtab                 = pt_outdata
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
3. 定义是事件子程序
*&---------------------------------------------------------------------*
*&      Form  FM_BUTTON
*&---------------------------------------------------------------------*
*       设置enter事件
*----------------------------------------------------------------------*
*      -->E_GRID     text
*----------------------------------------------------------------------*
FORM fm_button USING e_grid TYPE slis_data_caller_exit.
  DATA: lv_event_receiver TYPE REF TO lcl_event_receiver,
        lt_f4             TYPE lvc_t_f4,
        ls_f4             TYPE lvc_s_f4.
 
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    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.
 
  CREATE OBJECT lv_event_receiver.
  SET HANDLER lv_event_receiver->handle_modify FOR tem_grid.
 
 
* 设置f4事件
  CHECK gv_flg IS INITIAL.
 
  gv_flg = 'X'.
 
  ls_f4-fieldname  = 'ZSJCS'.   "窗口时间参数(需要定义F4帮助按钮的字段)
  ls_f4-register   = 'X'.
  ls_f4-getbefore  = 'X'.
  ls_f4-chngeafter = 'X'.
  INSERT ls_f4 INTO TABLE lt_f4.
 
  CREATE OBJECT lv_event_receiver.
  SET HANDLER lv_event_receiver->handle_f4 FOR tem_grid.
 
  CALL METHOD tem_grid->register_f4_for_fields
    EXPORTING
      it_f4 = lt_f4[].
 
ENDFORM.                    "FM_BUTTON
4. 定义alv-status子程序
*&---------------------------------------------------------------------*
*&      Form  PF_STATUS_SET
*&---------------------------------------------------------------------*
*       status设定
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
FORM pf_status_set USING rt_extab TYPE slis_t_extab.

  SET PF-STATUS 'STATUS_ALV'.

ENDFORM.                    "PF_STATUS_SET
5. 定义alv-comman子程序
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       USER COMMMAND
*----------------------------------------------------------------------*
*      -->P_UCOMM      text
*      -->PS_SELFIELD  text
*----------------------------------------------------------------------*
FORM user_command USING ucomm    LIKE sy-ucomm
                        selfield TYPE slis_selfield.
 
  DATA l_grid TYPE REF TO cl_gui_alv_grid.
*------------将ALV上修改的内容保存到内表---------------------------------*
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = l_grid.
  CALL METHOD l_grid->check_changed_data.
 
 
  CASE ucomm.
*   [行项目追加]按钮
    WHEN 'CREATE'.
*     多频次包装基础表
      IF p_mmvds = 'X'.
*       添加行项目(多频次包装基础表)
        PERFORM cteate_line_mmvds.
 
*     窗口时间基础表
      ELSEIF p_detail = 'X'.
*       添加行项目(窗口时间基础表)
        PERFORM cteate_line_dtdetail.
 
*     供应商供货信息基础表
      ELSEIF p_vds = 'X'.
*       添加行项目(供应商供货信息基础表)
        PERFORM cteate_line_vds.
 
      ENDIF.
 
      selfield-refresh = 'X'.      "将更新后内表的数据反馈到alv画面,自动刷新功能
 
*   [行项目删除]按钮
    WHEN 'DELETE'.
*     多频次包装基础表
      IF p_mmvds = 'X'.
*       删除行项目(多频次包装基础表)
        PERFORM delete_line_mmvds.
 
*     窗口时间基础表
      ELSEIF p_detail = 'X'.
*       删除行项目(窗口时间基础表)
        PERFORM delete_line_dtdetail.
 
*     供应商供货信息基础表
      ELSEIF p_vds = 'X'.
*       删除行项目(供应商供货信息基础表)
        PERFORM delete_line_vds.
 
      ENDIF.
 
      selfield-refresh = 'X'. "将更新后内表的数据反馈到alv画面,自动刷新功能
 
*   [保存]按钮
    WHEN 'SAVE'.
*     多频次包装基础表
      IF p_mmvds = 'X'.
*       保存处理(多频次包装基础表)
        PERFORM save_data_mmvds.
 
*     窗口时间基础表
      ELSEIF p_detail = 'X'.
*       保存处理(窗口时间基础表)
        PERFORM save_data_dtdetail.
 
*     供应商供货信息基础表
      ELSEIF p_vds = 'X'.
*       保存处理(供应商供货信息基础表)
        PERFORM save_data_vds.
 
      ENDIF.
 
  ENDCASE.
 
*------------将ALV上修改的内容保存到内表---------------------------------*
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = l_grid.
  CALL METHOD l_grid->check_changed_data.
 
ENDFORM.                    "USER_COMMAND
6. 其他子程序定义
*&---------------------------------------------------------------------*
*&      Form  REFRESH_TABLE_ALV
*&---------------------------------------------------------------------*
*       设置后,alv稳定刷新
*----------------------------------------------------------------------*
FORM refresh_table_alv .
  DATA: stbl        TYPE lvc_s_stbl.
*
  stbl-row = 'X'." 基于行的稳定刷新
  stbl-col = 'X'." 基于列稳定刷新
  CALL METHOD tem_grid->refresh_table_display
    EXPORTING
      is_stable = stbl.

ENDFORM.                    " REFRESH_TABLE_ALV

*&---------------------------------------------------------------------*
*&      Form  F4_HELP_ZSJCS
*&---------------------------------------------------------------------*
*       窗口时间参数的自定义f4检索帮助
*----------------------------------------------------------------------*
FORM f4_help_zsjcs USING p_fieldname  TYPE lvc_fname
                         p_row_no     TYPE lvc_s_roid.
  DATA: lt_dtdetail TYPE STANDARD TABLE OF ztpp_dtdetail,
        lt_return   TYPE STANDARD TABLE OF ddshretval,
        ls_return   TYPE ddshretval.
 
  CLEAR gw_vds.
  READ TABLE gt_vds INTO gw_vds INDEX p_row_no-row_id.
 
  IF p_fieldname = 'ZSJCS'.
 
    SELECT *
      INTO TABLE lt_dtdetail
      FROM ztpp_dtdetail
     WHERE werks = gw_vds-werks.
 
    SORT lt_dtdetail BY werks zsjcs.
    DELETE ADJACENT DUPLICATES FROM lt_dtdetail
                          COMPARING werks zsjcs.
 
  ENDIF.
 
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield         = 'ZSJCS'            "lt内表里面的字段
      dynpprog         = sy-repid
      dynpnr           = sy-dynnr
      dynprofield      = 'ZSJCS'            "画面上绑定字段
      value_org        = 'S'
      callback_program = sy-repid
    TABLES
      value_tab        = lt_dtdetail        "需要显示帮助的值内表
      return_tab       = lt_return          "返回值
    EXCEPTIONS
      parameter_error  = 1
      no_values_found  = 2
      OTHERS           = 3.
 
 
  IF sy-subrc = 0.
    READ TABLE lt_return INTO ls_return INDEX 1.
    gw_vds-zsjcs = ls_return-fieldval.
    MODIFY gt_vds FROM gw_vds INDEX p_row_no-row_id
                       TRANSPORTING zsjcs.
  ENDIF.
 
ENDFORM.                    " F4_HELP_ZSJCS

 

标签:function,OO,f4,PERFORM,alv,grid,ls,ALV,event
From: https://www.cnblogs.com/wangzuoer/p/18125345

相关文章

  • 【SpringBoot + Tomcat】【二】请求到达后端服务进程后的处理过程-连接的处理细节
    1 前言上节的后半部分,由于忙项目的事情去了,收尾的有点潦草,我们这节再继续。上节我们的思路是先简单回顾了下,SpringBoot启动和创建Tomcat的时机,然后我们还主要看了下连接器Connector的创建已经启动过程。连接器本身很重要,因为它就像一个港口或者一个枢纽,连接着客户端和服......
  • 【Python系列】Jupyter Notebook 中执行 Shell 脚本的方法
    ......
  • OO ALV 强制触发 data_change事件
    参考博客https://community.sap.com/t5/application-development-blog-posts/trigger-alv-data-change-event-manual/ba-p/13003658https://blog.csdn.net/qq_40977705/article/details/104599677https://blog.csdn.net/qq_40977705/article/details/108880331data_change写l......
  • 快速集成和使用 drools 规则引擎
    规则引擎技术的主要思想是将应用程序中的业务规则分离出来,业务规则不再以程序代码的形式驻留在系统中,而是存储在独立的文件或者数据库中,完全独立于程序。业务人员可以像管理数据一样对业务规则进行管理。业务规则在程序运行时被加载到规则引擎中供应用系统调用。drools是当前比......
  • CMD 批处理脚本自定义 UEFI 启动项,您需要使用 bcdedit 命令来操作 Windows 引导管理器
    CMD批处理脚本自定义UEFI启动项,您需要使用bcdedit命令来操作Windows引导管理器(BootConfigurationData,BCD)。BCD存储了计算机启动时所需的信息,包括可用的操作系统和启动选项。以下是一个简单的示例,演示如何使用CMD批处理脚本添加、修改和删除启动项:1.添加启动项要添......
  • 解决hadoop的namenode和datanode结点启动不起来的问题
    首先介绍一下本人的情况:我的虚拟机最开始是可以启动的,后来删除了主节点,重新创建了一个主节点,并保持相同的主机名,并把从结点上的hadoop打包发到了主节点(前提已经弄好ssh和相关映射)tar-zcf~/hadoop.master.tar.gz./hadoop//将hadoop目录下的内容打包复制到~/hadoop.master.ta......
  • Redis Sentinel 哨兵模式 故障转移失败 -failover-abort-no-good-slave master mymast
    根据网上的解决方案:1.我核对了sentinel.config和redis.configbind绑定的端口。2.三台redismasterauth都设置了密码3.sentinel.config的sentinelmonitormymaster和sentinelauth-passmymaster也没有错。但在我测试主从复制的时候,发现主从主机无法相连,我在网上找的解决......
  • OOP 面向对象
    转载自https://zhuanlan.zhihu.com/p/524264177并做部分内容上的补充和修改在前一章,我们学习了抽象数据类型(ADT)理论,这一章,我们学习ADT的具体实现技术:OOP类与对象什么是对象?对象都有两个特征:状态(states)和行为(behaviors)我们可以从真实世界中的对象来理解这两个特征:......
  • 基于JAVA Springboot + Vue 前端后分离 实现【考研资讯平台】(内附设计LW + PPT+ 源码
    项目名称项目名称:考研资讯平台项目技术栈该项目采用了以下核心技术栈:后端框架/库:SpringBoot数据库:MySQL前端技术:Vue.js(前后端分离)项目展示5.1学生前台功能模块5.1.2首页在系统首页可以查看以下内容:首页考研资讯报考指南资料信息论坛信息我的跳转到后台购物......
  • 基于JAVA Springboot + Vue 前端后分离 实现【教师人事档案管理系统】(内附设计LW + PP
    项目名称项目名称:教师人事档案管理系统项目技术栈该项目采用了以下核心技术栈:后端框架/库:Java数据库:MySQL前端技术:Vue.js(前后端分离)开发工具:Eclipse项目展示5.1前台功能模块前台首页在教师人事档案管理系统首页可以查看以下内容:首页培训信息系统公告个人中心......