cancel
Showing results for 
Search instead for 
Did you mean: 

ALV List in the same Column for the row CELL i need button or value

Former Member
0 Kudos

Hi,

In my ALV list for the same column I need Button or Value for the different rows (CELL) depending upon my condition.

as well as I have to make read only of 3 rd column CELL based on my first column dropdown value CELL for this Row Only.

Depends upon the value in column 1 / row 2 I have to read only the CELL of column 5 / row 2 ie for the same row.

Depends upon the value in Column 1/ row 3 I have to EDITABLE or Button the CELL of column 5 / row 3 ie for the same row

How to do the logic for this.

I tried and got it for the entire column only.

But my requirement is for the sepecific cell in the column.

Kindly help to proceed further.

Thanks in advance.

Dav

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Here is how you can make a particular cell in the row read-only based on certain conditions.

In my example I am displaying the flight details in an ALV. Here I am checking the airline id and if it is "AA' I am making the cell in the column airline id as readonly. In my example I am putting a check and readonly on the same column. However you can do this for different columns as well.

In order to achieve this you need to add a new context attribute 'READONLY' of type abap_bool to the context node which is bound to data node of ALV.

The method where I populate the node has the following code to populate the data.


  data: lr_input_node type ref to if_wd_context_node,
        lr_flight_node type ref to if_wd_context_node,
        lv_cityfrom   type s_from_cit,
        lv_cityto     type s_to_city,
        ls_from       type bapisfldst,
        ls_to         type bapisfldst,
        lt_flights    type table of bapisfldat,
        ls_flights    type bapisfldat.

  data: lt_final type if_mainview=>elements_node_flighttab,
        ls_final type if_mainview=>element_node_flighttab.

* Instantiate the variable lr_input_note to the node NODE_FLIGHT
  lr_input_node  = wd_context->get_child_node( name = 'NODE_FLIGHT' ).

* Instantiate the variable lr_flight_note to the node NODE_FLIGHTTAB
  lr_flight_node = wd_context->get_child_node( name = 'NODE_FLIGHTTAB' )
.

* Get the attributes CityFrom und CityTo
  lr_input_node->get_attribute( exporting name = 'CITYFROM'
                                importing value = lv_cityfrom ).
  lr_input_node->get_attribute( exporting name = 'CITYTO'
                                importing value = lv_cityto ).

* Fill the stuctures ls_from and ls_to
  ls_from-city = lv_cityfrom.
  ls_to-city   = lv_cityto.

* Call the function BAPI_FLIGHT_GETLIST
  call function 'BAPI_FLIGHT_GETLIST'
   exporting
     destination_from       = ls_from
     destination_to         = ls_to
   tables
     flight_list            = lt_flights.

Now I am going to check if the airline id is 'AA' and based on that I will fill the readonly context attribute.


 loop at lt_flights into ls_flights.
    MOVE-CORRESPONDING ls_flights to ls_final.
    if ls_flights-airlineid = 'AA'.
      ls_final-readonly = abap_true.
    else.
      ls_final-readonly = abap_false.
    endif.
    append ls_final to  lt_final.
  endloop.

Finally bind the data to the context node.


* Bind the data to the node NODE_FLIGHTTAB
  lr_flight_node->bind_elements( lt_final ).

Now you need to do the ALV configuration settings.


* create an instance of ALV component
  DATA:
    lr_salv_wd_table_usage TYPE REF TO if_wd_component_usage.

  lr_salv_wd_table_usage = wd_this->wd_cpuse_alv( ).
  IF lr_salv_wd_table_usage->has_active_component( ) IS INITIAL.
    lr_salv_wd_table_usage->create_component( ).
  ENDIF.

* get ALV component
  DATA:
    lr_salv_wd_table TYPE REF TO iwci_salv_wd_table.

  lr_salv_wd_table = wd_this->wd_cpifc_alv( ).
  wd_this->alv_config_table = lr_salv_wd_table->get_model( ).

  CALL METHOD wd_this->alv_config_table->if_salv_wd_table_settings~set_read_only
    EXPORTING
      VALUE  = ABAP_FALSE
      .

* set visible row count
  DATA:
    lr_table_settings TYPE REF TO if_salv_wd_table_settings.

  lr_table_settings ?= wd_this->alv_config_table.
  lr_table_settings->set_visible_row_count( '10' ).

  DATA:
    lr_column_settings TYPE REF TO if_salv_wd_column_settings,
    lr_column          TYPE REF TO cl_salv_wd_column.
  
  lr_column_settings ?= wd_this->alv_config_table.

  DATA: lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.

  lr_column = lr_column_settings->get_column( 'AIRLINEID' ).

  CREATE OBJECT lr_input_field EXPORTING value_fieldname = 'AIRLINEID'.

  lr_column->set_cell_editor( lr_input_field ).

  lr_input_field->set_read_only_fieldname( value = 'READONLY' ).

  CALL METHOD lr_column_settings->delete_column
    EXPORTING
      id     = 'READONLY'
      .

Former Member
0 Kudos

Hi Pooja,

Thanks for the help.

In my requirement I need to get two controls( BUTTON and INPUTFIELD ) for the same column.

like BUTTON and INPUTFIELD for depending upon the value of the concerned .

pl help to give some details to proceed further..

Dav

Former Member
0 Kudos

You can use cell variants for this purpose.

You need to add a context attribute 'VARIANT' of type string to the context node which is bound to data node of ALV.

Here I am trying to display to display a button in the column airline if the airline id is 'AA" otherwise a input field.

Change the method where you fetch the data


  loop at lt_flights into ls_flights.
    move-corresponding ls_flights to ls_final.
    if ls_flights-airlineid = 'AA'.
      ls_final-readonly = abap_true.
      ls_final-variant = 'BT'.
    else.
      ls_final-readonly = abap_false.
      ls_final-variant = 'IN'.
    endif.
    append ls_final to  lt_final.
  endloop.

Add the following code to the method where you are doing ALV config settings.


* setting cell variants
  data: lr_column_airline type ref to cl_salv_wd_column.
  data: lr_cv type ref to cl_salv_wd_cv_standard.
  data: lr_button type ref to cl_salv_wd_uie_button.

  lr_column_airline = lr_column_settings->get_column( 'AIRLINE' ).

* Add cell variant input field
  create object lr_cv.

  call method lr_cv->set_key
    exporting
      value = 'IN'.

  create object lr_input_field exporting value_fieldname = 'AIRLINE'.

  call method lr_cv->set_editor
    exporting
      value = lr_input_field.

  call method lr_column_airline->add_cell_variant
    exporting
      r_cell_variant = lr_cv.


* Add cell variant button

  create object lr_cv.

  call method lr_cv->set_key
    exporting
      value = 'BT'.

  create object lr_button.

  call method lr_button->set_text
    exporting
      value  = 'Button'
      .

  call method lr_cv->set_editor
    exporting
      value = lr_button.

  call method lr_column_airline->add_cell_variant
    exporting
      r_cell_variant = lr_cv.

  call method lr_column_airline->set_sel_cell_variant_fieldname
    exporting
      value = 'VARIANT'.

Edited by: Pooja Patodia on Mar 14, 2011 12:42 PM

Former Member
0 Kudos

Hi Pooja,

I did exactly what you suggested and it worked perfectly. This was really amazing.

Thanks a lot,

Rajeev.