cancel
Showing results for 
Search instead for 
Did you mean: 

cl_wd_table - table with dynamic fields

Former Member
0 Kudos

Hi all,

I have generated a dynamic table with dynamic fields.

How can I fill the fields?

METHOD wddomodifyview .

DATA lr_container TYPE REF TO cl_wd_uielement_container.

DATA lr_input TYPE REF TO cl_wd_input_field.

DATA lr_table TYPE REF TO cl_wd_table.

DATA lr_caption TYPE REF TO cl_wd_caption.

DATA lr_table_column TYPE REF TO cl_wd_table_column.

DATA lr_table_standard_cell TYPE REF TO cl_wd_table_standard_cell.

DATA lr_column_group TYPE REF TO cl_wd_table_column_group.

DATA lr_column_group2 TYPE REF TO cl_wd_table_column_group.

DATA lr_column_group3 TYPE REF TO cl_wd_table_column_group.

DATA lr_column_group4 TYPE REF TO cl_wd_table_column_group.

DATA lr_column_group5 TYPE REF TO cl_wd_table_column_group.

DATA: lines TYPE i.

DATA: id TYPE string.

DATA: counter TYPE string.

DATA: binding TYPE string.

DATA: c_count TYPE string.

DATA: text TYPE string.

DATA: it_comp_header TYPE TABLE OF zst_comp_header.

DATA: wa_comp_header LIKE LINE OF it_comp_header.

DATA: it_bin_comp TYPE TABLE OF zst_bin_comp.

DATA: wa_bin_comp LIKE LINE OF it_bin_comp.

SELECT * FROM zst_bin_comp

INTO TABLE it_bin_comp.

SELECT * FROM zst_comp_header

INTO TABLE it_comp_header.

IF first_time = abap_true.

lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).

cl_wd_table=>new_table(

EXPORTING

bind_data_source = 'IT_BIN_COMP'

id = 'DYNTABLE'

RECEIVING

control = lr_table ).

DESCRIBE TABLE it_comp_header LINES lines.

LOOP AT it_comp_header INTO wa_comp_header.

  • Minimum

counter = counter + 1.

CONDENSE counter.

CONCATENATE 'INPUT_' counter INTO id.

  • c_count = sy-index.

c_count = counter.

CONDENSE c_count.

CONCATENATE 'IT_BIN_COMP.MIN' c_count INTO binding.

cl_wd_input_field=>new_input_field(

EXPORTING

bind_value = binding

id = id

RECEIVING

control = lr_input ).

lr_column_group = cl_wd_table_column_group=>new_table_column_group( ).

lr_table_column = cl_wd_table_column=>new_table_column( ).

