Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

looking for method for alv

Former Member
0 Likes
494

Hi i created alv grid with columns as checkboxes. i use methods event_handler_on_change, modify_cell but now i looking for method which allows me to check after click on checkbox if in this column is any cell checked already.

Could someone tell me which method I can use?

regards,

Joanna

2 REPLIES 2
Read only

uwe_schieferstein
Active Contributor
0 Likes
405

Hello Joanna

There is no method for your specific requirement available. However, have a look at my sample report <b>ZUS_SDN_ALV_WITH_RADIOBUTTONS2</b> which may give you an idea how to solve the problem. Simply replace the radiobuttons with your checkboxes and you have your solution.

The report is based on my previous posting:

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a02535ce-9eaf-2910-ae8c-f2f2afc1c8e7">ALV List with Radio Buttons</a>

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_ALV_WITH_RADIOBUTTONS2
*&
*&---------------------------------------------------------------------*
*& This program shows how to realize radiobuttons in ALV grid lists
*& using event HOTSPOT_CLICK.
*&
*&---------------------------------------------------------------------*
*& Screen 100:
*& - Flow logic
*&
*&      PROCESS BEFORE OUTPUT.
*&        MODULE PBO.
*&*
*&      PROCESS AFTER INPUT.
*&        MODULE PAI.
*&
*& - Screen elements: none
*& - ok-code field -> gd_okcode
*&
*& GUI Status MAIN100:
*& - F3 = 'BACK', Shift+F3 = 'EXIT', F12 = 'CANC'
*&---------------------------------------------------------------------*
PROGRAM zus_sdn_alv_with_radiobuttons2.



TYPE-POOLS: abap, icon.  " INCLUDE <icon>. for releases < 6.20


TYPES: BEGIN OF ty_s_sflight.
INCLUDE TYPE sflight.
TYPES: button1    TYPE iconname.
TYPES: button2    TYPE iconname.
TYPES: button3    TYPE iconname.
TYPES: button4    TYPE iconname.
TYPES: END OF ty_s_sflight.


DATA:
  gt_sflight    TYPE STANDARD TABLE OF ty_s_sflight,
*
  gs_layout     TYPE lvc_s_layo,
  gt_fcat       TYPE lvc_t_fcat.


DATA:
  gd_okcode    TYPE ui_func,
  go_docking   TYPE REF TO cl_gui_docking_container,
  go_grid      TYPE REF TO cl_gui_alv_grid.





*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.

  PUBLIC SECTION.

    CLASS-METHODS:
      handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
        IMPORTING
          e_row_id
          e_column_id
          es_row_no
          sender.

ENDCLASS.                    "lcl_eventhandler DEFINITION


*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.

  METHOD handle_hotspot_click.
* define local data
    DATA:
      ld_count(3)   TYPE n,
      ld_msg        TYPE bapi_msg.

    FIELD-SYMBOLS:
      <ls_entry>    TYPE ty_s_sflight,
      <ld_fld>      TYPE ANY.

    READ TABLE gt_sflight ASSIGNING <ls_entry> INDEX es_row_no-row_id.
    CHECK ( <ls_entry> IS ASSIGNED ).

*   Set all radio buttons "unselected"
    <ls_entry>-button1 =  icon_wd_radio_button_empty.
    <ls_entry>-button2 =  icon_wd_radio_button_empty.
    <ls_entry>-button3 =  icon_wd_radio_button_empty.
    <ls_entry>-button4 =  icon_wd_radio_button_empty.

    ASSIGN COMPONENT e_column_id-fieldname OF STRUCTURE <ls_entry>
                                              TO <ld_fld>.
    IF ( <ld_fld> IS ASSIGNED ).
*     Set selected radio button "selected".
      <ld_fld> = icon_wd_radio_button.
    ENDIF.

    ld_count = 0.
    LOOP AT gt_sflight ASSIGNING <ls_entry>.
      ASSIGN COMPONENT e_column_id-fieldname OF STRUCTURE <ls_entry>
                                                TO <ld_fld>.
      "     Note: here you could count your marked checkboxes within
      "           the column, e.g.: IF ( '<checkbox1>' = 'X' ).
      IF ( <ld_fld> = icon_wd_radio_button ).
        ADD 1 TO ld_count.
      ENDIF.

    ENDLOOP.

    CONCATENATE 'Column' e_column_id-fieldname
      INTO ld_msg SEPARATED BY space.
    CONCATENATE ld_msg ':' ld_count 'times marked'
      INTO ld_msg SEPARATED BY space.
    MESSAGE ld_msg TYPE 'I'.



*   Force PAI followed by refresh of table display in PBO
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'REFRESH'
*      IMPORTING
*        RC       =
        .

  ENDMETHOD.                    "handle_hotspot_click

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION



*---------------------------------------------------------------------*
*       MAIN                                                          *
*---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM select_data.

  PERFORM init_controls.
  PERFORM build_fieldcatalog.
  PERFORM set_layout.

  CALL METHOD go_grid->set_table_for_first_display
   EXPORTING
*     i_structure_name = 'SFLIGHT'
      is_layout        = gs_layout
    CHANGING
      it_fieldcatalog  = gt_fcat
      it_outtab        = gt_sflight.

* Link docking container to dynpro
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = syst-repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      lifetime_dynpro_dynpro_link = 3
      OTHERS                      = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CALL SCREEN 100.


END-OF-SELECTION.






*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.
ENDMODULE.                    "PBO OUTPUT

*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.

* Leave report
  CASE gd_okcode.
    WHEN 'BACK'  OR
         'EXIT'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.

*   Refresh table display
    WHEN 'REFRESH'.
      PERFORM refresh_display.


    WHEN OTHERS.
