Application Development 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: 

How to make checkbox to be pre-selected in ALV

Former Member
0 Kudos

Hi all!

I`m creating ALV report and I want to create checkbox in the first column of the row. So I have a field SEL(1) in my structure and I`ve made the fieldcat:

gs_fcat-col_pos = 5.
  gs_fcat-coltext = 'Check'.
  gs_fcat-fieldname = 'SEL'.
  gs_fcat-tabname = 'GT_TREE9001'.
  gs_fcat-outputlen = 10.
  gs_fcat-checkbox = 'X'.
  gs_fcat-edit = 'X'.

That works, checkbox is displayed.

But now I need to make all the checkboxes to be checked for the first start of my program.

I mean when user executes my report all the checkboxes must be checked by default.

I have tried to do following:

loop at gt_tree9001.
gs_tree9001-sel = 'X'.
modify gt_tree9001 from gs_tree9001.
endloop.

But it doesnt work, I now see checkbox and mark 'X' near but not the checked ckeckbox.

Any help appreciated!

10 REPLIES 10

Former Member
0 Kudos

loop at gt_tree9001.

gs_tree9001-sel = 'X'.

modify gt_tree9001 from gs_tree9001.

endloop.

Hi,

Change code

loop at gt_tree9001 INTO gs_tree9001.

gs_tree9001-sel = 'X'.

modify gt_tree9001 from gs_tree9001 TRANSPORTING sel.

endloop.

Former Member
0 Kudos

Hi ,

Use the below logic.

Declare a field symbol with respect to your local structure internal table.

field-symbols : <wa_ekko> like LINE OF it_ekko.

Before displaying ALV fm write this code.

loop at it_ekko ASSIGNING <wa_ekko> .

<wa_ekko>-check = 'X'.

MODIFY TABLE it_ekko FROM <wa_ekko> TRANSPORTING check.

ENDLOOP.

If you want entire code ican send to you.

Regards,

Aditya.

Edited by: Aditya.G on Jan 19, 2012 6:01 PM

0 Kudos

> loop at it_ekko ASSIGNING <wa_ekko> .

> <wa_ekko>-check = 'X'.

> MODIFY TABLE it_ekko FROM <wa_ekko> TRANSPORTING check.

> ENDLOOP.

> Edited by: Aditya.G on Jan 19, 2012 6:01 PM

you dont need a modify statement when field symbol is used this way... do you? its a reference.. once you change the reference value means you are directly changing the actual object..

0 Kudos

Problem is not in Loop statement.

Using debugger I can see:

call method g_tree9001->set_table_for_first_display
    EXPORTING
      i_save              = 'A'
      is_variant          = ls_variant
    CHANGING
      it_sort             = gt_sort9001
      it_outtab           = gt_tree9001
      it_fieldcatalog     = gt_treefcat9001.

Here I look at my gt_tree9001. There are 15 rows and everywhere column SEL (of type C(1)) is set to 'X'.

But in my ALV-tree instead of checked boxes I see empty boxes and marks 'X' near it.

Here is what I see: http://imageshack.us/photo/my-images/857/checkboxt.png/

0 Kudos

you need to fill the layout parameter as well saying that this field is checkbox. search SDN for a sample code for checkbox

Former Member
0 Kudos

Hi

Try this code:

AT SELECTION-SCREEN.
 
 <Code to fill data to the internal table gt_tree9001>
  
 LOOP AT gt_tree9001.
      gs_tree9001-sel = 'X'.
      MODIFY gt_tree9001 FROM gs_tree9001.
  ENDLOOP.

START-OF-SELECTION.

  <Code to display alv>

Thanks and Regards,

Rinzy Deena Mathews.

0 Kudos

Hi fore,

In our grid display use layout filed also.use below code for this

DATA: LAYOUT TYPE SLIS_LAYOUT_ALV.

START-OF-SELECTION.

perform layout.

FORM LAYOUT .

layout-box_fieldname = 'CBOX'. This is your checkbox name'(SEL)(use capital letters)

endform.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = REPID

IS_LAYOUT = LAYOUT

IT_FIELDCAT = IT_FC_VBAK

I_DEFAULT = 'X'

I_SAVE = 'X'

TABLES

T_OUTTAB = IT_VBAK.

Regards,

Haritha.M

Former Member
0 Kudos

Hi Forewar,

I suppose this is your code.

loop at gt_tree9001.

gs_tree9001-sel = 'X'.

modify gt_tree9001 from gs_tree9001.

endloop.

Here you are using internal table without header line right. You have missed the into class in the loop.

Check this code.

loop at gt_tree9001 into gs_tree9001.

gs_tree9001-sel = 'X'.

modify gt_tree9001 from gs_tree9001.

endloop.

and after this loop refresh your grid display using refresh_table_display method of your grid object.

Try it will work.

Wish this helps.

Aswath.

Edited by: aswathsa on Jan 20, 2012 5:27 AM

Former Member
0 Kudos

Solved.

My final code:

data: lv_tree_size TYPE i,
            ls_layout_item TYPE lvc_s_laci,
            lt_layout_item TYPE lvc_t_laci,
            lv_ind TYPE LVC_INDEX.

      CLEAR ls_layout_item.
      ls_layout_item-fieldname = 'SEL'.
      ls_layout_item-class = cl_gui_column_tree=>item_class_checkbox.
      ls_layout_item-editable = 'X'.
      ls_layout_item-u_class = 'X'.
      ls_layout_item-u_editable = 'X'.
      ls_layout_item-u_chosen = 'X'.
      ls_layout_item-chosen = 'X'.
      append ls_layout_item to lt_layout_item.

call method g_tree9001->set_table_for_first_display
      EXPORTING
        i_save              = 'A'
        is_variant          = ls_variant
      CHANGING
        it_sort             = gt_sort9001
        it_outtab           = gt_tree9001
        it_fieldcatalog     = gt_treefcat9001.

DESCRIBE TABLE gt_tree9001 LINES lv_tree_size.

DO lv_tree_size TIMES.
        CALL METHOD G_TREE9001->CHANGE_LAYOUT
          EXPORTING
            I_OUTTAB_INDEX = sy-index
            IT_ITEM_LAYOUT = lt_layout_item                .
ENDDO.

The main trick is in u_class, u_editable, u_chosen. These params say that layout should be changed. Only this way it will work.

And some helpful links:

Report BCALV_TREE_ITEMLAYOUT is also very helpful.

0 Kudos

Thanks for the solution. Here's a full short & working example ->