OO ALV 强制触发 data_change事件

参考博客

https://community.sap.com/t5/application-development-blog-posts/trigger-alv-data-change-event-manual/ba-p/13003658

https://blog.csdn.net/qq_40977705/article/details/104599677

https://blog.csdn.net/qq_40977705/article/details/108880331

data_change 写log

相关类 CL_GUI_ALV_GRID ,CL_ALV_CHANGED_DATA_PROTOCOL
事件 DATA_CHANGED
首先PROTOCOL只能写在DATA CHANGED事件里面,在其它地方是无效的,所以在需要PROTOCOL的时候,一般需要强制的去触发DATA_CHANGED事件(比如点保存按钮的时候,强制触发DATA_CHANGED)

一 强制触发DATA_CHANGED的写法

  CALL METHOD GO_ALVGRID_RIGHT->IF_CACHED_PROP~SET_PROP 
        EXPORTING
          PROPNAME           = 'GridModified' "单元格假修改
          PROPVALUE          = '1'
        EXCEPTIONS
          PROP_NOT_FOUND     = 1
          INVALID_NAME       = 2
          ERROR_SET_PROPERTY = 3
          OTHERS             = 4
              .
      IF SY-SUBRC <> 0.
*       Implement suitable error handling here
      ENDIF.
      CALL METHOD GO_ALVGRID_RIGHT->CHECK_CHANGED_DATA
*        IMPORTING
*          E_VALID   =
*        CHANGING
*          C_REFRESH = 'X'
          .

 二、添加protocol,调用方法ADD_PROTOCOL_ENTRY,消息类可以在SE91去创建,然后加在这里

FORM FRM_HANDLE_DATA_CHANGED USING PR_DATA_CHANGED
                              TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL
                              P_UCOMM TYPE SY-UCOMM.
 
  DATA LS_MODCELL TYPE LVC_S_MODI .
  READ TABLE PR_DATA_CHANGED->MT_MOD_CELLS INTO LS_MODCELL INDEX 1 .
  IF SY-UCOMM EQ GC_SAVE.
   LOOP AT GT_TABLE_RIGHT WHERE ZPJBH IS INITIAL OR ZWRBTR IS INITIAL
                          AND ZXZ EQ GC_X  .
     IF GT_TABLE_RIGHT-ZPJBH  IS INITIAL  .
 
        CALL METHOD PR_DATA_CHANGED->ADD_PROTOCOL_ENTRY
         EXPORTING
            I_MSGID     = 'ZSSFDZ'
            I_MSGTY     = 'E'
            I_MSGNO     = '000'
*            I_MSGV1     = 'ZPJBH is required'
*            I_MSGV2     =
*            I_MSGV3     =
*            I_MSGV4     =
            I_FIELDNAME = 'ZPJBH'
*            I_ROW_ID    =
             I_TABIX     = SY-TABIX
        .
      ENDIF.
      IF  GT_TABLE_RIGHT-ZWRBTR IS INITIAL.
 
        CALL METHOD PR_DATA_CHANGED->ADD_PROTOCOL_ENTRY
          EXPORTING
            I_MSGID     = 'ZSSFDZ'
            I_MSGTY     = 'E'
            I_MSGNO     = '001'
*            I_MSGV1     =
*            I_MSGV2     =
*            I_MSGV3     =
*            I_MSGV4     =
            I_FIELDNAME = 'ZWRBTR'
*            I_ROW_ID    =
             I_TABIX     = SY-TABIX
            .
       ENDIF.
     ENDLOOP.
   ENDIF.
  CALL METHOD PR_DATA_CHANGED->DISPLAY_PROTOCOL
*  EXPORTING
*    I_CONTAINER        =
*    I_DISPLAY_TOOLBAR  =
*    I_OPTIMIZE_COLUMNS =
    .
ENDFORM.

 

  

posted @ 2024-04-09 23:14  Lan_dev  阅读(151)  评论(0编辑  收藏  举报