OO ALV 強制觸發 data_change事件

Lan_dev發表於2024-04-09

參考部落格

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/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.

  

相關文章