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: 

Select rows in ALV grid with CL_GUI_ALV_GRID

massimo_sforza
Participant
0 Kudos

Hi all,

i'm using class CL_GUI_ALV_GRID and i want the buttons at begin of every row to select it.

With the classic function REUSE_ALV_GRID_DISPLAY i used the layout parameter box_fieldname:

<b>layout-box_fieldname = 'CBOX'.</b>

where CBOX is the name field of my internal table in the first position (char1)

and it works.

with the CL_GUI_ALV_GRID ther's not parameter box_fieldname but BOX_FNAME.

<b>layout_alv-BOX_FNAME = 'CBOX'.</b>

When i call the method

call method grid->set_table_for_first_display

EXPORTING

is_layout = layout_alv

CHANGING

IT_FIELDCATALOG = it_fieldcat_voci

it_sort = gt_sort_grid[]

it_outtab = gt_voci[].

it doesn't work.

Somebody knows why? Do i have to do something else?

Thanks a lot?

Massimo.

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate

Its a little different using the class, First you need to set the selection module before calling the SET_TABLE_FOR_FIRST_DISPLAY method.



data:      LAYOUT  TYPE LVC_S_LAYO,
 
 LAYOUT-SEL_MODE = 'D'.

  CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
           IS_LAYOUT              = LAYOUT
      CHANGING
           IT_OUTTAB       = IALV[]
           IT_FIELDCATALOG = FIELDCAT[].

So this will give you the selection box in the ALV output, then you use the method GET_SELECTED_ROWS to determine what rows the user has selected.



DATA: INDEX_ROWS TYPE LVC_T_ROW,
      INDEX LIKE LINE OF INDEX_ROWS.

  CLEAR INDEX_ROWS.  REFRESH INDEX_ROWS.
  CALL METHOD ALV_GRID->GET_SELECTED_ROWS
           IMPORTING
                 ET_INDEX_ROWS = INDEX_ROWS.


* Do something with those selected rows here
      LOOP AT INDEX_ROWS INTO INDEX.

* Use the index to read the specific line of ALV which is selected
        READ TABLE IALV INDEX INDEX-INDEX.
        IF SY-SUBRC = 0.

* Now do what ever you need to with the selected line

        ENDIF.
      ENDLOOP.



Regards,

Rich Heilman

5 REPLIES 5

RichHeilman
Developer Advocate
Developer Advocate

Its a little different using the class, First you need to set the selection module before calling the SET_TABLE_FOR_FIRST_DISPLAY method.



data:      LAYOUT  TYPE LVC_S_LAYO,
 
 LAYOUT-SEL_MODE = 'D'.

  CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
           IS_LAYOUT              = LAYOUT
      CHANGING
           IT_OUTTAB       = IALV[]
           IT_FIELDCATALOG = FIELDCAT[].

So this will give you the selection box in the ALV output, then you use the method GET_SELECTED_ROWS to determine what rows the user has selected.



DATA: INDEX_ROWS TYPE LVC_T_ROW,
      INDEX LIKE LINE OF INDEX_ROWS.

  CLEAR INDEX_ROWS.  REFRESH INDEX_ROWS.
  CALL METHOD ALV_GRID->GET_SELECTED_ROWS
           IMPORTING
                 ET_INDEX_ROWS = INDEX_ROWS.


* Do something with those selected rows here
      LOOP AT INDEX_ROWS INTO INDEX.

* Use the index to read the specific line of ALV which is selected
        READ TABLE IALV INDEX INDEX-INDEX.
        IF SY-SUBRC = 0.

* Now do what ever you need to with the selected line

        ENDIF.
      ENDLOOP.



Regards,

Rich Heilman

0 Kudos

ok, perfect....

thanks a lot.

Massimo

0 Kudos

Maybe you could award some points if the answer has helped you to solve your problem. Thanks in advance.

Regards,

Rich HEilman

0 Kudos

Hi Rich,

I tried the to capture the selected row in the ALV display but INDEX_ROWS remains intial when i checked in debug.

Pls let me know why this happening.

Regards,

Naba

0 Kudos

After 17 years, your answer still helped me 🙏