TEST ALV in SAP [BCALV_TEST_GRID_EDITABLE]

这是一个关于在SAP中处理ALV(Advanced List Viewer)表格编辑事件的示例代码,包括双击事件、热点点击事件、按钮点击事件和数据变化事件的响应函数。代码展示了如何捕获并处理这些交互事件,如信息弹出框的显示和事件日志记录。
摘要由CSDN通过智能技术生成

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L1S31 { font-style: italic; color: #808080; } .L1S32 { color: #3399FF; } .L1S33 { color: #4DA619; } .L1S52 { color: #0000FF; } *&---------------------------------------------------------------------*
*& Report  BCALV_TEST_GRID_EDITABLE                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*
report  bcalv_test_grid_editable.

types: g_ty_s_sflight type alv_t_t2.

constants: con_sflight type lvc_fname value 'ALV_T_T2'.

*----------------------------------------------------------------------*
* DATA                                                                 *
*----------------------------------------------------------------------*
include <icon>.
include <symbol>.

class lcl_events_d0100 definition deferred.

types: g_ty_t_icon  type standard table of icon,
       g_ty_t_icont type standard table of icont,

       begin of g_ty_s_onf4,
         register        type char1,
         get_before      type char1,
         change_after    type char1,
         internal_format type char1,
       end   of g_ty_s_onf4,

       begin of g_ty_s_test,
         select_amount     type i,
         only_db_info      type char1,
         no_info_popup     type char1,
         info_popup_once   type char1,
         events_info_popup type lvc_fname occurs 0,
         edit_type         type i,
         edit_mode         type i,
         edit_event        type i,
         edit_fields       type lvc_fname occurs 0,
         no_row_ins        type char1,
         no_row_move       type char1,
         onf4              type g_ty_s_onf4,
         onf4_fields       type lvc_fname occurs 0,
         excp_group        type char1,
         excp_amount       type i,
         excp_condense     type char1,
         excp_led          type char1,
         layo_selection    type char1,
         layo_no_rowmark   type char1,
         bypassing_buffer  type char1,
         buffer_active     type char1,
       end   of g_ty_s_test,

       begin of g_ty_s_outtab.
include type g_ty_s_sflight.
types:   checkbox             type char1,
         box                  type char1,
         lights               type char1,
         handle_style         type lvc_t_styl,
         handle_hlink         type lvc_s_hype-handle,
         handle_drdn          type lvc_s_drop-handle,

         char(10)             type c,
         string               type string,
         int1                 type int1,
         int2                 type int2,
         int4                 type i,
         numc(10)             type n,
         dec(10)              type p decimals 2,
         fltp                 type f,
         dats                 type d,
         tims                 type t,
         icon                 type icon-id,
         icon_qinfo           type icon-name,
         symbol               type icon-id,
         hotspot              type string,
         hyperlink            type string,
         button               type string,
         dropdown_f4          type i,
       end   of g_ty_s_outtab,
       g_ty_t_outtab type table of g_ty_s_outtab.

constants: con_exit type sy-ucomm value 'EXIT',
           con_canc type sy-ucomm value 'CANC',
           con_back type sy-ucomm value 'BACK',
           con_save type sy-ucomm value 'SAVE',

           con_true     type char1 value 'X',

           con_on       type char1 value '1',
           con_off      type char1 value '0',

           con_edit_grid         type i value 1,
           con_edit_column       type i value 2,
           con_edit_cell         type i value 3,

           con_edit_mode_display type i value 1,
           con_edit_mode_change  type i value 2,

           con_edit_event_enter  type i value 1,
           con_edit_event_modify type i value 2.

data: g_field type lvc_s_fcat-fieldname.

data: g_okcode type sy-ucomm.

data: gs_test type g_ty_s_test.

data: gt_outtab            type g_ty_t_outtab,

      gr_container_d0100   type ref to cl_gui_custom_container,
      gr_grid_d0100        type ref to cl_gui_alv_grid,
      gr_events_d0100      type ref to lcl_events_d0100.

*---------------------------------------------------------------------*
*       CLASS lcl_events_d0100 DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
class lcl_events_d0100 definition.
  public section.
    methods:
    double_click         for event double_click
                         of cl_gui_alv_grid
                         importing e_row
                                   e_column
                                   es_row_no, "#EC CALLED

    hotspot_click        for event hotspot_click
                         of cl_gui_alv_grid
                         importing e_row_id
                                   e_column_id
                                   es_row_no, "#EC CALLED

    button_click         for event button_click
                         of cl_gui_alv_grid
                         importing es_col_id
                                   es_row_no, "#EC CALLED

    data_changed         for event data_changed
                         of cl_gui_alv_grid
                         importing er_data_changed
                                   e_onf4
                                   e_onf4_before
                                   e_onf4_after, "#EC CALLED

    data_changed_finished
                         for event data_changed_finished
                         of cl_gui_alv_grid. "#EC CALLED

endclass.                    "lcl_events_d0100 DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_events_d0100 IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
class lcl_events_d0100 implementation.
*---------------------------------------------------------------------*
*       METHOD double_click                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
  method double_click.
    perform d0100_event_double_click using e_row
                                           e_column.
  endmethod.                    "double_click

*---------------------------------------------------------------------*
*       METHOD hotspot_click                                          *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
  method hotspot_click.
    perform d0100_event_hotspot_click using e_row_id
                                            e_column_id.
  endmethod.                    "hotspot_click

*---------------------------------------------------------------------*
*       METHOD button_click                                           *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
  method button_click.
    perform d0100_event_button_click using es_col_id
                                           es_row_no.
  endmethod.                    "button_click

  method data_changed.
    perform d0100_event_data_changed using er_data_changed
                                           e_onf4
                                           e_onf4_before
                                           e_onf4_after.
  endmethod.                    "data_changed

  method data_changed_finished.
    perform d0100_event_data_changed_finis.
  endmethod.                    "data_changed_finished
endclass.                    "lcl_events_d0100 IMPLEMENTATION

*---------------------------------------------------------------------*
*       CLASS random DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
class random definition.
  public section.
    types:
      value(16type p decimals 0,
      numcv(15type n.
    constants:
      max type random=>value value 4294967295.
    class-methods:
*   computes a random natural number from the set {0, ..., random=>max}.
      number returning value(rval) type random=>value,
*   computes a random character from the set {A-Za-z0-9}
      c returning value(rval) type char01,
*   computes a random string consisting of "len" random characters
      string importing len type i
             returning value(rval) type string,
*   computes a date
      dats returning value(rval) type d,
*   computes a time
      time returning value(rval) type t,
*   computes a random numc from the set {low, ..., high}
      numc importing low type random=>numcv high type random=>numcv
        returning value(rval) type random=>numcv,
*   computes a random integer from the set {low, ..., high}
      i importing low type i high type i
        returning value(rval) type i,
*   computes a random integer from the set {low, ..., high}
      int2 importing low type int2 high type int2
           returning value(rval) type int2,
*   computes a random integer from the set {low, ..., high}
      int1 importing low type int1 high type int1
           returning value(rval) type int1,
*   computes a random float from the interval [low ; high]
      f importing low type f high type f
        returning value(rval) type f,
*   computes a random character from the set {A-F0-9}
      hex returning value(rval) type char01,
*   computes a random character from the set {0-1}
      x returning value(rval) type char01,
*   method "random=>class_constructor"
      class_constructor.

  private section.
    class-data:
*   precomputed maximal index (= string length - 1) of "random=>chars"
*   or of "random=>x_data".
      charsmax type i,
      xmax type i,
*   random number seed value.
*   (Used in method "random=>number".)
      seed type random=>value.

    constants:
*   characters for class-method "random=>hex"
      hex_data(100type c value 'ABCDEF' &
                                 '0123456789',
*   characters for class-method "random=>x"
      x_data(100type c value '01',
*   characters for class-metshod "random=>c"
      chars(100type c value 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' &
                              'abcdefghijklmnopqrstuvwxyz' &
                              '0123456789'.

endclass.                    "random DEFINITION

*---------------------------------------------------------------------*
*       CLASS random IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
class random implementation.
* implementation of the methods for randomizing the values
  method x.
    data: ri type i.
    ri = random=>i( low = 0  high = random=>xmax ).
    move x_data+ri(1to rval.
  endmethod.                    "x

  method hex.
    data: ri type i.
    ri = random=>i( low = 0  high = random=>charsmax ).
    move hex_data+ri(1to rval.
  endmethod.                    "hex

  method number.
    constants:
      a(3type p  value 67301,        " Coefficient
      c(1type p  value 1,            " Increment
      m(6type p  value 4294967296.   " Modulus 2**32
    random=>seed = ( a * random=>seed + c ) mod m.
    rval = random=>seed.
  endmethod.                    "number

  method c.
    data:
      ri type i.
    ri = random=>i( low = 0  high = random=>charsmax ).
    move chars+ri(1to rval.
  endmethod.                    "c

  method string.
    data:
      char(1type c.
    clear rval.
    do len times.
      char = random=>c( ).
      concatenate rval char into rval.
    enddo.
  endmethod.                    "string

  method dats.
    data: l_date      type sy-datum,
          l_day(2)    type n,
          l_month(2)  type n,
          l_year(4)   type n,
          l_value     type random=>numcv,
          l_low       type random=>numcv,
          l_high      type random=>numcv.

    l_year  = sy-datum+0(4).
    l_low   = l_year - 5.
    l_high  = l_year + 5.
    l_value = random=>numc( low = l_low high = l_high ).
    l_year  = l_value+11(4).

    l_value = random=>numc( low = 1 high = 12 ).
    l_month = l_value+13(2).
    case l_month.
      when 2.
        l_high = 28.
      when 4 or 6 or 9 or 11.
        l_high = 30.
      when others.
        l_high = 31.
    endcase.

    l_value = random=>numc( low = 1 high = l_high ).
    l_day   = l_value+13(2).

    l_date+0(4) = l_year.
    l_date+4(2) = l_month.
    l_date+6(2) = l_day.

    rval = l_date.
  endmethod.                    "dats

  method time.
    data

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值