lr_table_column->set_table_cell_editor( lr_input ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( 'Min' ).

lr_table_column->set_header( lr_caption ).

lr_column_group->set_fixed_position( 1 ).

lr_column_group->add_column( lr_table_column ).

  • MAX

CONDENSE counter.

CONCATENATE 'INPUT2_' counter INTO id.

c_count = counter.

CONDENSE c_count.

CONCATENATE 'IT_BIN_COMP.MAX' c_count INTO binding.

cl_wd_input_field=>new_input_field(

EXPORTING

bind_value = binding

id = id

RECEIVING

control = lr_input ).

lr_table_column = cl_wd_table_column=>new_table_column( ).

lr_table_column->set_table_cell_editor( lr_input ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( 'Max' ).

lr_table_column->set_header( lr_caption ).

lr_column_group->set_fixed_position( 2 ).

lr_column_group->add_column( lr_table_column ).

  • BIN

CONDENSE counter.

CONCATENATE 'INPUT3_' counter INTO id.

c_count = counter.

CONDENSE c_count.

CONCATENATE 'IT_BIN_COMP.BIN' c_count INTO binding.

cl_wd_input_field=>new_input_field(

EXPORTING

bind_value = binding

id = id

RECEIVING

control = lr_input ).

lr_table_column = cl_wd_table_column=>new_table_column( ).

lr_table_column->set_table_cell_editor( lr_input ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( 'Sorting Bin' ).

lr_table_column->set_header( lr_caption ).

lr_column_group->add_column( lr_table_column ).

lr_caption = cl_wd_caption=>new_caption( ).

  • Column group headline

text = wa_comp_header-chip.

lr_caption->set_text( text ).

lr_column_group->set_header( lr_caption ).

lr_table->add_grouped_column( lr_column_group ).

ENDLOOP.

  • Subproduct

cl_wd_input_field=>new_input_field(

EXPORTING

bind_value = 'IT_BIN_COMP.SUBPROD'

id = 'SUBPROD'

RECEIVING

control = lr_input ).

lr_column_group = cl_wd_table_column_group=>new_table_column_group( ).

lr_table_column = cl_wd_table_column=>new_table_column( ).

lr_table_column->set_table_cell_editor( lr_input ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( 'Sub Product' ).

lr_table_column->set_header( lr_caption ).

lr_column_group->add_column( lr_table_column ).

lr_table->add_grouped_column( lr_column_group ).

  • Remarks

cl_wd_input_field=>new_input_field(

EXPORTING

bind_value = 'IT_BIN_COMP.REMARKS'

id = 'REMARKS'

RECEIVING

control = lr_input ).

lr_input->set_read_only( value = abap_false ).

lr_column_group = cl_wd_table_column_group=>new_table_column_group( ).

lr_table_column = cl_wd_table_column=>new_table_column( ).

lr_table_column->set_table_cell_editor( lr_input ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( 'Remarks' ).

lr_table_column->set_header( lr_caption ).

lr_column_group->add_column( lr_table_column ).

lr_table->add_grouped_column( lr_column_group ).

lr_input->set_value( 'tets' ).

  • wd_context->set_attribute( name = 'IT_BIN_COMP.REMARKS' value = 'test' ).

  • Yield loss

cl_wd_input_field=>new_input_field(

EXPORTING

bind_value = 'IT_BIN_COMP.YIELD'

id = 'YIELD'

RECEIVING

control = lr_input ).

lr_column_group = cl_wd_table_column_group=>new_table_column_group( ).

lr_table_column = cl_wd_table_column=>new_table_column( ).

lr_table_column->set_table_cell_editor( lr_input ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( 'Yield loss' ).

lr_table_column->set_header( lr_caption ).

lr_column_group->add_column( lr_table_column ).

lr_table->add_grouped_column( lr_column_group ).

    • create the layout data of the text view

DATA lr_grid_data TYPE REF TO cl_wd_grid_data.

lr_grid_data = cl_wd_grid_data=>new_grid_data( lr_table ).

lr_table->set_layout_data( lr_grid_data ).

  • Characteristics

DATA: it_2_char_2_col1 TYPE TABLE OF zst_2_char_2_col.

DATA: wa_2_char_2_col1 LIKE LINE OF it_2_char_2_col1.

DATA: it_2_char_2_col2 TYPE TABLE OF zst_2_char_2_col.

DATA: wa_2_char_2_col2 LIKE LINE OF it_2_char_2_col2.

DATA: it_2_char_2_col3 TYPE TABLE OF zst_2_char_2_col.

DATA: wa_2_char_2_col3 LIKE LINE OF it_2_char_2_col3.

TYPES: BEGIN OF char,

column TYPE i,

char1 TYPE string,

min1 TYPE i,

max1 TYPE i,

char2 TYPE string,

min2 TYPE i,

max2 TYPE i,

char3 TYPE string,

min3 TYPE i,

max3 TYPE i,

END OF char.

DATA: min1 TYPE string.

DATA: min2 TYPE string.

DATA: min3 TYPE string.

DATA: max1 TYPE string.

DATA: max2 TYPE string.

DATA: max3 TYPE string.

DATA: it_char TYPE TABLE OF char.

DATA: wa_char LIKE LINE OF it_char.

SELECT * FROM zst_2_char_2_col

INTO TABLE it_2_char_2_col1

WHERE st_2_char_id = 1.

SELECT * FROM zst_2_char_2_col

INTO TABLE it_2_char_2_col2

WHERE st_2_char_id = 2.

SELECT * FROM zst_2_char_2_col

INTO TABLE it_2_char_2_col3

WHERE st_2_char_id = 3.

LOOP AT it_2_char_2_col1 INTO wa_2_char_2_col1.

LOOP AT it_2_char_2_col2 INTO wa_2_char_2_col2.

LOOP AT it_2_char_2_col3 INTO wa_2_char_2_col3.

wa_char-column = 1.

SELECT SINGLE bin_descr zmin zmax

FROM zst_bin_char

INTO (wa_char-char1, wa_char-min1, wa_char-max1)

WHERE st_2_ch_2_col_id = wa_2_char_2_col1-id.

SELECT SINGLE bin_descr zmin zmax

FROM zst_bin_char

INTO (wa_char-char2, wa_char-min2, wa_char-max2)

WHERE st_2_ch_2_col_id = wa_2_char_2_col2-id.

SELECT SINGLE bin_descr zmin zmax

FROM zst_bin_char

INTO (wa_char-char3, wa_char-min3, wa_char-max3)

WHERE st_2_ch_2_col_id = wa_2_char_2_col3-id.

APPEND wa_char TO it_char.

ENDLOOP.

ENDLOOP.

ENDLOOP.

DATA: spalte TYPE string.

counter = 0.

LOOP AT it_char INTO wa_char.

counter = counter + 1.

CONDENSE counter.

CONCATENATE 'IT_BIN_COMP.SPALTE' counter INTO binding.

CONCATENATE 'CHAR_' counter INTO id.

cl_wd_input_field=>new_input_field(

EXPORTING

bind_value = binding

id = id

RECEIVING

control = lr_input ).

min1 = wa_char-min1.

min2 = wa_char-min2.

min3 = wa_char-min3.

max1 = wa_char-max1.

max2 = wa_char-max2.

max3 = wa_char-max3.

  • Zeile 6

CONCATENATE min3 '-' max3 INTO spalte.

lr_table_column = cl_wd_table_column=>new_table_column( ).

lr_input->set_read_only( value = abap_false ).

lr_table_column->set_table_cell_editor( lr_input ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( spalte ).

lr_table_column->set_header( lr_caption ).

  • Zeile 5

lr_column_group5 = cl_wd_table_column_group=>new_table_column_group( ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( wa_char-char3 ).

lr_column_group5->set_header( lr_caption ).

lr_column_group5->add_column( lr_table_column ).

  • Zeile 4

CONCATENATE min2 '-' max2 INTO spalte.

lr_column_group4 = cl_wd_table_column_group=>new_table_column_group( ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( spalte ).

lr_column_group4->set_header( lr_caption ).

lr_column_group4->add_column( lr_column_group5 ).

  • Zeile 3

lr_column_group3 = cl_wd_table_column_group=>new_table_column_group( ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( wa_char-char2 ).

lr_column_group3->set_header( lr_caption ).

lr_column_group3->add_column( lr_column_group4 ).

  • Zeile 2

CONCATENATE min1 '-' max1 INTO spalte.

lr_column_group2 = cl_wd_table_column_group=>new_table_column_group( ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( spalte ).

lr_column_group2->set_header( lr_caption ).

lr_column_group2->add_column( lr_column_group3 ).

  • Zeile 1

lr_column_group = cl_wd_table_column_group=>new_table_column_group( ).

lr_caption = cl_wd_caption=>new_caption( ).

lr_caption->set_text( wa_char-char1 ).

lr_column_group->set_header( lr_caption ).

lr_column_group->add_column( lr_column_group2 ).

lr_table->add_grouped_column( lr_column_group ).

lr_grid_data = cl_wd_grid_data=>new_grid_data( lr_table ).

lr_table->set_layout_data( lr_grid_data ).

ENDLOOP.

lr_container->add_child(

EXPORTING

the_child = lr_table ).

ENDIF.

ENDMETHOD.

regards

Accepted Solutions (0)

Answers (1)

Answers (1)

Madhu2004
Active Contributor
0 Kudos

As you have created the dynamic table with dynamic fields, you might have assigned as node to the data source of the table.

If not, create a dynamic node and with the fields used in the dynamic table, assign it to the data source of the table.

Bind the dynamically created node with data and data wil be displayed in the table.

*get the node info
lr_node_info type ref to if_wd_context_node_info.

lr_node_info = wd_context->get_node_info( ).

In the IF_WD_CONTEXT_NODE_INFO method you will have methods to create node(ADD_CHILD_NODE) and attributes(ADD_ATTRIBUTE) dynamically

Regards,

Madhu

Former Member
0 Kudos

Thanks.

Can you please provide an example coding?

regards

Madhu2004
Active Contributor
0 Kudos
*get node info

 lr_node_info type ref to if_wd_context_node_info.
lr_new_node_info  type ref to if_wd_context_node_info
 lr_node_info  = wd_context->get_node_info( ).

*create node
 lr_node type ref to if_wd_context_node.

 CALL METHOD lr_node_info->add_new_child_node
  EXPORTING
*    supply_method                =
*    supply_object                =
*    dispose_method               =
*    dispose_object               =
*    static_element_type          =
    name                         = 'node_name'
*    is_mandatory                 = ABAP_FALSE
*    is_mandatory_selection       = ABAP_FALSE
*    is_multiple                  = ABAP_TRUE
*    is_multiple_selection        = ABAP_TRUE
*    is_singleton                 = ABAP_FALSE
*    is_initialize_lead_selection = ABAP_TRUE
*    static_element_rtti          =
*    is_static                    = ABAP_TRUE
*    attributes                   =
  receiving
    child_node_info              = lr_new_node_info    .

*now add all the attributes to the nodes which you have created as columns in the table
 lr_new_node_info->add_attribute...........

*set the newly created node as data source to ur dynamic table
table->set_data_source( new_node ).

Now you can bind the data to the node...
Former Member
0 Kudos

hi,

The below code shows how to create a node.

lo_node_info = wd_context->get_node_info( ).
  CALL METHOD lo_node_info->add_new_child_node
    EXPORTING
      name            = node_name
    RECEIVING
      child_node_info = lo_node_info.

Once you created the node , you can add attributes to the node.

CALL METHOD lo_child_node_info->add_attribute
    EXPORTING
      attribute_info = lv_attribute_info.

lv_attribute_info has all the properties of a attribute , set them properly as you want before you create.

Once a node with required attributes is done , bind this to the data source of the table , using

cl_wd_table->BIND_DATA_SOURCE( ).

Thanks,

Aditya.