2007 Feb 10 2:25 PM
Hi,
can anyone send me a sample code for alv grid display, in which i must be able to select multiple rows.
when i mean multiple rows ,its not by selectall,because say if i have 10 records, i want to select only 3 rows .
Thanks in advance
2007 Feb 10 2:59 PM
Check this example,
*&---------------------------------------------------------------------*
*& Report ZKB_ALV_GRID
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zkb_alv_grid.
DATA: BEGIN OF i_scarr_tab OCCURS 0.
INCLUDE STRUCTURE scarr.
DATA: END OF i_scarr_tab.
DATA: i_scarr LIKE TABLE OF i_scarr_tab WITH HEADER LINE,
w_scarr LIKE LINE OF i_scarr_tab.
DATA: o_grid TYPE REF TO cl_gui_alv_grid,
o_container TYPE REF TO cl_gui_custom_container.
DATA: lt_fcat TYPE lvc_t_fcat,
ls_layo TYPE lvc_s_layo,
ls_sort TYPE lvc_s_sort,
lt_sort TYPE lvc_t_sort,
ls_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
START-OF-SELECTION.
CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*& Module status_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS '9000'.
SET TITLEBAR '9000'.
ENDMODULE. " status_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module user_command_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
CASE sy-ucomm .
WHEN 'BACK' OR 'EXIT'.
SET SCREEN 0.
LEAVE SCREEN.
ENDCASE.
ENDMODULE. " user_command_9000 INPUT
*&---------------------------------------------------------------------*
*& Module init_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE init_9000 OUTPUT.
IF o_container IS INITIAL.
SELECT * FROM scarr INTO CORRESPONDING FIELDS OF TABLE
i_scarr UP TO 100 ROWS.
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
* Create a custom container control for ALV Control
CREATE OBJECT o_container
EXPORTING
container_name = 'CONTROL'.
* Create a ALV Control
CREATE OBJECT o_grid
EXPORTING i_parent = o_container.
PERFORM build_field_catalgue.
ls_layo-sel_mode = 'A'.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
i_save = 'A'
i_default = 'X'
is_layout = ls_layo
CHANGING
it_outtab = i_scarr[]
it_fieldcatalog = lt_fcat
it_sort = lt_sort[].
ENDIF.
ENDIF.
ENDMODULE. " init_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Form build_field_catalgue
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_field_catalgue .
DATA: ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-cprog
i_internal_tabname = 'I_SCARR_TAB'
i_structure_name = 'SCARR'
* i_client_never_display = 'X'
CHANGING
ct_fieldcat = ls_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE 'FCAT Error' TYPE 'I'.
EXIT.
ENDIF.
LOOP AT ls_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = ls_fieldcat-fieldname. "Fieldname
ls_fcat-ref_table = ls_fieldcat-tabname. "DDIC ref struct
ls_fcat-inttype = ls_fieldcat-inttype. "Data type
ls_fcat-outputlen = ls_fieldcat-outputlen. "Column width
ls_fcat-coltext = ls_fieldcat-seltext_m. "Column Header
ls_fcat-seltext = ls_fieldcat-seltext_m. "Column Desc
ls_fcat-ref_field = ls_fieldcat-ref_fieldname. "Reference field
ls_fcat-ref_table = ls_fieldcat-ref_tabname. "Reference table
CASE ls_fieldcat-fieldname.
WHEN 'LUGGWEIGHT' OR 'FORCURAM'.
ls_fcat-edit = 'X'.
ls_fcat-do_sum = 'X'.
WHEN 'URL'.
ls_fcat-no_out = 'X'.
WHEN OTHERS.
ls_fcat-edit = ' '.
ls_fcat-do_sum = ' '.
ENDCASE.
APPEND ls_fcat TO lt_fcat.
ENDLOOP.
ENDFORM. " build_field_catalgue
Regards
Kathirvel
Hi
Look in the example programs BCALV_GRID_05 and BCALV_GRID_06. I hope this will solve this problem.
Thanks and Regards
Amit
2007 Feb 10 2:29 PM
use sel_mode.
data : g_layout type slis_layout_alv.
g_layout-sel_mode = 'A'.
2007 Apr 10 2:08 PM
2007 Apr 11 4:53 PM
Hi,
I'm comfused:
I got a syntax error for
The data object "P_ALV_LAYOUT" has no component called "SEL_MODE", but there is a component called "EDIT_MODE".
FORM alv_layout CHANGING p_alv_layout TYPE slis_layout_alv.
p_alv_layout-colwidth_optimize = c_true.
p_alv_layout-detail_initial_lines = c_true.
p_alv_layout-zebra = c_true.
* p_alv_layout-f2code = '&IC1'.
p_alv_layout-min_linesize = 132.
p_alv_layout-coltab_fieldname = 'COLOUR'.
p_alv_layout-box_fieldname = 'SEL'.
p_alv_layout-sel_mode = 'D'.
ENDFORM. " ALV_LAYOUT
I know this is possible with OO cl_salv_display_settings
Selection Code Constant Value
No selection NONE 0
Single selection SINGLE 1
Multiple selection MULTIPLE 2
Cell selection CELL 3
Row and column selection ROW_COLUMN 4With ALV functional the behaviour changes if a boxfieldname is set in layout
p_alv_layout-box_fieldname = 'SEL' switches from line to cell selection.
Regards,
Clemens
2007 Feb 10 2:59 PM
Check this example,
*&---------------------------------------------------------------------*
*& Report ZKB_ALV_GRID
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zkb_alv_grid.
DATA: BEGIN OF i_scarr_tab OCCURS 0.
INCLUDE STRUCTURE scarr.
DATA: END OF i_scarr_tab.
DATA: i_scarr LIKE TABLE OF i_scarr_tab WITH HEADER LINE,
w_scarr LIKE LINE OF i_scarr_tab.
DATA: o_grid TYPE REF TO cl_gui_alv_grid,
o_container TYPE REF TO cl_gui_custom_container.
DATA: lt_fcat TYPE lvc_t_fcat,
ls_layo TYPE lvc_s_layo,
ls_sort TYPE lvc_s_sort,
lt_sort TYPE lvc_t_sort,
ls_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
START-OF-SELECTION.
CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*& Module status_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS '9000'.
SET TITLEBAR '9000'.
ENDMODULE. " status_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module user_command_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
CASE sy-ucomm .
WHEN 'BACK' OR 'EXIT'.
SET SCREEN 0.
LEAVE SCREEN.
ENDCASE.
ENDMODULE. " user_command_9000 INPUT
*&---------------------------------------------------------------------*
*& Module init_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE init_9000 OUTPUT.
IF o_container IS INITIAL.
SELECT * FROM scarr INTO CORRESPONDING FIELDS OF TABLE
i_scarr UP TO 100 ROWS.
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
* Create a custom container control for ALV Control
CREATE OBJECT o_container
EXPORTING
container_name = 'CONTROL'.
* Create a ALV Control
CREATE OBJECT o_grid
EXPORTING i_parent = o_container.
PERFORM build_field_catalgue.
ls_layo-sel_mode = 'A'.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
i_save = 'A'
i_default = 'X'
is_layout = ls_layo
CHANGING
it_outtab = i_scarr[]
it_fieldcatalog = lt_fcat
it_sort = lt_sort[].
ENDIF.
ENDIF.
ENDMODULE. " init_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Form build_field_catalgue
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_field_catalgue .
DATA: ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-cprog
i_internal_tabname = 'I_SCARR_TAB'
i_structure_name = 'SCARR'
* i_client_never_display = 'X'
CHANGING
ct_fieldcat = ls_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE 'FCAT Error' TYPE 'I'.
EXIT.
ENDIF.
LOOP AT ls_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = ls_fieldcat-fieldname. "Fieldname
ls_fcat-ref_table = ls_fieldcat-tabname. "DDIC ref struct
ls_fcat-inttype = ls_fieldcat-inttype. "Data type
ls_fcat-outputlen = ls_fieldcat-outputlen. "Column width
ls_fcat-coltext = ls_fieldcat-seltext_m. "Column Header
ls_fcat-seltext = ls_fieldcat-seltext_m. "Column Desc
ls_fcat-ref_field = ls_fieldcat-ref_fieldname. "Reference field
ls_fcat-ref_table = ls_fieldcat-ref_tabname. "Reference table
CASE ls_fieldcat-fieldname.
WHEN 'LUGGWEIGHT' OR 'FORCURAM'.
ls_fcat-edit = 'X'.
ls_fcat-do_sum = 'X'.
WHEN 'URL'.
ls_fcat-no_out = 'X'.
WHEN OTHERS.
ls_fcat-edit = ' '.
ls_fcat-do_sum = ' '.
ENDCASE.
APPEND ls_fcat TO lt_fcat.
ENDLOOP.
ENDFORM. " build_field_catalgue
Regards
Kathirvel
2007 Feb 10 3:02 PM
Hai,
Set the following layout attribute.
g_r_layo TYPE lvc_s_layo.
g_r_layo-sel_mode = 'A'.
If useful reward points.
Regards,
Umasankar
2007 Feb 10 4:52 PM
Hello,
For multiple selections in <b>ALV GRID</b>,you have to pass a layout structure in the method <b>SET_TABLE_FOR_FIRST_DISPL</b><b>AY</b>.For ex:
<b>DATA:gs_layout TYPE lvc_s_layo.
gs_layout-sel_mode = 'A'.</b>
CALL METHOD gv_alv->set_table_for_first_display
EXPORTING
is_layout = <b>gs_layout</b>
You can append A,B,C,D based on your requirements.
<b>'A'</b>
Column and row selection
Multiple columns
Multiple rows
The user selects the rows through pushbuttons at the left border of the grid control.
<b>'B'</b>
Simple selection, list box
Multiple columns
Multiple rows
<b>'C'</b>
Multiple selection, list box
Multiple columns
Multiple rows
<b>'D'</b>
Cell selection
Multiple columns
Multiple rows
Any cells
The user selects the rows through pushbuttons at the left border of the grid control.
To select 3 rows,press SHIFT continuously and click on the three records.
Also download this PDF :
Regards,
Beejal
**Reward if this is helpful
<b></b>
2007 Feb 10 5:58 PM
Hi,
using classical ALV function modules you need a SEL flag field in the display table. In layout, set alv_layout-box_field name = 'SEL'. In field catalog, mark tis field as technical (<alv_fieldcat>-tech = c_true).
Automatically you get row select buttons and 'select all' /'deselect all' buttons in menu.
All selected rows get the SEL field set.
In OO ALV it works as already described; there a CTRL-C will copy selected rows to clipboard.
Regards,
Clemens
2007 Feb 10 7:53 PM
hi
good
go through this link,this ll help you to solve your problem
http://www.supinfo-projects.com/fr/2005/alv_display_fr/2/
thanks
mrutyun^
2007 Feb 11 10:22 PM
Hi
Look in the example programs BCALV_GRID_05 and BCALV_GRID_06. I hope this will solve this problem.
Thanks and Regards
Amit
2007 Feb 11 10:26 PM
Hi
Look in the example programs BCALV_GRID_05 and BCALV_GRID_06. I hope this will solve this problem.
Thanks and Regards
Amit
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |