Well, as it turns out, I didn’t figure out everything I needed for a dynamic table. =) The dynamic table code that I previously talked about works great, until you want to control the read only vs. editable aspects of the table. I found a great way of creating a Dynamic Table in ABAP Web Dynpro that gives me the control that I needed to do allow for editing.
First things first, you need to create a context node and the attributes for to define the table. You could do this dynamically, but I’m finding it’s cleaner to build it normally. Either way, once it exists, here how to build the dynamic table.
*** create dynamic table for Notification – Items
cl_wd_table=>new_table(
exporting
id = ‘TB_TABLE’
bind_data_source = ‘CONTEXT_NODE’
visible_row_count = 5
read_only = abap_false
receiving
control = l_table ).
*** build table columns
loop at <cols> into wa_config.
wa_cols = cl_wd_table_column=>new_table_column( ).
*For Dynamically creating Input Field
CASE type.
when ‘TEXT’ OR ‘TIME’ or ‘DATE’ or ‘DROPDOWN’.
CALL METHOD cl_wd_input_field=>new_input_field
EXPORTING
bind_value = lv_bind
id = lv_id
state = lv_state
read_only = abap_false
on_enter = ‘ON_ENTER’
RECEIVING
control = lr_input.
wa_cols->set_table_cell_editor( lr_input ).
when ‘CHECK’.
CALL METHOD cl_wd_checkbox=>new_checkbox
EXPORTING
bind_checked = lv_bind
id = lv_id
state = lv_state
RECEIVING
control = lr_check.
wa_cols->set_table_cell_editor( lr_check ).
ENDCASE.
ELSE.
CALL METHOD cl_wd_text_view=>new_text_view
EXPORTING
bind_text = lv_bind
id = lv_id
RECEIVING
control = lr_textview.
wa_cols->set_table_cell_editor( lr_textview ).
ENDIF.
l_col_hdr = cl_wd_caption=>new_caption( ).
l_col_hdr->set_text( lv_col_text ).
wa_cols->set_header( l_col_hdr ).
l_table->add_column( wa_cols ).
endloop.
l_root ?= view->get_element( ‘TC_XXX’ ).
grid_data = cl_wd_grid_data=>new_grid_data( l_table ).
l_table->set_layout_data( grid_data ).
l_root->add_child( l_table ).
Now this code obviously won’t work out of the box, but you should be able to get the idea of how to use it. If you have questions on this let me know and I can expand on the code provided. Thanks for reading.
As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,
Mike