*     do nothing
  ENDCASE.
  CLEAR gd_okcode.
ENDMODULE.                    "PAI INPUT



*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
* define local data
  DATA:
    ls_fcat        TYPE lvc_s_fcat.


  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'ICON'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  DELETE gt_fcat WHERE ( fieldname <> 'NAME' ).
* NOTE: field ICON-NAME has data element ICONNAME.


  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'SFLIGHT'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  READ TABLE gt_fcat INTO ls_fcat
       WITH KEY fieldname = 'NAME'.
  IF ( syst-subrc = 0 ).
    DELETE gt_fcat INDEX syst-tabix.
  ENDIF.

  ls_fcat-fieldname = 'BUTTON4'.
  ls_fcat-coltext   = ls_fcat-fieldname.
  ls_fcat-icon    = 'X'.
  ls_fcat-hotspot = 'X'.
  INSERT ls_fcat INTO gt_fcat INDEX 5.
*
  ls_fcat-fieldname = 'BUTTON3'.
  ls_fcat-coltext   = ls_fcat-fieldname.
  INSERT ls_fcat INTO gt_fcat INDEX 5.
*
  ls_fcat-fieldname = 'BUTTON2'.
  ls_fcat-coltext   = ls_fcat-fieldname.
  INSERT ls_fcat INTO gt_fcat INDEX 5.
*
  ls_fcat-fieldname = 'BUTTON1'.
  ls_fcat-coltext   = ls_fcat-fieldname.
  INSERT ls_fcat INTO gt_fcat INDEX 5.


* Renumbering of the columns
  LOOP AT gt_fcat INTO ls_fcat.
    ls_fcat-col_pos = syst-tabix.
    MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
  ENDLOOP.






ENDFORM.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  SELECT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM select_data .
* define local data
  DATA:
    ls_sflight    TYPE ty_s_sflight.


  SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_sflight.

  ls_sflight-button1 = icon_wd_radio_button. " selected radiobutton
  ls_sflight-button2 = icon_wd_radio_button_empty.
  ls_sflight-button3 = icon_wd_radio_button_empty.
  ls_sflight-button4 = icon_wd_radio_button_empty.
* Alternatively: create icons using function module 'ICON_CREATE'



  MODIFY gt_sflight FROM ls_sflight
      TRANSPORTING button1 button2 button3 button4
    WHERE ( carrid IS NOT INITIAL ).

ENDFORM.                    " SELECT_DATA


*&---------------------------------------------------------------------*
*&      Form  INIT_CONTROLS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM init_controls .

  CHECK ( go_docking IS NOT BOUND ).

* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent                      = cl_gui_container=>screen0
*      REPID                       =
*      DYNNR                       =
*      SIDE                        = DOCK_AT_LEFT
*      EXTENSION                   = 50
*      STYLE                       =
*      LIFETIME                    = lifetime_default
*      CAPTION                     =
*      METRIC                      = 0
      ratio                       = 90
*      NO_AUTODEF_PROGID_DYNNR     =
*      NAME                        =
    EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      lifetime_dynpro_dynpro_link = 5
      OTHERS                      = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Size of container = full screen size
  CALL METHOD go_docking->set_extension
    EXPORTING
      extension  = 99999
    EXCEPTIONS
      cntl_error = 1
      OTHERS     = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Create ALV grid instance
  CREATE OBJECT go_grid
    EXPORTING
*      I_SHELLSTYLE      = 0
*      I_LIFETIME        =
      i_parent          = go_docking
*      I_APPL_EVENTS     = space
*      I_PARENTDBG       =
*      I_APPLOGPARENT    =
*      I_GRAPHICSPARENT  =
*      I_NAME            =
*      I_FCAT_COMPLETE   = SPACE
    EXCEPTIONS
      error_cntl_create = 1
      error_cntl_init   = 2
      error_cntl_link   = 3
      error_dp_create   = 4
      OTHERS            = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


*   Set event handler for event HOTSPOT_CLICK
  SET HANDLER:
    lcl_eventhandler=>handle_hotspot_click FOR go_grid.

ENDFORM.                    " INIT_CONTROLS


*&---------------------------------------------------------------------*
*&      Form  REFRESH_DISPLAY
*&---------------------------------------------------------------------*
*       Refresh table display after switching the radiobuttons
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM refresh_display .
* define local data
  DATA:
    ls_stable    TYPE lvc_s_stbl.

  ls_stable-row = abap_true.
  ls_stable-col = abap_true.

  CALL METHOD go_grid->refresh_table_display
    EXPORTING
      is_stable      = ls_stable
*        I_SOFT_REFRESH =
    EXCEPTIONS
      finished       = 1
      OTHERS         = 2.
  IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " REFRESH_DISPLAY

*&---------------------------------------------------------------------*
*&      Form  SET_LAYOUT
*&---------------------------------------------------------------------*
*       Set layout for ALV list
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_layout .

  CLEAR: gs_layout.

  gs_layout-cwidth_opt = abap_true.  " optimize column width
  gs_layout-zebra      = abap_true.

ENDFORM.                    " SET_LAYOUT

Regards

Uwe

Read only

Former Member
0 Likes
405

Hi Joanna,

See this standard program in your system which clearly explains the following scenarios.

<b>BCALV_EDIT_05</b>

This example shows how to use checkboxes within an ALV Grid Control. You learn:

(1) how to define a column for editable checkboxes for an attribute of your list

(2) how to evaluate the checked checkboxes

(3) how to switch between editable and non-editable checkboxes

Once you understand this program, you can find many other sample programs in similar lines.

Thanks & Regards,

Aleem.