二维码

[ooalv] ALV GRID中实现RadioButton单选按钮

Twilight发表于 2015-06-29 15:35zhongguomao 最后回复于 2017-08-25 09:04 [复制链接] 7721 2

ALV GRID中实现Checkbox复选框很简单,只需要将LVC_S_FCAT-CHECKBOX = 'X'即可,那么alv中radio Button单选怎么实现呢?

1、程序代码
  1. TYPE-POOLS:abap, slis.

  2. DATA: BEGIN OF gt_list OCCURS 0,
  3.         sel TYPE char4,
  4.         val TYPE i,
  5.       END OF gt_list.

  6. DATA: go_alv_grid TYPE REF TO cl_gui_alv_grid.
  7. *&---------------------------------------------------------------------*
  8. *& CLASS LCL_EVENT_RECEIVER DEFINITION
  9. *&---------------------------------------------------------------------*
  10. CLASS lcl_event_receiver DEFINITION.
  11.   PUBLIC SECTION.
  12.     CLASS-METHODS:
  13.       hotspot_click
  14.         FOR EVENT hotspot_click OF cl_gui_alv_grid
  15.           IMPORTING e_row_id
  16.                     e_column_id
  17.                     es_row_no.
  18. ENDCLASS.                    "LCL_EVENT_RECEIVER DEFINITION
  19. *&---------------------------------------------------------------------*
  20. *& CLASS LCL_EVENT_RECEIVER DEFINITION
  21. *&---------------------------------------------------------------------*
  22. CLASS lcl_event_receiver IMPLEMENTATION.
  23.   METHOD hotspot_click.
  24.     DATA: ls_list LIKE gt_list.
  25.     CLEAR ls_list.
  26.     READ TABLE gt_list INTO ls_list INDEX e_row_id.
  27.     IF gt_list-sel NE '@TB@'.
  28.       ls_list-sel = '@SR@'.
  29.       MODIFY gt_list FROM ls_list TRANSPORTING sel WHERE sel NE '@SR@'.
  30.       ls_list-sel = '@TB@'.
  31.       MODIFY gt_list FROM ls_list INDEX e_row_id TRANSPORTING sel .
  32.     ENDIF.
  33.     PERFORM frm_ref_alv.
  34.   ENDMETHOD.                    "HANDLE_ONF4
  35. ENDCLASS.                    "LCL_EVENT_RECEIVER IMPLEMENTATION
  36. *&---------------------------------------------------------------------*
  37. *&      START-OF-SELECTION
  38. *&---------------------------------------------------------------------*
  39. START-OF-SELECTION.
  40.   PERFORM frm_get_data.
  41.   PERFORM frm_dsp_data.
  42. *&---------------------------------------------------------------------*
  43. *&      Form  FRM_GET_DATA
  44. *&---------------------------------------------------------------------*
  45. FORM frm_get_data .
  46.   DO 10 TIMES.
  47.     IF sy-index = 1.
  48.       gt_list-sel = '@TB@'.
  49.     ELSE.
  50.       gt_list-sel = '@SR@'.
  51.     ENDIF.
  52.     gt_list-val = sy-index.
  53.     APPEND gt_list.
  54.   ENDDO.
  55. ENDFORM.                    " FRM_GET_DATA
  56. *&---------------------------------------------------------------------*
  57. *&      Form  FRM_DSP_DATA
  58. *&---------------------------------------------------------------------*
  59. FORM frm_dsp_data .
  60.   DATA: ls_layo  TYPE lvc_s_layo,
  61.         lt_fcat  TYPE lvc_t_fcat,
  62.         ls_fcat  TYPE lvc_s_fcat,
  63.         lt_event TYPE slis_t_event,
  64.         ls_event TYPE slis_alv_event.
  65.   ls_layo-zebra      = abap_true.
  66.   ls_layo-cwidth_opt = abap_true.
  67.   ls_fcat-fieldname = 'SEL'.
  68.   ls_fcat-hotspot = 'X'.
  69.   ls_fcat-scrtext_l =
  70.   ls_fcat-scrtext_m =
  71.   ls_fcat-scrtext_s = '选择'.
  72.   APPEND ls_fcat TO lt_fcat.
  73.   CLEAR ls_fcat.
  74.   ls_fcat-fieldname = 'VAL'.
  75.   ls_fcat-scrtext_l =
  76.   ls_fcat-scrtext_m =
  77.   ls_fcat-scrtext_s = '值'.
  78.   APPEND ls_fcat TO lt_fcat.
  79.   CLEAR ls_fcat.
  80.   ls_event-name = slis_ev_caller_exit_at_start.
  81.   ls_event-form = slis_ev_caller_exit_at_start.
  82.   APPEND ls_event TO lt_event.
  83. * 显示alv列表
  84.   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  85.     EXPORTING
  86.       i_callback_program = sy-repid
  87.       is_layout_lvc      = ls_layo
  88.       it_fieldcat_lvc    = lt_fcat
  89.       i_save             = 'A'
  90.       it_events          = lt_event
  91.     TABLES
  92.       t_outtab           = gt_list
  93.     EXCEPTIONS
  94.       program_error      = 1
  95.       OTHERS             = 2.
  96.   IF sy-subrc NE 0.
  97.     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  98.           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  99.   ENDIF.
  100. ENDFORM.                    " FRM_DSP_DATA
  101. *&---------------------------------------------------------------------*
  102. *&      Form  CALLER_EXIT
  103. *&---------------------------------------------------------------------*
  104. FORM caller_exit USING u_exit TYPE slis_data_caller_exit.
  105.   DATA: ls_f4 TYPE lvc_s_f4,
  106.         lt_f4 TYPE lvc_t_f4.
  107.   CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
  108.     IMPORTING
  109.       e_grid = go_alv_grid.
  110. * 设置回车事件
  111.   CALL METHOD go_alv_grid->register_edit_event
  112.     EXPORTING
  113.       i_event_id = cl_gui_alv_grid=>mc_evt_enter
  114.     EXCEPTIONS
  115.       error      = 1
  116.       OTHERS     = 2.
  117. * 设置光标焦点移开被修改单元格后触发事件
  118.   CALL METHOD go_alv_grid->register_edit_event
  119.     EXPORTING
  120.       i_event_id = cl_gui_alv_grid=>mc_evt_modified
  121.     EXCEPTIONS
  122.       error      = 1
  123.       OTHERS     = 2.
  124.   SET HANDLER lcl_event_receiver=>hotspot_click FOR go_alv_grid.
  125. ENDFORM.                    "CALLER_EXIT
  126. *&---------------------------------------------------------------------*
  127. *&      Form  FRM_REF_ALV
  128. *&---------------------------------------------------------------------*
  129. FORM frm_ref_alv .
  130.   DATA ls_stbl TYPE lvc_s_stbl.
  131.   ls_stbl-row = abap_true.
  132.   ls_stbl-col = abap_true.
  133.   CALL METHOD go_alv_grid->refresh_table_display
  134.     EXPORTING
  135.       is_stable = ls_stbl.
  136. ENDFORM.                    " FRM_REF_ALV
复制代码

2、程序执行效果:
radiobutton.jpg
回复

使用道具 举报

CK_Rocky
受教了,感谢lz
回复

使用道具 举报

zhongguomao
居然还可以选择,收藏了。
回复 支持 反对

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表