当前位置:首页 > IT技术 > 其他好文 > 正文

20170228 ALV method中用E消息,会退出到初始界面;STOP 会dump;
2017-02-28 13:41:18

再回车就处理界面了,

 

所以,Handel_data_change 做数据检查时,如果需要报错要用到,

CALL METHOD er_data_changed->add_protocol_entry
            EXPORTING
              i_msgid     = 'Z_BH1'
              i_msgno     = '000'
              i_msgty     = 'E'
              i_msgv1     = '你输入的起始日期大于结束日期!'
              i_msgv2     = ''
              i_msgv3     = ''
              i_fieldname = ls_modi-fieldname
              i_row_id    = ls_modi-row_id.

可参考

*&监听修改
      HANDLE_DATA_CHANGED
        FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
            IMPORTING ER_DATA_CHANGED.

*&方法实施:
METHOD handle_data_changed.

    DATA: ls_modi TYPE lvc_s_modi.
    DATA: lv_valid TYPE c.

    DATA: lt_lvc_t_modi TYPE lvc_t_modi .
    DATA: ls_lvc_t_modi TYPE lvc_s_modi ,
          l_matnr       TYPE matnr,
          l_datum       TYPE datum,
          l_datab       TYPE datum,
          lv_flag(1).
*    CLEAR:LV_FLAG,L_DMBTR,L_CTCOD.
    LOOP AT er_data_changed->mt_good_cells INTO ls_modi.
      IF ls_modi-fieldname = 'MATNR'.
*****************获取CELL值
        CALL METHOD er_data_changed->get_cell_value
          EXPORTING
            i_row_id    = ls_modi-row_id
            i_fieldname = ls_modi-fieldname
          IMPORTING
            e_value     = l_matnr.
        IF NOT l_matnr IS INITIAL.
          SELECT SINGLE matnr  INTO l_matnr FROM mara
                          WHERE matnr = l_matnr.
          IF sy-subrc = 0.
            SELECT SINGLE maktx INTO wa_out-maktx FROM makt
                               WHERE matnr = l_matnr
                                 AND spras = sy-langu.
            MODIFY gt_out FROM wa_out INDEX ls_modi-row_id TRANSPORTING maktx.
            CLEAR: ls_lvc_t_modi,lt_lvc_t_modi[].
            ls_lvc_t_modi-row_id = ls_modi-row_id.  "自然数
            ls_lvc_t_modi-fieldname = 'MAKTX'.   "内部表字段的字段名称
            ls_lvc_t_modi-value = wa_out-maktx."  单元格内容
            ls_lvc_t_modi-tabix  = ls_modi-row_id."自然数
            APPEND ls_lvc_t_modi TO lt_lvc_t_modi.
            CLEAR ls_lvc_t_modi.
            CALL METHOD g_grid->set_delta_cells
              EXPORTING
                it_delta_cells = lt_lvc_t_modi[].
          ELSE.
            lv_flag = 'X'.
*            CALL METHOD ER_DATA_CHANGED->ADD_PROTOCOL_ENTRY
*              EXPORTING
*                I_MSGID     = 'Z_BH1'
*                I_MSGNO     = '000'
*                I_MSGTY     = 'E'
*                I_MSGV1     = '你输入的商品不存在!'
*                I_MSGV2     = ''
*                I_MSGV3     = ''
*                I_FIELDNAME = LS_MODI-FIELDNAME
*                I_ROW_ID    = LS_MODI-ROW_ID.

          ENDIF.
        ENDIF.
      ENDIF.

      IF ls_modi-fieldname = 'DATBI'.
        CALL METHOD er_data_changed->get_cell_value
          EXPORTING
            i_row_id    = ls_modi-row_id
            i_fieldname = ls_modi-fieldname
          IMPORTING
            e_value     = l_datum.

        READ TABLE gt_out INTO wa_out INDEX ls_modi-row_id.
        l_datab  = wa_out-datab.

        IF l_datum < l_datab.
          lv_flag = 'X'.
          CALL METHOD er_data_changed->add_protocol_entry
            EXPORTING
              i_msgid     = 'Z_BH1'
              i_msgno     = '000'
              i_msgty     = 'E'
              i_msgv1     = '你输入的起始日期大于结束日期!'
              i_msgv2     = ''
              i_msgv3     = ''
              i_fieldname = ls_modi-fieldname
              i_row_id    = ls_modi-row_id.
        ENDIF.

      ENDIF.

    ENDLOOP.

****************显示错误消息
*    IF LV_FLAG = 'X'.
*      CALL METHOD ER_DATA_CHANGED->DISPLAY_PROTOCOL.
*    ENDIF.

  ENDMETHOD.                    "HANDLE_DATA_CHANGED

 

本文摘自 :https://www.cnblogs.com/

开通会员,享受整站包年服务立即开通 >