Skip to Content

Checkbox in factory ALV, whenever this thought comes to might it feels like scratching the head as in one shot it looks like a blunder that can’t be implemented.

But giving it a try, might help you achieve the results, As this is possible and that too easily, just give it a try.

Here’s the procedure on how to achieve the results without container ALV, but by factory ALV.

Step1: Primarily include a field say chkbox in structure of final ALV display which is of type as4flag.

I tried with as4flag you can try defining it as of Char1 type too, it will work, but why to use any other as SAP has provided with something already.

Step2: Now you need to display the same in your code of ALV display.

example provided below:

   * Checkbox Addition
      o_column ?= o_columns->get_column( ‘CHKBOX’ ).                    “here CHKBOX is the field that you introduced in final structure
      o_column->set_cell_type( if_salv_c_cell_type=>checkbox_hotspot ). “this is to implement the check uncheck functionality
      o_column->set_output_length( 1 ).                         ” display length
      o_column->set_long_text( ‘CHECKBOX’ ).              ” Display name in ALV output

Step3: Now to add the check-Uncheck Functionality you need to record the events happening on screen.

this is how you will do this. Primarily what needs to be done is an event must be created which will record the click (CHECK/Uncheck) on screen.

Example code:

        o_cevents = o_table->get_event( ).

      CREATE OBJECT o_levents.
      SET HANDLER o_levents->on_link_click FOR o_cevents.  ” This event will be for link click(CHECK/ Uncheck)

Here “on_link_click” is the method of class “lcl_handle_events”

Step4: Now As you have used a method you need to define and implement the same too (else it will thow you an error)

Examples are provided below:

For DEFINITION

   CLASS lcl_handle_events DEFINITION.
  PUBLIC SECTION.
    METHODS :
      on_link_click FOR EVENT link_click OF cl_salv_events_table
      IMPORTING row column,
ENDCLASS.                    “lcl_handle_events DEFINITION

For IMPLEMENTATION

   CLASS lcl_handle_events IMPLEMENTATION.
  METHOD on_link_click.
    PERFORM f_change_flag USING row.
  ENDMETHOD.                    “on_link_click
ENDCLASS.                    “lcl_handle_events IMPLEMENTATION

Here the perform is for implementating the Check/ Uncheck Functionality i.e. to view the results after you click on checkbox.

for form the code will be like:

  FIELD-SYMBOLS: <lfs_data> LIKE LINE OF it_final31.
  READ TABLE <Name of Final Table > ASSIGNING <lfs_data> INDEX fp_row.
  CHECK sy-subrc IS INITIAL.
  IF <lfs_data>-check IS INITIAL.
    <lfs_data>-check = ‘X’.
  ELSE.
    CLEAR <lfs_data>-check.
  ENDIF.
  o_table->refresh( ).          ” This is for refreshing after screen i.e. if you click the unchecked checkbox, after you click it should get check, right and vice versa.

this is all how this will work..

If anyone has any doubts do reply to me…

To summarize I am attaching some snapshots shich will help you in understanding what I achieved, and now you can too.

Unchecked

Capture1.JPG

Checked

Capture2.JPG

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply