cancel
Showing results for 
Search instead for 
Did you mean: 

Table

Former Member
0 Kudos

Hi Forum,

Im new to webdynpro..Till now i could able to create a table and displayed the records from database table..My requirement is to edit the fields in the table and apply the changes in database. How to do this? Kindly help me.

Regards

Mallika

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Mallika,

Say suppose that you are binding your table to a context node by name SFLIGHT. When you right click on your table & say "Create Binding" you select the context node as SFLIGHT & then you get the option to specify the Cell editor of the various table columns. Now select the cell editor as "InputField" & name of property to be bound as "Value". Now this would result in your table being displayed in editable mode. You can create a toolbar button using which you can save your table entries. Associate an action with this button and suppose you want to save all the data being displayed on your table to the database then you can read the entire tables content using the get_static_attributes_table method of if_wd_context_node. once you have the data in your internal table you can then save it into the database using the normal UPDATE statement.

NOTE: Am suggesting you this approach only for your practise as you said that you are a beginner in WDA. In reality you would have to make use of a BAPI for saving the data on to your database.

Regards,

Uday

Adding to the earlier reply. If you intend to only read those rows which the user had edited by performing a multiple selection then you can proceed as shown below. The coding does actually read all the selected rows and fill them into an internal table lt_node1. Am then binding this internal table to another context node to achieve copying selected rows between 2 tables. I guess that you can use this logic to extract your desired rows and then use the extracted rows to save on to database.

METHOD onactioncopy_selected_rows .
  DATA:  wd_node TYPE REF TO if_wd_context_node,
         ls_node1 TYPE ig_componentcontroller=>element_node1,
         lt_node1 TYPE ig_componentcontroller=>elements_node1,
         lt_node2 TYPE ig_componentcontroller=>elements_node2,
         wa_temp  TYPE REF TO if_wd_context_element,
         lt_temp  TYPE wdr_context_element_set.


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

  CALL METHOD wd_node->get_selected_elements
    RECEIVING
      set = lt_temp.

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

  LOOP AT lt_temp INTO wa_temp.
    CALL METHOD wa_temp->get_static_attributes
      IMPORTING
        static_attributes = ls_node1.
    APPEND ls_node1 TO lt_node1.
    CLEAR ls_node1.
  ENDLOOP.

  wd_node->bind_table( new_items = lt_node1 ).
ENDMETHOD.

Answers (4)

Answers (4)

uday_gubbala2
Active Contributor
0 Kudos

Hi Mallika,

As how you said the below snippet does only end in displaying the data for the user.

method wddoinit.

data : node_zbook type if_wd_context_node,
itab type standard table of zbookinfo.

select * from zbookinfo into table itab.

node_zbook = wd_context->get_child_node( name = 'node_zbook' ).
node_zbook->bind_table ( itab ).
endmethod.

If you have already managed to display the table in editable mode as how described in [here|; then you can create a toolbar button for saving the records on to the database. Within the action handler for this method you can try fetch all the data being displayed in the table into an internal table using the get_static_attributes_table method.

DATA: node_flighttab TYPE REF TO if_wd_context_node,
          lt_sflight TYPE if_resultview=>elements_node_flighttab.
 
 node_flighttab = wd_context->get_child_node( name = `NODE_FLIGHTTAB` ). " NODE_FLIGHTTAB is the node that you have bound to your table
node_flighttab->get_static_attributes_table( IMPORTING table = lt_sflight ). " Get all tables data into your internal table lt_sflight

You can then just say modify <database table> from <internal table> However note that this is not suggested in real time. This is only for your practice purpose.

Regards,

Uday

Former Member
0 Kudos

Hi Mallika,

To enter/edit data in the cells of table u have to make the cells editable

1. Select the required column in the table and uncheck its readOnly property. It will make the entire column editable. Do this for the required columns.

2. After entering/editing the values u have to read the context to read the entered values. Use GET_STATIC_ATTRIBUTES_TABLE method of IF_WD_CONTEXT_NODE interface. U can use WD Code Wizard here.

3. Once data are available in the internal table u can update it in the required database table.

pranav_nagpal2
Contributor
0 Kudos

Hi Mallika,

in the layout of the view follow these steps

1. Right click on the u201CROOTUIELEMENTu201D and click on u201CInsert Elementu201D.

2. Give any name for the ui element (TB_FORINPUTFIELD here). And select the UI element Table

3. Right click on the table name and click on u201CInsert Table Columnu201D.

4. A column will appear for the table as shown below. Now right click on the column name and click u201CInsert Cell Editoru201D.

5. Give the name in the Id and select the type of column you want (Input field is selected here so that column can be used to get data from the user).

6. Select the context tab if not selected by default. Right click on the context and click on create Node.

7. Give the name of the node and set the Cardinality to 0:n.

8. right click on the node and create a Context Attribute.

9. Give the name of the context name and select the type. String is used here.

10. Bind table with node and input field with attribute.

11.in doinit write the following code

DATA lt_table TYPE wd_this->elements_cn_uitable.

DATA ls_table TYPE wd_this->element_cn_uitable.

do 5 times.

clear ls_table.

append ls_table to lt_table.

enddo.

lo_nd_cn_uitable->bind_table( lt_table ).

Above code will activate the 5 input fields column of table.

regards

Pranav

Former Member
0 Kudos

Hi Mallika,

you can use an editable ALV to edit the values directly within the table.

[http://help.sap.com/saphelp_nw04s/helpdata/en/74/fd4142646ab46be10000000a155106/content.htm]

Or you use a master/detail view.

In the master (table), you can select the entries, in the detail (InputFields) you modify it.

For this, you can use the option "Singelton" and "Supply Function" for the node.

Regards,

Andreas