cancel
Showing results for 
Search instead for 
Did you mean: 

Set ALV Cell visibility property

Former Member
0 Kudos

Hi,

I would have 2 tables for ALV. One table consists of the data to be bound to the ALV. The other table would have the read only property(boolean) filled for each of the ALV cells.

I would want to set the property of each ALV cell using the second table. How do i do that?

Currently i am just testing it for few attributes statically using the below code.

-


DATA lo_nd_date_table TYPE REF TO if_wd_context_node.

DATA lo_el_date_table TYPE REF TO if_wd_context_element.

DATA: lt_ele_set TYPE wdr_context_element_set.

    • navigate from <CONTEXT> to <DATE_TABLE> via lead selection

lo_nd_date_table = wd_context->get_child_node( name = wd_this->wdctx_date_table ).

lt_ele_set = lo_nd_date_table->get_elements( ).

LOOP AT lt_ele_set INTO lo_el_date_table.

lo_el_date_table->set_attribute_property(

attribute_name = 'WK02' -


> Attribute Name (Column Name)

property = if_wd_context_element=>e_property-read_only

value = 'X' ).

<< Similarly for other attributes>>

ENDLOOP.

-


I have inserted this code at the end. Initially few other properties were set to the cells.

This seems to be not working.

Regards,

Rekha

