cancel
Showing results for 
Search instead for 
Did you mean: 

ALV and Checkbox : retrieving what we select

david_fryda2
Participant
0 Kudos

Hi everyone,

I created checkoxes in an ALV.

I am trying to retrieve what lines I selected from the ALV.

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

former_member188685
Active Contributor
0 Kudos

Hi David If you are Using Classes then

You Have use method get_selected_rows.

but if you are using normal fm then you need to loop the internal table and get the values where flag = 'X'.

regards

vijay

david_fryda2
Participant
0 Kudos

Hi everyone,

The scenario is :

I added a button (refresh) in the ALV. When I click on it I want to know which lines I selected via the checkboxes.

I am using normal ALV (no classes).

If I click on my refresh button my internal table has no flag = 'X'.

But if I click on a row (after selecting the checkbox) I do see the flag='X'.

So it works when I click on the row of the ALV but does not work if I click on the refresh button that I added.

Here is the code.


REPORT  ztestdfalv1                             .

*Data Declaration
*----------------
DATA: BEGIN OF t_ekko,
  select(1),
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF t_ekko.

DATA: BEGIN OF it_ekko OCCURS 0.
        INCLUDE STRUCTURE t_ekko.
DATA: END OF it_ekko.

*ALV data declarations
TYPE-POOLS: slis.                                 "ALV Declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_layout    TYPE slis_layout_alv,
      gd_repid     LIKE sy-repid.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

  PERFORM data_retrieval.
  PERFORM build_fieldcatalog.
  PERFORM build_layout.
  PERFORM display_alv_report.


*&--------------------------------------------------------------------*
*&      Form  build_fieldcatalog
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM build_fieldcatalog.
  REFRESH fieldcatalog.
  CLEAR fieldcatalog.

  fieldcatalog-fieldname   = 'SELECT'.
  fieldcatalog-seltext_m   = 'Select please'.
  fieldcatalog-checkbox    = 'X'.
  fieldcatalog-edit        = 'X'.
  fieldcatalog-input       = 'X'.
  fieldcatalog-col_pos     = 1.
  APPEND fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-hotspot     = 'X'.
  fieldcatalog-col_pos     = 2.
  APPEND fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-seltext_m   = 'PO Item'.
  fieldcatalog-col_pos     = 3.
  APPEND fieldcatalog.
  CLEAR  fieldcatalog.

ENDFORM.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
FORM build_layout.
  "Permet d'ajuster les colonnes au text
*  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).

*  gd_layout-box_fieldname = 'SELECT'.
*  gd_layout-box_tabname   = 'IT_EKKO'.

ENDFORM.                    " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
FORM display_alv_report.
  gd_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            i_callback_program        = gd_repid
*            i_callback_top_of_page   = 'TOP-OF-PAGE'
            i_callback_pf_status_set  = 'SET_PF_STATUS'
            i_callback_user_command   = 'USER_COMMAND'
*            i_grid_title             = 'My Title'
            is_layout                 = gd_layout
            it_fieldcat               = fieldcatalog[]
            i_save                    = 'X'
       TABLES
            t_outtab                  = it_ekko
       EXCEPTIONS
            program_error             = 1
            OTHERS                    = 2.

  IF sy-subrc <> 0.
    WRITE:/ sy-subrc.
  ENDIF.

ENDFORM.                    " DISPLAY_ALV_REPORT


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM data_retrieval.
  SELECT ebeln ebelp
   UP TO 10 ROWS
    FROM ekpo
    INTO CORRESPONDING FIELDS OF TABLE  it_ekko.
ENDFORM.                    " DATA_RETRIEVAL


*----------------------------------------------------------------------*
*                      FORM SET_PF_STATUS                              *
*----------------------------------------------------------------------*
FORM set_pf_status USING rt_extab   TYPE  slis_t_extab.
  SET PF-STATUS 'STANDARD_FULLSCREEN1'.
ENDFORM.                    "set_pf_status


