Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Scope :

The purpose of this document is to display radio buttons in ALV grid.

Business requirement :

Consider a scenario where the screen needs to be displayed with a list of accounting document numbers, fiscal year and company code. By Selecting one option at a time, it should navigate to the next screen (FB03) with the corresponding details of that selected accounting document number.

SAP ALV Limitation :

As radio button is nowhere included in as a genuine feature of ALV grid, it is a bit tricky. We can implement the same by using the corresponding ICON and HOTSPOT_CLICK event.

Workaround:

In this case from a report program we are calling screen where ALV Grid is displayed.

In the report program write the below code:

  1. 1. Declaration:

Create a top include in the report program. Add below lines of code:

TYPE-POOLS: slis.

INCLUDE <icon>.

Internal table structure:

As mentioned in the scenario with accounting document number, fiscal year and company code, radio button should be get displayed. So in top of program only structure of internal table will be of following type:

TYPES: BEGIN OF ty_view,
        bukrs
TYPE bukrs,
        belnr
TYPE belnr_d,
        gjahr
TYPE gjahr,
        radio(4)
TYPE c,
        handle_style 
TYPE lvc_t_styl,
       
END OF ty_view.

Make this field (RADIO) as both hot-spot and be active on double click. Then using the corresponding icons and the HOTSPOT_CLICK event it works like a radio button. For achieving our goal we have to use local class and methods in our report program.

Define and implement event handler class

Define a local class and declare two methods one for handling hotspot and other one for handling double click.

   

    CLASS lcl_event_handler DEFINITION FINAL.

          PUBLIC SECTION.

          METHODS: handle_double_click  FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row e_column,

                     handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid

IMPORTING e_row_id
                                                          e_column_id
                                                    es_row_no
                                                    sender.

     ENDCLASS.                   

Write implementation of that class with implementation of the method.

CLASS lcl_event_handler IMPLEMENTATION.

 
METHOD: handle_double_click.
   
CALL METHOD g_grid3->get_selected_rows
     
IMPORTING
        et_index_rows = lt_selected_rows.
 
ENDMETHOD.                   

  METHOD: handle_hotspot_click.
   
FIELD-SYMBOLS: <ls_entry> TYPE ty_view,
                             <ld_fld>  
TYPE ANY.
   
LOOP AT gt_view ASSIGNING <ls_entry>.
     
IF sy-tabix EQ es_row_no-row_id.
       
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_radiobutton.
       
ENDIF.
     
ELSE.

  1. Module Pool:

            Open the screen where ALV grid with radio button needs to be displayed (For example screen number is 1000) and create a custom control in that. Suppose the name of the custom control is C_CUST_CONT3.

PBO

  1. Now in PBO of module pool program. Our aim to display ALV grid with radio button in screen.

  Structure of field catalog and layout will be of type: lvc_t_fcat and lvc_s_layo. 

Initialy ALV will be displayed with one radio button as set.

So for setting a radio button we can just by default set 1st row as set.

Gf_view-radio = icon_radiobutton.  “It will tell selected radio button.

And for other entries set them as unselected for that pass

gf_view-radio = icon_wd_radio_button_empty.

  1. While building fieldcatalog for that radio field we have to pass below 2 fields :

  gf_fieldcat1-icon       = 'X'.

gf_fieldcat1-hotspot = 'X'.

  1. While creating layout of the ALV table we need to pass stylefname with:

  gf_lay-stylefname = 'HANDLE_STYLE'. 

  1. To handle events we have to create event handler.

CREATE OBJECT go_handler .
   
SET HANDLER:

    go_handler->handle_double_click  FOR g_grid3,
    go_handler->handle_hotspot_click
FOR g_grid3.

    CALL METHOD cl_gui_control=>set_focus
     
EXPORTING
       
control = g_grid3.

To display output:

*-To display output.
   
CALL METHOD g_grid3->set_table_for_first_display
     
EXPORTING
        is_layout                     = gf_lay
     
CHANGING
        it_outtab                     = gt_view
        it_fieldcatalog               = gt_fieldcat1
     
EXCEPTIONS
        invalid_parameter_combination =
1
        program_error                 =
2
        too_many_lines                =
3
       
OTHERS                        = 4.

If it is not for first time then we need to check change data and refresh ALV data

          CALL METHOD g_grid3->check_changed_data.
         
CALL METHOD g_grid3->refresh_table_display.

         
CALL METHOD cl_gui_control=>set_focus
         
EXPORTING
         
control = g_grid3.

PAI :

The below code has to be written for ‘REFRESH’ OKCODE.

Refresh table display after switching the radiobuttons

  DATA: ls_stable TYPE lvc_s_stbl.
  ls_stable-row = abap_true.
  ls_stable-col = abap_true.

  CALL METHOD g_grid3->refresh_table_display
   
EXPORTING
      is_stable = ls_stable
   
EXCEPTIONS
      finished  =
1
     
OTHERS    = 2.


  gx_fresh =

'X'.

In PAI of the screen read internal table where for field radio button icon is set like

READ TABLE gt_view INTO gf_view WITH KEY radio = icon_radiobutton.

After that call transaction FB03 and skip first screen.

The screen will look as below:

The screen navigates to the accounting document screen transaction FB03.

Conclusion: Thus the radio buttons could be included in ALV grid display using ICON and HOTSPOT_CLICK event.

5 Comments