Edited by: Rekha Gopinath on Sep 8, 2009 10:40 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You will have to create an extra attribute/column in your node/table that is bound to the ALV. say VISIBLE type boolean. Then read the data from you 2nd table and modify your table by setting the field visible as abap_true or abap_false. Check this wiki for details , [https://wiki.sdn.sap.com/wiki/display/WDABAP/How%20to%20edit%20conditionally%20row%20of%20a%20ALV%20table%20in%20Web%20Dynpro%20for%20ABAP] Radhika.

Former Member
0 Kudos

Hi Radhika,

Thanks for your reply.

Using the approach you have mentioned, i can maybe assign the entire row's property or maybe some cells property in the ALV.

-


Consider this scenario,

1. There are 4 rows with 15 columns for my node. I have a READ_ONLY Attribute for the node.

I want to set the following propeties:

Row 1: Cells for colums 1, 2, 3, 4, 5 are set to read only

Row 2: Cells for columns 1,2, 3, 4, 10, 11 are set to read only

Row 3: All cells are set to read only

Row 4: All cells are set to visible.

2. When i loop through the row records for setting read_only attribute value, based on what condition do i set the attribute to abap_true?

At the moment i am setting it true whenever even one of the cells in a row is set to abap_true

This way the READ_ONLY will have the following values set.

Row 1: X

Row 2: X

Row 3: X

Row 4: ' '

3. Later i loop through the columns as mentioned by you.

CREATE OBJECT lr_input

EXPORTING

value_fieldname = lv_id.

lo_column->set_cell_editor( value = lr_input ).

lr_input->set_read_only_fieldname( value = 'READ_ONLY' ).

wd_this->go_alv_model->if_salv_wd_column_settings~delete_column( id = 'READ_ONLY' ).

4. Output:

The output would be that row 1, row 2 and row 3 are set to read only. Row 4 is set to editable.

Whereas, if you see the properties i wanted to set in step 1, it is different.

Maybe the condition based on what i am setting READ_ONLY is not completely right. Can you provide me your suggestions?

Regards,

Rekha

Former Member
0 Kudos

Hi,,

On what basis are you setting the read only row wise...

For ex: if the row1...how are you setting it....

Do you want this setting for all the columns based on condition.

I guess you have created input field...for all columns right...

loop at lt_table into ls_Table.
if sy-tabix eq 1.
ls_table-read_only = abap_false.
else.
ls_table-read_only = abap_true.
endif.
modify lt_table from ls_table index sy-tabix.
clear ls_Table.
endloop.

First bind the table to node then do the column settings....

In the above code, first row is set to editable for those cells where the READONLY of column is applicable other than that it is not editable.

Why the visiblity feature is set...Do you want to hiode the columns... Then you can also set the value as read_only...as above by creating the context attribute.

Regards,

Lekha.

Former Member
0 Kudos

Hi Lekha,

In my case, the columns represents dates. The rows represent projects. So, only those row cells are editable where the project is valid.

1. I have created READ_ONLY attribute for the date node (table).

2. I am filling the READ_ONLY to abap_true or abap_false based on the following condition.

Even if one of the projects is not valid for a date, then READ_ONLY = ABAP_TRUE. This means, even if one cell is set to abap_true, then READ_ONLY is set to abap_true.

3. I modify the date node and bind it with the READ_ONLY set row wise.

  • Loop at the data and set read only

  • navigate from <CONTEXT> to <DATE_TABLE> via lead selection

lo_nd_date_table = wd_context->get_child_node( name = wd_this->wdctx_date_table ).

CALL METHOD lo_nd_date_table->get_static_attributes_table

IMPORTING

table = lt_date_table .

LOOP AT lt_date_table INTO ls_date_table.

lv_tabix = sy-tabix.

READ TABLE wd_this->gt_prop INTO ls_prop INDEX lv_tabix.

IF sy-subrc EQ 0.

IF ls_prop-wk01 = abap_true OR

ls_prop-wk02 = abap_true OR

ls_prop-wk03 = abap_true OR

ls_prop-wk04 = abap_true OR

ls_prop-wk05 = abap_true OR

ls_prop-wk06 = abap_true OR

ls_prop-wk07 = abap_true OR

ls_prop-wk08 = abap_true OR

ls_prop-wk09 = abap_true OR

ls_prop-wk10 = abap_true OR

ls_prop-wk11 = abap_true OR

ls_prop-wk12 = abap_true OR

ls_prop-wk13 = abap_true OR

ls_prop-wk14 = abap_true OR

ls_prop-wk15 = abap_true.

ls_date_table-read_only = abap_true.

ELSE.

ls_date_table-read_only = abap_false.

ENDIF.

ENDIF.

MODIFY lt_date_table FROM ls_date_table INDEX lv_tabix TRANSPORTING read_only.

ENDLOOP.

CALL METHOD lo_nd_date_table->bind_table

EXPORTING

new_items = lt_date_table

set_initial_elements = abap_true.

4. I loop through the column reference and use the code mentioned earlier.

CREATE OBJECT lr_input

EXPORTING

value_fieldname = lv_id.

lo_column->set_cell_editor( value = lr_input ).

lr_input->set_read_only_fieldname( value = 'READ_ONLY' ).

The expected output is different from the input i had mentioned earlier for Row 1, row 2, Row 3 and row 4. Here, i would get all the rows as non editable except for Row 3.

I would want to set all columns based on condition.

Regards,

Rekha

Former Member
0 Kudos

Hi Rekha,

If you have created read_only attribute and bound to all the columns. Then...After you have modified the table..for that row using the read_only attribute. Then...for ex: in your case if the project is valid, then you are editing it right......Thenthat entire row will be editable. There is no need of explicit setting of 01..0n fields to abap_true........

Loop at lt_table into ls_table.

if ls_table-prj = 1.

ls_table-read_only = abap_false.

else.

ls_table-read_only = abap_true.

endif.

endloop.

Bind tble...There is no need of explict setting of indiviual day columns(ls_prop-wk1 to wk11) to abap_true.

Loop at the data and set read only * navigate from to via lead selection lo_nd_date_table = wd_context->get_child_node( name = wd_this->wdctx_date_table ). 
ALL METHOD lo_nd_date_table->get_static_attributes_table IMPORTING table = lt_date_table . 
LOOP AT lt_date_table INTO ls_date_table. lv_tabix = sy-tabix. 
READ TABLE wd_this->gt_prop INTO ls_prop INDEX lv_tabix. IF sy-subrc EQ 0.
 IF ls_prop-wk01 = abap_true OR ls_prop-wk02 = abap_true OR ls_prop-wk03 = abap_true OR ls_prop-wk04 = abap_true OR ls_prop-wk05 = abap_true OR ls_prop-wk06 = abap_true OR ls_prop-wk07 = abap_true OR ls_prop-wk08 = abap_true OR ls_prop-wk09 = abap_true OR ls_prop-wk10 = abap_true OR ls_prop-wk11 = abap_true OR ls_prop-wk12 = abap_true OR ls_prop-wk13 = abap_true OR ls_prop-wk14 = abap_true OR ls_prop-wk15 = abap_true. ls_date_table-read_only = abap_true. ELSE. ls_date_table-read_only = abap_false. 
ENDIF. 
ENDIF.
 MODIFY lt_date_table FROM ls_date_table INDEX lv_tabix TRANSPORTING read_only. 
ENDLOOP. 
CALL METHOD lo_nd_date_table->bind_table EXPORTING new_items = lt_date_table set_initial_elements = abap_true.

Why the above fields are required...like wk1 to 15.

Regards,

Lekha.

Edited by: Lekha on Sep 14, 2009 3:08 PM

Answers (2)

Answers (2)

preethi_santhanam
Participant
0 Kudos

Hi Rekha,

You need to create an attribute ALV_VISIBLE of type WDUI_VISIBILITY with a Default Value of 2. (i.e, visible). In method, you use:

data: wd_node type ref to if_wd_context_node,

lv_visibility type wd_this->element_visible-alv_visible.

wd_node = wd_context->get_child_node( name = 'VISIBLE' ).

wd_node->get_attribute( exporting name = 'ALV_VISIBLE'

importing value = lv_visibility ).

if lv_visibility = '02'.

wd_node->set_attribute( name = 'ALV_VISIBLE'

value = '01' ).

else.

wd_node->set_attribute( name = 'ALV_VISIBLE'

value = '02' ).

endif.

This would help you get the required output.

Best Regards,

Preethi.

preethi_santhanam
Participant
0 Kudos

Hi Rekha,

You need to create an attribute ALV_VISIBLE of type WDUI_VISIBILITY with a Default Value of 2. (i.e, visible). In method, you use:

data: wd_node type ref to if_wd_context_node,

lv_visibility type wd_this->element_visible-alv_visible.

wd_node = wd_context->get_child_node( name = 'VISIBLE' ).

wd_node->get_attribute( exporting name = 'ALV_VISIBLE'

importing value = lv_visibility ).

if lv_visibility = '02'.

wd_node->set_attribute( name = 'ALV_VISIBLE'

value = '01' ).

else.

wd_node->set_attribute( name = 'ALV_VISIBLE'

value = '02' ).

endif.