2007 Dec 06 4:07 PM
Hi,
I have an ALV gird display(using objects).I am getting the output in ALV.Now,I have a button (CHANGE)in the toolbar which is created by me,first the user will select the rows( or multiple rows) from ALV and then click on the CHANGE button(which is created by me),now how to I read the data selected by the user.?
I used the following code :
CASE e_ucomm.
WHEN 'CHANGE'.
CALL METHOD grid1-><b>get_selected_rows</b>
IMPORTING et_index_rows = lt_rows.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
ELSE.
CALL SCREEN 9001 STARTING AT 05 05
ENDING AT 40 12.
ENDIF.
ENDCASE.
............................................................
lt_rows gives me the index of the row that has been selected.But now how do I read the data corresponding to that index.
The data I am displaying in the ALV grid is stored in an Internal Table LT_DISPLAY.
Please help..its urgent.
Thanks.
2007 Dec 06 4:13 PM
You can use the READ statement
Like:
CASE e_ucomm.
WHEN 'CHANGE'.
CALL METHOD grid1->get_selected_rows
IMPORTING et_index_rows = lt_rows.
READ TABLE LT_DISPLAY INTO WA_DISPLAY INDEX IT_ROWS. " < get values
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
ELSE.
CALL SCREEN 9001 STARTING AT 05 05
ENDING AT 40 12.
ENDIF.
ENDCASE.
Regards,
Naimesh Patel
2007 Dec 06 4:13 PM
You can use the READ statement
Like:
CASE e_ucomm.
WHEN 'CHANGE'.
CALL METHOD grid1->get_selected_rows
IMPORTING et_index_rows = lt_rows.
READ TABLE LT_DISPLAY INTO WA_DISPLAY INDEX IT_ROWS. " < get values
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
ELSE.
CALL SCREEN 9001 STARTING AT 05 05
ENDING AT 40 12.
ENDIF.
ENDCASE.
Regards,
Naimesh Patel
2007 Dec 06 4:31 PM
Hi,
thanks for that, even i thought that read would work.but it is giving me an error saying " LT_ROWS cannot be a table ,a reference ,a string or contain any of these objects".
what to do ?
2007 Dec 06 4:36 PM
Try like this
READ TABLE LT_DISPLAY INTO WA_DISPLAY INDEX LT_ROWS-ROW_ID.
Pavan
2007 Dec 06 4:37 PM
You need to use the INDEX field of the structure IT_ROWS.
DATA: WA_ROWS TYPE LVC_S_ROW.
READ TABLE IT_ROWS INTO WA_ROWS.
READ TABLE LT_DISPLAY INTO WA_DISPLAY INDEX <b>WA_ROWS-INDEX</b>.
Sorry, It's my mistaks.
Regards,
Naimesh Patel
2007 Dec 06 4:37 PM
Whats the value in LT_ROWS.
If it has a numeric value it should.
Shreekant
2007 Dec 06 4:42 PM
Hi,
This is the code :
DATA: t_display TYPE TABLE OF zstatchng ,
lt_display LIKE LINE OF t_display .
DATA: lt_rows TYPE lvc_t_row.
<b>READ TABLE t_display INTO lt_display INDEX lt_rows-index.</b>
when I try this, it gives me an error saying LT_ROWS is a table without header line so it has no component like INDEX.
What's the problem....when I debug and see , I get two fields for LT_ROWS one is ROWTYPE and one is index. if I select the first row, Rowtype is blank and Index is one....but the read is failing...dont know why..!!!!
2007 Dec 06 4:44 PM
Try like this:
DATA: WA_ROWS TYPE LVC_S_ROW.
READ TABLE IT_ROWS INTO WA_ROWS.
READ TABLE LT_DISPLAY INTO WA_DISPLAY INDEX WA_ROWS-INDEX.
Regards,
Naimesh Patel
2007 Dec 06 4:52 PM
Hi,
it asks for an Index in the statement READ TABLE IT_ROWS INTO WA_ROWS.
2007 Dec 06 4:58 PM
Oh ok,
Corrected:
DATA: WA_ROWS TYPE LVC_S_ROW.
READ TABLE IT_ROWS INTO WA_ROWS INDEX 1. " << I assume you will only select one record.
READ TABLE LT_DISPLAY INTO WA_DISPLAY INDEX WA_ROWS-INDEX.
if you want multiple records than,
LOOP AT IT_ROWS INTO WA_ROWS.
READ TABLE LT_DISPLAY INTO WA_DISPLAY INDEX WA_ROWS-INDEX.
ENDLOOP.
Regards,
Naimesh Patel
2007 Dec 06 5:10 PM
Hi ,
Now its working fine.Thanks a lot for your help...Awarded points to you.
Thanks Again.
Regards,
Deepti.
2007 Dec 06 4:17 PM
A simple Read statement Should work.
Eg,
Read Table lt_display index lt_rows.
It ilt_diaplay dosent have a header line,
A simple Read statement Should work.
Eg,
Read Table lt_display into wa_diaplay index lt_rows.
Hope it helps.
Shreekant