Skip to Content
avatar image
Former Member

Inserting values into a table

Hi.

I am trying to learn myself Web Dynpro and wonder how to insert values into a table that is populatet with data from a RFC in the R/3 system.

I have imported the RFC into a model and presenting the data in a table in a view, I am able to manipulate the data etc, but I am not able to insert data.

Is there any mechanism to press a "new button", get a empty row in the table, fill the fields in the table with data and then press save?

Have anyone done that and can help med with som code or tips?

Regards

Kay-Arne

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Jan 09, 2004 at 12:51 PM

    Hi Kay-Arne,

    There is no built-in machanism in the table to get something like a "New Line Button". The data shown in the table (coming from the RFC) comes from a context node that is bound to the RFC model. An RFC usually either retrieves data from the backend or is used to store data to the backend. How do you plan to store data you modified in the table?

    Best regards,

    Karin

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 12, 2004 at 10:28 AM

    Hello Kay-Arne,

    I have some more information for you. The answer depends on the RFC supplied. Some provide a table parameter which can be used to read and write data via the same RFC. Others require two RFCs, one for reading the data, a second for writing the data. In this case, the structure used to read the data may vary from the structure used to write the data, which requires manually copying new user input to the second RFCs structure before firing the second update RFC.

    In case the RFC uses a Table Parameter, then the following can be done:

    - Fetch the RFC to read the initial list and bind it via context to your UITable

    - Provide a "New" Button on your view which fires an eventhandler

    - also provide a "Save" Button which is activated only when new elements have been added

    - the New Button adds a new LineItem to the collection of Items:

    wdContext.currentOutputNodeElement().modelObject().addToItems(new ModelClassLineItem()); // updates the model to contain a new LineItem in the ItemsCollection

    wdContext.nodeOutput().invalidate(); //synchronizes the context with the model

    - also the save button is enabled, once the new LineItem has been added

    - The new Line should now be visible in the Table. Its fields are empty. If you would like to provide initial values, then you can do that in the above eventHandler, when creating the LineItem.

    - You can repeat this process as many times creating mutliple new lines.

    - Once the save button is pressed, you must copy the RowsCollection containing the new LineItems from the RFC Output to the RFC Input and fire the RFC again:

    wdContext.currentInputNodeElement().modelObject().setItems(wdContext.currentOutputNodeElement().modelObject().getItems();

    try{

    wdContext.currentInputNodeElement().modelObject().execute();

    wdContext.nodeOutput().invalidate(); //synchronizes the context with the model

    } catch (Exception e)

    { // handle Exceptions here}

    There are many variations depending on your RFCs and your user input demands, which may require adapting the above strategy.

    Hope that helps.

    Best regards,

    Karin

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 12, 2004 at 10:52 AM

    Hello Kay-Arne,

    And again, some more stuff which might be helpful for you!

    Best regards, Karin

    Assumption:

    - Both master table and detail table are read with a single RFC.

    - All details of all masters are container in the details tables.

    - A foreign key relationship between the master table and the details table exists and the keys are a part of the structure in which the master and detail data are passed via RFC.

    - The resulting context Hierarchy bound to the RFC looks like the following:

    - InputNode

    - OutputNode

    - MasterNode

    - DetailsNode

    Solution:

    - Define a Child ModelNode "MasterDetails" underneath the MasterNode and bind it the ModelClass "Detail":

    - InputNode

    - OutputNode

    - MasterNode

    - MasterDetailNode

    - DetailsNode

    - In the MasterDetailNode, define a SupplyFunction, which takes the MasterKey of the selected Master and determines all Detail ModelClass Instances and binds them to the MasterDetailNode

    - This can be done by going to the OutputModelClass, getting the Details collection, iterating over the elements and binding each instance to the MasterDetailsNode, which has a matching foreign Key

    - If you would like to save the Result, so that the Supply Function is only called the first time a Master Element is selected, then define the MasterDetailNode's singleton property to be "false".

    - Bind the Details UITable to the MasterDetailNode

    - You can repeat the above process for any sort of relationship, such as only the orders of a selected customer, which were not yet completed, or which were processed in the last two weeks, etc.

    Add comment
    10|10000 characters needed characters exceeded