*&--------------------------------------------------------------------*
*&      Form  user_command
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->R_UCOMM    text
*      -->RS_SELFIELDtext
*---------------------------------------------------------------------*
FORM user_command  USING r_ucomm LIKE sy-ucomm
                         rs_selfield TYPE slis_selfield.
  CASE r_ucomm.
    WHEN '&IC1'.
      CHECK rs_selfield-tabindex > 0.
      IF rs_selfield-value EQ '6000000001'.
        CALL TRANSACTION 'ZDF2'.
      ENDIF.
    WHEN 'REFRESH'.

      LOOP AT it_ekko WHERE select = 'X'.

      ENDLOOP.

      PERFORM data_retrieval.
      rs_selfield-refresh = 'X'.

  ENDCASE.
ENDFORM.                    "user_command



Thanks.

Message was edited by: David Fryda

former_member181962
Active Contributor
0 Kudos

Hi David,

IN the code

<b> LOOP AT it_ekko WHERE select = 'X'.

ENDLOOP.</b>

PERFORM data_retrieval.

rs_selfield-refresh = 'X'.

why are you doing nothing inside the loop??

Former Member
0 Kudos

Hi David,

Do the following steps as you are using an Editable ALV Grid.

First of all declare the following at top in your program,

gd_repid LIKE sy-repid, "Exists

<b> ref_grid TYPE REF TO cl_gui_alv_grid.</b> "new

then insert the following code in your USER_COMMAND routine...

FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

<b> IF ref_grid IS INITIAL.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

IMPORTING

  • ET_EXCLUDING =

  • E_FLG_NO_HTML =

  • E_REPID =

e_grid = ref_grid

  • ES_LAYOUT_KKBLO =

.

ENDIF.

IF NOT ref_grid IS INITIAL.

CALL METHOD ref_grid->check_changed_data

  • IMPORTING

  • E_VALID =

  • CHANGING

  • C_REFRESH = 'X'

.

ENDIF.</b>

Now you will see 'X' in your internal table..

Hope this helps..

Sri

david_fryda2
Participant
0 Kudos

Thanks to everyone and especially to Srikanth Pinnamaneni.

It works.

Here are the rewards...

Regards.

Answers (6)

Answers (6)

former_member188685
Active Contributor
0 Kudos

Hi The above Code works very well if you change the FM to <b>REUSE_ALV_LIST_DISPLAY</b>.

you can see the values that are checked.

try that.

Regards

vijay

former_member181962
Active Contributor
0 Kudos

Hi david,

Firstly you should be able to reflect the changes that the user makes in the basic list(Like choosing lines) into the internal tables.

For that you should check the parameter i_save = 'A' while calling the alv FM.

Then you will have the internal table with the flag set to 'X' for each line which you have choosen.

loop at internal table and choose based on the falg(for the checkbox).

Regards,

ravi

Former Member
0 Kudos

you can use the field standard of the alv grid.

there is a method that get the selected lines.

call method ob_alvgrid->get_selected_rows

importing

et_index_rows = tl_rows.

Alexandre Nogueira.

Former Member
0 Kudos

David,

Use the methd <b>GET_SELECTED_ROWS</b> of the Class <b>CL_GUI_ALV_GRID</b>

Thanks

Kam

Former Member
0 Kudos

Hi David,

Your internal table itself will get filled with the checkboxes selected i.e. SELECT = 'X' will be set in your internal table for all the lines that you have selected.

Also take a look at report BCALV_FULLSCREEN_GRID_EDIT.

Basically put a break point in user_command routine in the above program and then change some thing in the editable grid and click on some button. Once you reach the break-point you will notice that the internal table (gt_sflight in this case) already has your changes.

Hope this helps..

Sri

Message was edited by: Srikanth Pinnamaneni

Message was edited by: Srikanth Pinnamaneni

former_member188685
Active Contributor
0 Kudos

hi using selfield you can get the line which you selected

if you are selecting single line.

using <b> enter</b> you can get the value.

if it is multiple lines.

then you place your own button in the Tool bar and then

if you press the button then you can handle.using enter also possible i guess

loop the table and where ever the checkbox is 'X' select them and process.

regards

vijay

Message was edited by: Vijay Babu Dudla