ALV DataChange EVENT
在CX项目中,根据需求,自定义一个表,维护供应商的银行账号信息,当输入供应商编号时,自动在供应商名称列里自动填写供应商名称,用到了ALV DataChange 事件 ,下面是源代码:
*&---------------------------------------------------------------------*
*& REPORT ZMM_LIFNR_BANK
*&
*&---------------------------------------------------------------------*
*& PROGRAM NAME : ZMM_LIFNR_BANK
*& DESCRIPTION :
*& AUTHOR :
*& DATE WRITTEN :
*& TCODE :
*& NOTE :
*&---------------------------------------------------------------------*
REPORT ZMM_LIFNR_BANK.
*INCLUDE ZMMLIFNRBANKTOP.
TABLES:ZXK001.
TYPE-POOLS:SLIS.
TYPES BEGIN OF TY_ITAB.
TYPES CHK.
INCLUDE TYPE ZXK001.
TYPES END OF TY_ITAB.
DATA: IT_ZXK001 TYPE TABLE OF TY_ITAB WITH HEADER LINE.
DATA: WA_IT_ZXK001 TYPE TY_ITAB.
DATA: ITZXK001 LIKE TABLE OF ZXK001 WITH HEADER LINE.
DATA: GT_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE.
DATA: GC_GLAY TYPE LVC_S_GLAY.
DATA: GS_LAYOUT TYPE LVC_S_LAYO, "SLIS_LAYOUT_ALV,
WK_REPID LIKE SY-REPID.
DATA GS_GRID TYPE LVC_S_GLAY.
DATA TEM_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA GT_EVENTS TYPE SLIS_T_EVENT.
DATA GS_EVENTS LIKE LINE OF GT_EVENTS.
*----------------------------------------------------------------------*
* 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_ONF4 "F4
FOR EVENT ONF4 OF CL_GUI_ALV_GRID
IMPORTING E_FIELDNAME ES_ROW_NO ER_EVENT_DATA.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
DATA GT_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER .
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-B01.
SELECT-OPTIONS:
S_LIFNR FOR ZXK001-LIFNR.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.
*&---------------------------------------------------------------------*
*& FORM GET_DATA
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
FORM GET_DATA.
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_ZXK001 FROM ZXK001 WHERE LIFNR IN S_LIFNR.
ENDFORM. "GET_DATA
*&---------------------------------------------------------------------*
*& FORM DISPLAY_DATA
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .
DEFINE FILL_ALV.
CLEAR GT_FIELDCAT.
GT_FIELDCAT-FIELDNAME = &1.
GT_FIELDCAT-SCRTEXT_M = &2 .
* GT_FIELDCAT-OUTPUTLEN = &3.
GT_FIELDCAT-NO_ZERO = &3.
GT_FIELDCAT-DECIMALS_O = &4.
APPEND GT_FIELDCAT.
END-OF-DEFINITION.
FILL_ALV 'LIFNR' '供应商编号 ' '' ''.
FILL_ALV 'NAME1' '供应商名称 ' '' ''.
FILL_ALV 'BANKN' '开户银行 ' ' ' ''.
FILL_ALV 'IBAN' '银行账号 ' '' ''.
LOOP AT GT_FIELDCAT WHERE FIELDNAME = 'LIFNR'
OR FIELDNAME = 'BANKN'
OR FIELDNAME = 'NAME1'
OR FIELDNAME = 'IBAN'.
IF GT_FIELDCAT-FIELDNAME <> 'NAME1'.
GT_FIELDCAT-EDIT = 'X'.
ENDIF.
IF GT_FIELDCAT-FIELDNAME = 'NAME1'.
GT_FIELDCAT-OUTPUTLEN = '30'.
ENDIF.
IF GT_FIELDCAT-FIELDNAME = 'LIFNR'.
* GT_FIELDCAT-REF_FIELD = 'LIFNR'.
* GT_FIELDCAT-REF_TABLE = 'LFA1'.
GT_FIELDCAT-OUTPUTLEN = '20'.
ENDIF.
IF GT_FIELDCAT-FIELDNAME = 'BANKN'.
GT_FIELDCAT-REF_FIELD = 'BANKN'.
GT_FIELDCAT-REF_TABLE = 'TIBAN'.
GT_FIELDCAT-OUTPUTLEN = '35'.
ENDIF.
IF GT_FIELDCAT-FIELDNAME = 'IBAN'.
GT_FIELDCAT-REF_FIELD = 'IBAN'.
GT_FIELDCAT-REF_TABLE = 'TIBAN'.
GT_FIELDCAT-OUTPUTLEN = '34'.
ENDIF.
MODIFY GT_FIELDCAT.
ENDLOOP.
GS_LAYOUT-STYLEFNAME = 'FSTYLE'.
GS_LAYOUT-ZEBRA = 'X'.
* GS_LAYOUT-CWIDTH_OPT = 'X'.
GS_LAYOUT-BOX_FNAME = 'CHK'.
GS_GRID-EDT_CLL_CB = 'X'.
* **************定义事件FORM名称*********************
GS_EVENTS-NAME = 'CALLER_EXIT'.
GS_EVENTS-FORM = 'CALLER_EXIT'.
APPEND GS_EVENTS TO GT_EVENTS.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
* I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
IT_FIELDCAT_LVC = GT_FIELDCAT[]
I_GRID_SETTINGS = GS_GRID
IS_LAYOUT_LVC = GS_LAYOUT
I_SAVE = 'X'
IT_EVENTS = GT_EVENTS
TABLES
T_OUTTAB = IT_ZXK001.
ENDFORM. " DISPLAY_DATA
*&---------------------------------------------------------------------*
*& FORM SET_PF_STATUS
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->EXTAB TEXT
*----------------------------------------------------------------------*
FORM SET_PF_STATUS USING EXTAB TYPE SLIS_T_EXTAB. "#EC CALLED
SET PF-STATUS '1000' .
ENDFORM. "WHOLE_TOOLBAR
*&---------------------------------------------------------------------*
*& FORM USER_COMMAND
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->RF_UCOMM TEXT
* -->RS TEXT
*----------------------------------------------------------------------*
FORM USER_COMMAND USING RF_UCOMM LIKE SY-UCOMM
RS TYPE SLIS_SELFIELD.
DATA:P_COUNT TYPE I.
DATA: P_ANSWER(1).
DATA: LR_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA LV_ANSWER.
DATA LS_STYLEROW TYPE LVC_S_STYL .
DATA LT_STYLETAB TYPE LVC_T_STYL .
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LR_GRID.
CALL METHOD LR_GRID->CHECK_CHANGED_DATA.
RS-REFRESH = 'X'. "自动刷新
CASE RF_UCOMM.
WHEN '&NEW'.
IT_ZXK001-LIFNR = ''.
IT_ZXK001-NAME1 = ''.
IT_ZXK001-BANKN = ''.
IT_ZXK001-IBAN = ''.
APPEND IT_ZXK001.
CLEAR IT_ZXK001.
WHEN '&DEL'.
CLEAR P_COUNT.
LOOP AT IT_ZXK001 WHERE CHK = 'X'.
P_COUNT = 1.
EXIT.
ENDLOOP.
IF P_COUNT <= 0.
MESSAGE '请选择要删除的数据!' TYPE 'I'.
RETURN.
ELSE.
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
TEXTLINE1 = '确认要删除所选记录吗?'
TITEL = '确认提示'
CANCEL_DISPLAY = ''
IMPORTING
ANSWER = P_ANSWER.
CHECK P_ANSWER = 'J'.
IF P_ANSWER = 'J'.
LOOP AT IT_ZXK001 WHERE CHK = 'X'.
DELETE FROM ZXK001 WHERE LIFNR = IT_ZXK001-LIFNR.
DELETE IT_ZXK001.
ENDLOOP.
ENDIF.
ENDIF.
WHEN '&SAVE'.
CLEAR P_COUNT.
LOOP AT IT_ZXK001 WHERE LIFNR = ''.
P_COUNT = 1.
EXIT.
ENDLOOP.
IF P_COUNT > 0.
MESSAGE '供应商字段不能为空!' TYPE 'I'.
RETURN.
ELSE.
REFRESH ITZXK001.
CLEAR ITZXK001.
LOOP AT IT_ZXK001.
MOVE-CORRESPONDING IT_ZXK001 TO ITZXK001.
APPEND ITZXK001.
CLEAR ITZXK001.
ENDLOOP.
MODIFY ZXK001 FROM TABLE ITZXK001.
IF SY-SUBRC EQ 0.
COMMIT WORK.
MESSAGE S000(ZMM001).
ELSE.
ROLLBACK WORK.
MESSAGE S001(ZMM001).
ENDIF.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& FORM CALLER_EXIT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->E_GRID TEXT
*----------------------------------------------------------------------*
FORM CALLER_EXIT USING E_GRID TYPE SLIS_DATA_CALLER_EXIT.
DATA: L_FIELD TYPE LVC_FNAME,
LT_F4 TYPE LVC_T_F4,
LS_F4 TYPE LVC_S_F4.
* LS_F4-FIELDNAME = 'UMSKZ'.
* LS_F4-REGISTER = 'X'.
"LS_F4-GETBEFORE = 'X'. "打'X'会在弹出窗体之前先刷新ALV数据
"LS_F4-CHNGEAFTER = 'X'. "打'X'会在关闭窗体之后刷新ALV数据
"LS_F4-INTERNAL = ''.
INSERT LS_F4 INTO TABLE LT_F4.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = TEM_GRID.
CALL METHOD TEM_GRID->REGISTER_EDIT_EVENT "注册GRID事件
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER"事件:回车
EXCEPTIONS
ERROR = 1
OTHERS = 2.
* CALL METHOD TEM_GRID->REGISTER_F4_FOR_FIELDS
* EXPORTING
* IT_F4 = LT_F4.
CREATE OBJECT GT_EVENT_RECEIVER.
SET HANDLER GT_EVENT_RECEIVER->HANDLE_MODIFY FOR TEM_GRID.
SET HANDLER GT_EVENT_RECEIVER->HANDLE_ONF4 FOR TEM_GRID.
ENDFORM. "CALLER_EXIT
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION. "实现类 处理回车事件
METHOD HANDLE_MODIFY.
DATA LS_STYLEROW TYPE LVC_S_STYL .
DATA LT_STYLETAB TYPE LVC_T_STYL .
DATA STBL TYPE LVC_S_STBL.
LOOP AT IT_ZXK001 INTO WA_IT_ZXK001.
SELECT SINGLE
NAME1
INTO WA_IT_ZXK001-NAME1
FROM LFA1
WHERE LIFNR = WA_IT_ZXK001-LIFNR.
MODIFY IT_ZXK001 FROM WA_IT_ZXK001.
ENDLOOP.
STBL-ROW = 'X'." 基于行的稳定刷新
STBL-COL = 'X'." 基于列稳定刷新
CALL METHOD TEM_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = STBL.
ENDMETHOD. "HANDLE_MODIFY
METHOD HANDLE_ONF4.
DATA :PT_RET TYPE TABLE OF DDSHRETVAL ,
PS_RET TYPE DDSHRETVAL ,
LS_MODI TYPE LVC_S_MODI.
FIELD-SYMBOLS <MODTAB> TYPE LVC_T_MODI.
* SELECT SHBKZ AS UMSKZ
* LTEXT
* INTO TABLE ITHELP
* FROM T074T
* WHERE KOART = 'D'
* AND SPRAS = '1'.
*
* CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
* EXPORTING
* RETFIELD = 'UMSKZ' "内表的关键字段名
* VALUE_ORG = 'S' "'S'
* DYNPPROG = SY-REPID "文本框PROGRAM
* DYNPNR = SY-DYNNR "文本框所在屏幕
* DYNPROFIELD = '特殊总账标识' "文本框名
* WINDOW_TITLE = '标题' "窗体标题
* TABLES
* VALUE_TAB = ITHELP "内表
* "FIELD_TAB = T_FIELD
* RETURN_TAB = PT_RET "返回选择的数据
* EXCEPTIONS
* PARAMETER_ERROR = 1
* NO_VALUES_FOUND = 2
* OTHERS = 3.
** 处理 PT_RET 返回的数据,更新ALV CELL即可
READ TABLE PT_RET INTO PS_RET INDEX 1 .
IF SY-SUBRC = 0.
LS_MODI-ROW_ID = ES_ROW_NO-ROW_ID.
LS_MODI-FIELDNAME = E_FIELDNAME.
LS_MODI-VALUE = PS_RET-FIELDVAL.
ASSIGN ER_EVENT_DATA->M_DATA->* TO <MODTAB>.
APPEND LS_MODI TO <MODTAB>.
ENDIF.
ER_EVENT_DATA->M_EVENT_HANDLED = 'X'. "通知系统搜索事件处理完毕,停止调用系统标准的SEARCH HELP。
ENDMETHOD. "HANDLE_ONF4
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
ALV DataChange EVENT的更多相关文章
- SAP Grid control( ALV Grid 列表 自定义 按钮)
ALV 列表和按钮 效果 源代码 PROGRAM bcalvc_tb_menu_with_def_but. *&&&&&&&&& ...
- Model-View-Controller Explained in C++
The Permanent URL is: Model-View-Controller Explained in C++. The Model-View-Controller (MVC) is not ...
- ALV TREE中双击触发PAI事件的方法
用事件类实现双击事件,实例化后使用set handler注册到ALV对象.斜体部分为事件方法的具体实现. 代码如下 CLASS lcl_tree_event_receiver DEFINITION. ...
- 00 alv抬头等
*&---------------------------------------------------------------------* *& Report ZHJ_TEST0 ...
- ABAP ALV单个单元格状态编辑
*&---------------------------------------------------------------------* *& Report ZPPR0024 ...
- SAP ALV显示并打印(非OO方式)
*&---------------------------------------------------------------------* *& Report Z_SD_CPF ...
- SAP ALV OO 选择行打印
&---------------------------------------------------------------------* *& Report ZSDF001 * ...
- ALV用例大全
一.ALV介绍 The ALV Grid Control (ALV = SAP List Viewer)是一个显示列表的灵活的工具,它提供了基本功能的列表操作,也可以通过自定义来进行增强,因此可以允 ...
- ALV详解:OO ALV
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
随机推荐
- hibernate.cfg.xml文件的配置模板和不同数据库的配置參数
(1)hibernate.cfg.xml文件的配置模板 <?xml version="1.0" encoding="UTF-8"?> <!DO ...
- All consistent reads within the same transaction read the snapshot established by the first read.
Session 1: Session 2: mysql> show variables like '%tx_isolation%'; +---------------+------------- ...
- 由一道淘宝面试题到False sharing问题
今天在看淘宝之前的一道面试题目,内容是 在高性能服务器的代码中经常会看到类似这样的代码: typedef union { erts_smp_rwmtx_t rwmtx; byte cache_line ...
- HDU 1007 近期点对
分治法求近期点对 递归将点不断分成小组.计算最短距离.此时的最短距离不过两点都属两块的某一块(这里的切割点是mid点). 还须要考虑两点分属两块的情况. 这时对于选点则把范围缩小到了以mid为中心. ...
- CentOS6.5与window远程桌面配置
VNC配置手冊 一.服务端 VNC(Virtual Network Computing)是一种Linux系统(或者BSD.Mac等)下经常使用的图形化远程管理工具.使用的是RFB协议.VNC跟SSH一 ...
- Codeforces325-B(二分搜索)
题目:B. Stadium and Games 分析:问题可以转化为下面的等式求解问题: 由于n在10^18范围内,所以k的范围是从0到63即可,这样就可以枚举k,二分m,然后所有符合条件的就是答案了 ...
- [Cocos2d-x]博客推荐
推荐一下大神们的博客: JackyStudio: http://blog.csdn.net/jackyvincefu/article/category/1591201/3 老G的小屋: http:// ...
- kill命令"-1"这个参数到底是杀进程还是reload?(转)
kill-1:重新读取一次参数的配置文件 (类似 reload) 这句话给我的感觉是把进程杀掉后重启进程,即 reload.而我查了下 man kill,-1 对应的 signal 是 SIGHUP, ...
- jquery中实现全选按钮
<html> <head> <script type='text/javascript' src='js/jquery-1.5.1.js'></scr ...
- java特权制度设计篇
数据库表设计 1.1.1. 模块管理(jk_module) 项 类型 说明 id long 就是数据库记录idx号 name string 模块名称 orderid int 排序id 由小到大显 ...