Selected rows sequence in ALV
Dear Fnds,
My requirement is, Iam displaying output data in ALV. in the output ALV i have 10 rows.
in the 10 rows if i select 5 rows(any rows), Example 3,7,1,2,5, Do we have any function module or class to determine the selected row sequence (which one we have selected as first, second and thrid etc.)
srinu reddy wrote:
Dear Fnds,
>
> My requirement is, Iam displaying output data in ALV. in the output ALV i have 10 rows.
>
> in the 10 rows if i select 5 rows(any rows), Example 3,7,1,2,5, Do we have any function module or class to determine the selected row sequence (which one we have selected as first, second and thrid etc.)
Hi,
I think you can achieve this thru GET CURSOR statement which will tell you current cursor position. I don`t think you can store it in a internal table to know the sequence.
Try, have a look at this document. http://help.sap.com/saphelp_470/helpdata/en/9f/dbabf135c111d1829f0000e829fbfe/content.htm
Hope, you find this useful.
Reetesh
Similar Messages
-
Edit a selected row in an alv report after pressing a push button ?
hi all ,
I want to edit a selected row in an alv report but that too after i press a push button . After pressing the push button , a pop up shud *** showing all the entries of the selected row which shud be editable and after editing it shud be saved into the database table.
How can i do this please help asap ???May this prog. of mine can solve your requirement.
REPORT z_demo_alv_jg.
TYPE-POOLS *
TYPE-POOLS: slis.
INTERNAL TABLES/WORK AREAS/VARIABLES *
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
i_index TYPE STANDARD TABLE OF i WITH HEADER LINE,
w_field TYPE slis_fieldcat_alv,
p_table LIKE dd02l-tabname,
dy_table TYPE REF TO data,
dy_tab TYPE REF TO data,
dy_line TYPE REF TO data.
FIELD-SYMBOLS *
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa> TYPE ANY,
<dyn_field> TYPE ANY,
<dyn_tab_temp> TYPE STANDARD TABLE.
SELECTION SCREEN *
PARAMETERS: tabname(30) TYPE c,
lines(5) TYPE n.
START-OF-SELECTION *
START-OF-SELECTION.
Storing table name
p_table = tabname.
Create internal table dynamically with the stucture of table name
entered in the selection screen
CREATE DATA dy_table TYPE STANDARD TABLE OF (p_table).
ASSIGN dy_table->* TO <dyn_table>.
IF sy-subrc <> 0.
MESSAGE i000(z_zzz_ca_messages) WITH ' No table found'.
LEAVE TO LIST-PROCESSING.
ENDIF.
Create workarea for the table
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
Create another temp. table
CREATE DATA dy_tab TYPE STANDARD TABLE OF (p_table).
ASSIGN dy_tab->* TO <dyn_tab_temp>.
SORT i_fieldcat BY col_pos.
Select data from table
SELECT * FROM (p_table)
INTO TABLE <dyn_table>
UP TO lines ROWS.
REFRESH <dyn_tab_temp>.
Display report
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_structure_name = p_table
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_PF_STATUS'
TABLES
t_outtab = <dyn_table>
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
*& Form SET_PF_STATUS
Setting custom PF-Status
-->RT_EXTAB Excluding table
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'Z_STANDARD'.
ENDFORM. "SET_PF_STATUS
*& Form user_command
Handling custom function codes
-->R_UCOMM Function code value
-->RS_SELFIELD Info. of cursor position in ALV
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
Local data declaration
DATA: li_tab TYPE REF TO data,
l_line TYPE REF TO data.
Local field-symbols
FIELD-SYMBOLS:<l_tab> TYPE table,
<l_wa> TYPE ANY.
Create table
CREATE DATA li_tab TYPE STANDARD TABLE OF (p_table).
ASSIGN li_tab->* TO <l_tab>.
Create workarea
CREATE DATA l_line LIKE LINE OF <l_tab>.
ASSIGN l_line->* TO <l_wa>.
CASE r_ucomm.
When a record is selected
WHEN '&IC1'.
Read the selected record
READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX
rs_selfield-tabindex.
IF sy-subrc = 0.
Store the record in an internal table
APPEND <dyn_wa> TO <l_tab>.
Fetch the field catalog info
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = 'Z_DEMO_PDF_JG'
i_structure_name = p_table
CHANGING
ct_fieldcat = i_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc = 0.
Make all the fields input enabled except key fields
w_field-input = 'X'.
MODIFY i_fieldcat FROM w_field TRANSPORTING input
WHERE key IS INITIAL.
ENDIF.
Display the record for editing purpose
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_structure_name = p_table
it_fieldcat = i_fieldcat
i_screen_start_column = 10
i_screen_start_line = 15
i_screen_end_column = 200
i_screen_end_line = 20
TABLES
t_outtab = <l_tab>
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc = 0.
Read the modified data
READ TABLE <l_tab> INDEX 1 INTO <l_wa>.
If the record is changed then track its index no.
and populate it in an internal table for future
action
IF sy-subrc = 0 AND <dyn_wa> <> <l_wa>.
<dyn_wa> = <l_wa>.
i_index = rs_selfield-tabindex.
APPEND i_index.
ENDIF.
ENDIF.
ENDIF.
When save button is pressed
WHEN 'SAVE'.
Sort the index table
SORT i_index.
Delete all duplicate records
DELETE ADJACENT DUPLICATES FROM i_index.
LOOP AT i_index.
Find out the changes in the internal table
and populate these changes in another internal table
READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX i_index.
IF sy-subrc = 0.
APPEND <dyn_wa> TO <dyn_tab_temp>.
ENDIF.
ENDLOOP.
Lock the table
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'E'
tabname = p_table
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc = 0.
Modify the database table with these changes
MODIFY (p_table) FROM TABLE <dyn_tab_temp>.
REFRESH <dyn_tab_temp>.
Unlock the table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'E'
tabname = p_table.
ENDIF.
ENDCASE.
rs_selfield-refresh = 'X'.
ENDFORM. "user_command
Regards,
Joy. -
How can I get the selected rows from two ALV grids at the same time?
I have a program that uses two ALV grids in one dialog screen. I'm using the OO ALV model (SALV* classes).
The user can select any number of rows from each grid. Then, when a toolbar pushbutton is pressed, I'd have to retrieve the selected rows from both grids and start some processing with these rows.
It is no problem to assign event handlers to both grids, and use the CL_SALV_TABLE->GET_SELECTIONS and CL_SALV_SELECTIONS->GET_SELECTED_ROWS methods to find out which rows were marked by the user. Trouble is, this only works when I raise an event in each grid separately, for instance via an own function that I added to the grid's toolbar. So, I can only see the selected rows of the same grid where such an event was raised.
If I try to do this in the PBO of the dialog screen (that contains the two grids), the result of CL_SALV_SELECTIONS->GET_SELECTED_ROWS will be empty, as the program does not recognize the marked entries in the grids. Also, an event for grid1 does not see the selected rows from grid2 either.
As it is right now, I can have an own button in both grid's toolbar, select the rows, click on the extra button in each grid (this will tell me what entries were selected per grid). Then, I'd have to click on a third button (the one in the dialog screen's toolbar), and process the selected rows from both grids.
How can I select the rows, then click on just one button, and process the marked entries from both grids?
Is it somehow possible to raise an event belonging to each grid programmatically, so that then the corresponding CL_SALV_SELECTIONS->GET_SELECTED_ROWS will work?
Thanks.Hello Tamas ,
If I try to do this in the PBO of the dialog screen (that contains the two grids), the result of CL_SALV_SELECTIONS->GET_SELECTED_ROWS will be empty, as the program does not recognize the marked entries in the grids. Also, an event for grid1 does not see the selected rows from grid2 either.--->
is it possible to have a check box in each grid & get the selected lines in PAI of the screen ?
regards
prabhu -
Detect selected row/column in ALV when clicking my button
Hello,
I use the cl_salv_table to display my ALV. I have implemented some double click events an so one. But now I like to be able detect u201Cselected row and coll when I press a button I my Application toolbar.
How do I get the selected row/column when pressing my button?
Regards,
KennethGive this a try:
class lcl_disp_code definition.
public section.
methods: disp_code
for event double_click
of cl_gui_alv_grid
importing es_row_no
e_column.
endclass. "lcl_disp_code DEFINITION
* CLASS lcl_disp_code IMPLEMENTATION
class lcl_disp_code implementation.
method disp_code.
perform restrict_data
using es_row_no-row_id.
endmethod. "on_double_click
endclass. "lcl_disp_code IMPLEMENTATION
Rob -
How to validate cells of selected rows in editable ALV
Hi,
I have created an ALV grid which is editable. Now I have entered the values in the grid, and selected some rows for which I need to validate the cells. But this is not happening. It is validating all the cells edited in the grid.
Can anyone help me...
Regards,
Satish Kanteti.Hi Satish,
Follow below steps,
1. Declare a additional field for selection flag in your internal table like below,
DATA: BEGIN OF g_t_vekp OCCURS 0,
flag(1) TYPE c, " <------ Flag for selection
venum TYPE vekp-venum,
exidv TYPE vekp-exidv,
vbeln_gen TYPE vekp-vbeln_gen,
END OF g_t_vekp.
2. Add extra parameter 'i_callback_user_command' in FM 'REUSE_ALV_GRID_DISPLAY'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_r_repid
i_callback_user_command = 'USER_COMMAND' " <------ Additional parameter
is_layout = g_wa_layout
it_fieldcat = g_t_fieldcat[]
TABLES
t_outtab = g_t_vekp
EXCEPTIONS
program_error = 1
OTHERS = 2.
3. Define a form 'USER_COMMAND' like below to check or save only selected rows.
FORM user_command USING l_r_ucomm LIKE sy-ucomm l_r_selfield TYPE slis_selfield.
CASE l_r_ucomm.
*Updating database when 'Save' is pressed
WHEN '&DATA_SAVE'.
LOOP AT g_t_vekp INTO g_wa_vekp WHERE flag = 'X'. " <---- Loop through only selected rows
" Ur operation on selected records
ENDLOOP.
ENDCASE.
l_r_selfield-refresh = 'X'.
ENDFORM. "user_command
Might solve ur problem.
Thanks,
Edited by: Sap Fan on Oct 13, 2009 5:10 PM -
How to get selected row no in ALV
Hi....
I am displaying a alv in sub screen...
I want to provide user functionality to delete records from alv..
The problem is i dont have a method to get row ids if user select multiple rows...
I tried using GET_ROW_ID but as its a protected method i cant use it..
please suggest stepwise how to use protected method in my class...and if u coud suggest some public method it will be great
regards
vivekHi,
You can also use the FM "REUSE_ALV_POPUP_TO_SELECT'.
It displays the output along with check boxes, where u can select the rows whatever u want.
Thanks & Regards,
Sudheer -
Get Row Data from a selected Row in an ALV Grid
Hello,
I create a Custom Control from an intern table. When i do a double click on a row, i call another dynpro. The data of the marked line should be written into an internal table.
How i implement this?
I tried things like:
Call method alv_list->GET_SELECTED_ROWS_BASE
or
Call method alv_list->GET_SELECTED_ROWSHi Sebastian,
For a double click event we need to register the double click event which goes the following way.
data: lref_alv type ref to cl_gui_alv_grid.
* after initializing ALV
SET HANDLER gref_application->handle_alv_dblclik FOR lref_alv.
Now this double click event needs to be handled in the local class.
eg:
CLASS lcl_application DEFINITION.
PUBLIC SECTION.
METHODS:
* Method to handle double click on ALV grid.............................
handle_alv_dblclik
FOR EVENT double_click
OF cl_gui_alv_grid
IMPORTING e_row
e_column
es_row_no.
endclass.
CLASS lcl_application IMPLEMENTATION.
* Method: HANDLE_ALV_DBLCLICK *
* Text: Event triggers when ALV grid is double clicked *
* -->e_row *
* -->e_column *
* -->es_row_no, *
METHOD handle_alv_dblclik.
data: lv_value(40) TYPE c.
* Get the value of the current cell double clicked......................
CALL METHOD gref_alv->get_current_cell
IMPORTING
e_value = lv_value
* here you can insert the values in the internal table
endmethod.
endclass.
hope this helps.
Regards,
Kinshuk -
ALV - How to set selected rows into internal table
Hi all,
I am tying to set with an 'X' flag the selected rows in my ALV using an internal table that contains all rows showed.
More exactly I have tried to follow these steps.
1) I have added the filed SEL (type SEL) to my ALV structure zrt_bo_slabsend and I defined my internal table in this way
DATA: gt_report TYPE STANDARD TABLE OF zrt_bo_slabsend,
gw_report TYPE zrt_bo_slabsend.
2) I have set gw_layo-box_fname = 'SEL' to gw_layo (ALV layout)
Pressing the "delete button" that I have insert on the top of the ALV, I intercept correctly my user command and I call a form (named "delete_lines") where I have this abap code
FORM delete_lines.
DATA: l_subrc LIKE sy-subrc,
lw_grid_settings LIKE lvc_s_glay.
gw_layo-box_fname = 'SEL'.
"set field name to store row selection
gw_layo-edit = 'X'. "makes whole ALV table editable
gw_layo-zebra = 'X'.
gv_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY_LVC'
exporting
i_callback_program = gv_repid
i_callback_pf_status_set = gc_status
i_callback_user_command = gc_user_command
is_layout_lvc = gw_layo
it_fieldcat_lvc = gw_fkat
i_grid_settings = lw_grid_settings
i_save = 'X'
is_variant = variant
it_events = gt_events
TABLES
t_outtab = gt_report
EXCEPTIONS
program_error = 1
OTHERS = 2.
LOOP AT gt_report ASSIGNING <report> WHERE SEL = 'X'.
DELETE gt_report.
ENDLOOP.
ENDFORM.
I'd like to select many rows in my ALV report, than by pressing the delete button I'd like to see a refresh of my ALV, without the selected rows. I want to save it only at the end of my action, only by pressing the save button.
Any suggestion about the abap code will be well appreciated.
Thanks in advance for your kind help.
Regards.
GiovanniHi Giovanni,
I am using the method:-
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
I_CALLBACK_PROGRAM = gd_REPID
I_CALLBACK_PF_STATUS_SET = 'UDIT'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
I_GRID_TITLE = 'Mainatin cell entry'
* I_GRID_SETTINGS =
IS_LAYOUT_LVC = GS_LAYOUT
IT_FIELDCAT_LVC = I_FIELDCAT[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS_LVC =
* IT_SORT_LVC =
* IT_FILTER_LVC =
* IT_HYPERLINK =
* IS_SEL_HIDE =
I_DEFAULT = 'X'
* I_SAVE = 'X'
* IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
* IS_PRINT_LVC =
* IS_REPREP_ID_LVC =
I_SCREEN_START_COLUMN = 30
I_SCREEN_START_LINE = 14
I_SCREEN_END_COLUMN = 120
I_SCREEN_END_LINE = 25
* IT_EXCEPT_QINFO_LVC =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_ZCP_DEMAND_SYS1
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
I have made five buttons on my toolbar (add, delete, save, back, exit).
Kindly tell me how can I catch the sy-ucomm of these buttons.
NOTE: this FM is written inside an user-exit, so I cannot make forms.
Thanks in advance. -
Selected rows in ALV to a file .txt
Hi all, I need to generate a File (.txt) from the selected rows of an alv.
Please, i need if you can help me with that. I have to especify the name of the file with "concatenate" and inside the file, the data must be separated with ' ; '
Thanks in advance.
JCOHi
First separate the data of the selected lines in the ALV output into an internal table
then download the data from that ITAb into a file separated by the separator( string using GUI_DOWNLOAD or some other fun module
Regards
Anji -
ALV Grid OO : Set Field editable for selected rows
Hello ABAPers,
I used object cl_gui_alv_grid to created ALV grid and i succed to set an editable
field for all rows. However my request is to set it for and only for selected rows
I could get the row index but i didn't know how to use it
Thanks in advance
AmineHi Amine,
I think the standard SAP sample program might help you, BCALV_EDIT_02.
I will tell the procedure to make the selected rows editable on ALV.
1. Add a additional field of type LVC_T_STYL in the internal table that you are displaying in the ALV. LVC_T_STYL is a actually a table type.
2. Place a button on the ALV toolbar for EDIT/DISPLAY.
3. Once you press the EDIT button after selecting the rows, loop through the records which you have selected (you have already said that you have the index of selected records).
4. The table type LVC_T_STYL has fields for FIELDNAME and STYLE.
If you have 10 fields in the internal table, then all these ten fields name should be appended to the newly added field in the internal table (LVC_T_STYL) and their style should be populated with value cl_gui_alv_grid=>mc_style_enabled.
Regards,
Rahul MB -
Displaying the selected rows in ALV Grid output
Hi Experts,
I am developing one interactive ALV Grid report where user can process the selected records/rows from the ALV Grid output.
for displaying the ALV Grid, I have used the class CL_GUI_ALV_GRID class. I am working on ECC 6.0 system.
when I select any records/rows from output and then press any Application Toolbar button, PAI and then PBO modules of the screen gets executed as per the normal flow.
however After PBO, when same ALV output comes, all the selected/highlighted rows appear as unselected, that means I want to retain the ALV
rows selection during the round trip.
please advise.
Regards,
JageshHi,
Feiyun Wu is correct.
Get_selected_rows and set_selected_rows are the methods to be used .
Some code:
Note the sequence of code:
FORM set_gui_alv_grid_1 .
DATA: wa_layout TYPE lvc_s_layo ,
wa_print TYPE lvc_s_prnt .
DATA: it_sort TYPE lvc_t_sort ,
wa_sort TYPE LINE OF lvc_t_sort .
DATA: it_fieldcatalog TYPE lvc_t_fcat.
IF gui_custom_container_1 IS INITIAL .
CREATE OBJECT gui_custom_container_1
EXPORTING
container_name = 'GUI_CUSTOM_CONTAINER_1'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6 .
IF sy-subrc <> 0.
ENDIF.
PERFORM get_field_catalog
USING gc_log_group_1
CHANGING it_fieldcatalog .
CREATE OBJECT gui_alv_grid_1
EXPORTING i_parent = gui_custom_container_1.
CREATE OBJECT ob_event_receiver_1
EXPORTING log_group = gc_log_group_1 .
* registers the event handlers
SET HANDLER ob_event_receiver_1->handle_toolbar FOR gui_alv_grid_1 .
SET HANDLER ob_event_receiver_1->handle_user_command FOR gui_alv_grid_1 .
SET HANDLER ob_event_receiver_1->print_top_of_page FOR gui_alv_grid_1 .
SET HANDLER ob_event_receiver_1->hotspot_click FOR gui_alv_grid_1 .
wa_layout-cwidth_opt = abap_true .
* wa_layout-excp_fname = gc_excp_fname .
* wa_layout-ctab_fname = gc_ctab_fname.
* wa_layout-excp_led = abap_true .
CALL METHOD gui_alv_grid_1->set_table_for_first_display
EXPORTING
is_layout = wa_layout
is_print = wa_print
i_save = 'A'
is_variant = gs_disvariant_1
CHANGING
it_sort = it_sort
it_fieldcatalog = it_fieldcatalog
it_outtab = it_alv_grid_1.
ELSE .
CALL METHOD gui_alv_grid_1->refresh_table_display.
* Restore selections
CALL METHOD gui_alv_grid_1->set_selected_rows
EXPORTING
it_index_rows = ob_event_receiver_1->it_rows.
* Restore position
CALL METHOD gui_alv_grid_1->set_scroll_info_via_id
EXPORTING
is_col_info = ob_event_receiver_1->wa_col
is_row_no = ob_event_receiver_1->wa_roid.
ENDIF.
ENDFORM . "set_gui_alv_grid_1
Regards. -
Urgent : how to select the rows in the ALV Grid Control
How to select the rows in the ALV Grid control,
I am facing the situation where i need to select the row/rows in the Grid control and then to lock the entries,
If anyone have the solution please help me out
<b>Its very Urgent</b>Hi Bharath,
Go through this hope u can understand.
SEL_MODE. Selection mode, determines how rows can be selected. Can have the following values:
A Multiple columns, multiple rows with selection buttons.
B Simple selection, listbox, Single row/column
C Multiple rows without buttons
D Multiple rows with buttons and select all ICON
Setting and getting selected rows (Columns) and read line contents
You can read which rows of the grid that has been selected, and dynamic select rows of the grid using methods get_selected_rows and set_selected_rows. There are similar methods for columns.
Note that the grid table always has the rows in the same sequence as displayed in the grid, thus you can use the index of the selected row(s) to read the information in the rows from the table. In the examples below the grid table is named gi_sflight.
Data declaration:
DATA:
Internal table for indexes of selected rows
gi_index_rows TYPE lvc_t_row,
Information about 1 row
g_selected_row LIKE lvc_s_row.
Example 1: Reading index of selected row(s) and using it to read the grid table
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows.
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines = 0.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'You must choose a valid line'.
EXIT.
ENDIF.
LOOP AT gi_index_rows INTO g_selected_row.
READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
ENDIF.
ENDLOOP.
Example 2: Set selected row(s).
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines > 0.
CALL METHOD go_grid->set_selected_rows
exporting
it_index_rows = gi_index_rows.
ENDIF.
Reward points if helpful.
Thanks
Naveen khan -
I have an ALV that displays a list, each row of the list has a Checkbox so is possible to select specific rows for further processing, my question is:
How can I get the selected rows in the exact sequence in which were selected?Hello
There is a simple and a more elaborate answer to your question:
<i>Simple answer: </i>You cannot. The ALV grid has no kind of "memory" which would store this information.
<i>Elaborate answer:</i> You can, but you have to implement the logic yourself. You may use sample report <b>ZUS_SDN_ALVGRID_EDITABLE_9</b> as template. Please note that I did not elaborate the logic when a checkbox is <b><u>de</u></b>selected.
*& Report ZUS_SDN_ALVGRID_EDITABLE_9
*& Description: store sequence of marked checkboxes
REPORT zus_sdn_alvgrid_editable_9.
TYPE-POOLS: abap.
DATA:
gd_repid TYPE syrepid,
gd_okcode TYPE ui_func,
gs_layout TYPE lvc_s_layo,
gt_fcat TYPE lvc_t_fcat,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gt_outtab TYPE ty_t_outtab,
gt_outtab_mark TYPE ty_t_outtab,
gt_marked_rows TYPE lvc_t_row.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING
er_data_changed
e_onf4
e_onf4_before
e_onf4_after
e_ucomm
sender,
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender. " grid instance that raised the event
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
method handle_data_changed.
endmethod.
METHOD handle_hotspot_click.
* define local data
DATA:
ld_msg TYPE bapi_msg,
ls_outtab TYPE ty_s_outtab,
ls_col_id TYPE lvc_s_col.
READ TABLE gt_outtab INTO ls_outtab INDEX e_row_id-index.
IF ( ls_outtab-loevm = abap_false ).
ls_outtab-loevm = abap_true.
modify gt_outtab from ls_outtab index e_row_id-index.
APPEND ls_outtab TO gt_outtab_mark.
APPEND e_row_id TO gt_marked_rows.
WRITE e_row_id-index TO ld_msg NO-ZERO.
CONDENSE ld_msg NO-GAPS.
CONCATENATE 'Row' ld_msg 'selected'
INTO ld_msg
SEPARATED BY space.
MESSAGE ld_msg TYPE 'S'.
ELSE.
ls_outtab-loevm = abap_false.
modify gt_outtab from ls_outtab index e_row_id-index.
DELETE gt_outtab_mark WHERE ( kunnr = ls_outtab-kunnr
AND bukrs = ls_outtab-bukrs ).
ENDIF.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'DUMMY' " trigger PAI
* IMPORTING
* RC =
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_outtab UP TO 20 ROWS
WHERE bukrs = '1000'.
REFRESH: gt_outtab_mark.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grid
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Build fieldcatalog
PERFORM build_fieldcatalog.
PERFORM set_layout.
SET HANDLER:
lcl_eventhandler=>handle_data_changed for go_grid,
lcl_eventhandler=>handle_hotspot_click FOR go_grid.
* Display data
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fcat
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
* Flow logic (no elements on screen):
* PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
* PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
CALL METHOD go_grid->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
finished = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
TRANSLATE gd_okcode TO UPPER CASE.
* Fetch changes on ALV grid
go_grid->check_changed_data( ).
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'DISPLAY'.
PERFORM display_data.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form BUILD_FIELDCATALOG_KNB1
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'KNB1'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
" Set required fields editable
LOOP AT gt_fcat INTO ls_fcat
WHERE ( fieldname = 'LOEVM' ).
ls_fcat-edit = abap_true.
ls_fcat-checkbox = abap_true.
ls_fcat-hotspot = abap_true.
MODIFY gt_fcat FROM ls_fcat.
ENDLOOP.
DELETE gt_fcat WHERE ( fieldname = 'ZINRT' ).
ENDFORM. " BUILD_FIELDCATALOG
*& Form SET_LAYOUT
* text
* --> p1 text
* <-- p2 text
FORM set_layout .
CLEAR: gs_layout.
gs_layout-cwidth_opt = abap_true.
gs_layout-zebra = abap_true.
** gs_layout-stylefname = 'CELLTAB'.
ENDFORM. " SET_LAYOUT
*& Form SAVE_DATA
* text
* --> p1 text
* <-- p2 text
FORM display_data .
* define local data
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_structure_name = 'LVC_S_ROW'
i_grid_title = 'Selected Rows'
TABLES
t_outtab = gt_marked_rows
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_DATA
Regards,
Uwe -
Select row button not getting displayed in alv grid.
Hi ,
As per my requirement I am using tab strip in module pool.
Each tab strip is containing one ALV.
And user can change delete or create one record when the alv is displayed.
The same should be saved in the database and ALV should be refreshed.
When I am displaying the ALV the left most option of the ALV with which I can select the whole row is not coming.
Because of which I am unable to call the method to get the selected row and delete or change accordingly.
Why this button is not coming?
I am using set_table_for_first_display in my program.
Please help.Hi,
In the method SET_TABLE_FOR_FIRST_DISPLAY, you will have to change the Selection Mode to 'A'. I guess you are not passing any values to the Layout parameters.
Once you do that, you will find what your are looking for.
Data : LA_LAYO type LVC_S_LAYO.
LS_LAYO_SEL_MODE = 'A'.
and pass this to the method's layout parameter.
Cheers,
SKC, -
ALV GRID - Handling selected rows? Sorting in OUTTAB is different from ALV
Dear Experts ,
I have a transaction with ALV grid. I have defined several application specific functions to the ALV grid tool bar. My requirement is to handle the ALV tool bar functions only for the selected rows.
Code snippet:
DATA:
LS_GRID_DS TYPE TYS_DS.
TYPES: BEGIN OF TYS_DS.
INCLUDE TYPE TYS_ALVGRID.
TYPES: STRUCNAME LIKE DD02L-TABNAME.
TYPES: PRETAB TYPE ZTAB_T,
OUTTAB TYPE ZTAB_T,
OUTTAB_HIDDEN TYPE ZTAB_T,
OUTTAB_SUM TYPE ZTAB_T,
OUTTAB_ROLLBACK TYPE ZTAB_T,
END OF TYS_DS.
LOOP AT ls_grid_ds-marked_rows INTO ss_index_split
WHERE rowtype IS INITIAL.
( Marked rows is correctly giving the row numbers of the highlighted rows)
READ TABLE ls_grid_ds-outtab INTO ss_sel_rows_ds_split
INDEX ss_index_split-index.
ISSUE : Sorting in ls_grid_ds-outtab internal table is different from ALV Grid display.
Hence, though ls_grid_ds-marked_rows giving correct rows, I am not able to handle the my requirement correctly.
Why sorting in gs_grid_ds-outtab is different from ALV display? How can they made in sync?
Thank you in Advance.
Sravan.
Edited by: Raja Sravan on Jan 16, 2009 1:13 AMHello Raja
The OUTTAB is usually in sync with the display on the frontend grid control because it is a CHANGING parameter (of method SET_TABLE_FOR_FIRST_DISPLAY).
Question: Do you "feed" ls_grid_ds-outtab to the parameter IT_OUTTAB of method SET_TABLE_FOR_FIRST_DISPLAY?
If not then it is obvious why you get discrepancies.
Regards
Uwe
Maybe you are looking for
-
Schedule Line Delivery Date Calculation with Transportation Scheduling
Hi All, We are currently running into a problem where our Sales Order Schedule Line delivery dates are being pushed out too far into the future - because of the Calendar being used to determine the transit time. We have 'Delivery Scheduling' and 'Tra
-
Hello All at Apple Support, I have a 2009 iMac and it's time to replace the hard drive before it fails. I've searched a lot of sites and found this hard drive: Toshiba (by Hitachi) 2.0TB DT01ACAxx series (3.5 inch SATA 6GB/7200rpm/64mb cache) at Othe
-
Please Advise: iPod mini 1st gen. questions and issues
Hi all, thanks for your attention! I have, what I believe, is a 1st generation iPod mini - I purchased it in early/mid 2004. I love it, and don't want to just trade it in for one of the newer ones, that do 5 million more things than I really need. I
-
Hi all, I am using weblogic as the producer and plumtree as the consumer. I have configured for ConsumerURL rewriting by specifying it in the wsrp-producer-config.xml, but the soap request for the getMarkUp to weblogic is still containing the Templat
-
Hello, I want my Air application to have a titlebar like the 'Adobe Media Player'. I want it to have a custom logo, buttons, etc. in it. Does anyone know how to this? thanks a lot, Peter Vermeulen Belgium