cancel
Showing results for 
Search instead for 
Did you mean: 

Capturing the selected rows of the tableview .

Former Member
0 Kudos

HI all,

I have a requirement to capture the selected row of a tableview and display some of the fields of this selected row in another tableview.This should automatically be done as soon as one selects a record in the parent tableview.

Can anyone help me in this regard?????

Thanks in Advance,

Chandana.

Accepted Solutions (1)

Accepted Solutions (1)

raja_thangamani
Active Contributor
0 Kudos

Here is the logic to get the selected rows..


  DATA: tv          type ref to CL_HTMLB_TABLEVIEW,
        event       type ref to CL_HTMLB_EVENT,
        table_event type ref to CL_HTMLB_EVENT_TABLEVIEW.
  field-symbols <i> like line of selectedRowIndexTable.

  tv ?= CL_HTMLB_MANAGER=>GET_DATA( request = request
                                    name    = 'tableView'
                                    id      = 'tvX' ).
  IF tv IS NOT INITIAL.
    table_event = tv->data.
    clear selectedRowIndexTable.
    selectedRowIndexTable = table_event->PREVSELECTEDROWINDEXTABLE.

    if table_event->event_type eq CL_HTMLB_EVENT_TABLEVIEW=>CO_ROW_SELECTION.
      read table selectedRowIndexTable with key table_line = table_event->ROW_INDEX
        transporting no fields.
      if sy-subrc eq 0.
        delete selectedRowIndexTable index sy-tabix.
      else.
        append initial line to selectedRowIndexTable assigning <i>.
        <i> = table_event->ROW_INDEX.
      endif.
    endif.
  ENDIF.

Once you have selected Rows in Tableview 1 then pass it to Tableview 2.

Hope this will solve your issue.

Raja T

Answers (5)

Answers (5)

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi Raja,

Thanks a lot .My issue is solved .Your code was of great help.

Thanks and Regards,

Chandana.

raja_thangamani
Active Contributor
0 Kudos

If your issue is resolved, reward & close the thread...

Raja T

Former Member
0 Kudos

Hi Raja,

I have tried your code .I am getting an error message saying" ind1 cannot be converted to the line type of selectedRowIndexTable".

Can you please suggest a solution to correct this error?

Regards,

Chandana.

raja_thangamani
Active Contributor
0 Kudos

Corrected code..

selected_ind	TYPE	INT4_TABLE

  DATA: TV          TYPE REF TO CL_HTMLB_TABLEVIEW,
        EVENT       TYPE REF TO CL_HTMLB_EVENT,
        TABLE_EVENT TYPE REF TO CL_HTMLB_EVENT_TABLEVIEW.
  FIELD-SYMBOLS <I> LIKE LINE OF SELECTED_IND.

  TV ?= CL_HTMLB_MANAGER=>GET_DATA( REQUEST = REQUEST
                                    NAME    = 'tableView'
                                    ID      = 'tv' ).
  IF TV IS NOT INITIAL.
    TABLE_EVENT = TV->DATA.
    CLEAR  SELECTED_IND.
    SELECTED_IND = TABLE_EVENT->PREVSELECTEDROWINDEXTABLE.

    IF TABLE_EVENT->EVENT_TYPE EQ CL_HTMLB_EVENT_TABLEVIEW=>CO_ROW_SELECTION.
      READ TABLE  SELECTED_IND WITH KEY TABLE_LINE = TABLE_EVENT->ROW_INDEX
        TRANSPORTING NO FIELDS.
      IF SY-SUBRC EQ 0.
        DELETE  SELECTED_IND INDEX SY-TABIX.
      ELSE.
        APPEND INITIAL LINE TO  SELECTED_IND ASSIGNING <I>.
        <I> = TABLE_EVENT->ROW_INDEX.
      ENDIF.
    ENDIF.

  ENDIF.

Former Member
0 Kudos

Hi ,

I have tried the following code.Everything is working fine ,but when I select i a record initially in parent tableview I am not able to view it in the second tableview at that instance.I am able to see the data of the first selected record in the second tableview only when i select the second record in the parent tableview.i.e The first selected record is display in the second tableview on selecting the next record in parent tableview.I am pasting the code below.

Can anyone help me track the problem.

when 'tv'.

event = CL_HTMLB_MANAGER=>get_event( runtime->server->request ).

if event->id = 'tv' and event->event_type = CL_HTMLB_EVENT_TABLEVIEW=>CO_ROW_SELECTION.

DATA: tv_data TYPE REF TO CL_HTMLB_EVENT_TABLEVIEW.

IF tv IS NOT INITIAL.

tv_data = tv->data.

if tv_data->event_type eq CL_HTMLB_EVENT_TABLEVIEW=>CO_ROW_SELECTION.

refresh itab2.

call method tv_data->GET_ROWS_SELECTED

receiving selected_rows = itab2.

endif.

data : ind1 type SELECTEDROW,

row_s1 type row,

rw1 type itab.

tv_data = tv->data.

if itab2 is not initial.

loop at itab2 into ind1.

READ TABLE ivisit_report INDEX ind1-index into

rw1.

if rw1 is not initial.

row_s1 = rw1.

endif.

endloop.

select * from zaction_item into corresponding fields of table iaction_item where vrname eq row_s1-vrname.

****(the table iaction_item is displayed in the second tableview)

endif.

endif.

Thanks in Advance,

Chandana.

raja_thangamani
Active Contributor
0 Kudos

Try the below code...I tested & its working..


data: selectedRowIndexTable TYPE	INT4_TABLE.
data : ind1 type SELECTEDROW,
field-symbols <i> like line of selectedRowIndexTable.

tv ?= CL_HTMLB_MANAGER=>GET_DATA( request = request
                                    name    = 'tableView'
                                    id      = 'tvX' ).
  IF tv IS NOT INITIAL.
    table_event = tv->data.
    clear selectedRowIndexTable.
    selectedRowIndexTable = table_event->PREVSELECTEDROWINDEXTABLE.
 
    if table_event->event_type eq CL_HTMLB_EVENT_TABLEVIEW=>CO_ROW_SELECTION.
      read table selectedRowIndexTable with key table_line = table_event->ROW_INDEX
        transporting no fields.
      if sy-subrc eq 0.
        delete selectedRowIndexTable index sy-tabix.
      else.
        append initial line to selectedRowIndexTable assigning <i>.
        <i> = table_event->ROW_INDEX.
      endif.
    endif.
  ENDIF.

* Here Itab selectedRowIndexTable will have all selected rows.

if  selectedRowIndexTable is not initial.

loop at  selectedRowIndexTable into ind1.

READ TABLE ivisit_report INDEX ind1-index into rw1.
 
 if rw1 is not initial.
  row_s1 = rw1.
 endif.
 endloop.
select * from zaction_item into corresponding fields of table iaction_item where vrname eq row_s1-vrname.
****(the table iaction_item is displayed in the second tableview)
endif.
endif.

Raja T