Show TOC Start of Content Area

Procedure documentation Storing Data in a Data Store  Locate the document in its SAP Library structure

Use

A Data Store is a central data container in which you temporarily store data for later use. The data is stored in memory, and is available at runtime as long as the modeled application is open. When the modeled application is closed, the data store is emptied.

Each model uses a single Data Store. To make it easier to connect elements to the Data Store, you can add multiple Data Store elements to the Design board. However, these multiple Data Storeelements all represent the same Data Store(data stored in one element is visible in the other elements).

The connecting lines to the input port of the Data Store are of data mapping type. The values in the Data Store are accessed using expressions.

Procedure

...

       1.      In your model, drag a Data Store connector from the Compose task panel to the Design board.

       2.      Drag from the out port of the UI element whose data is to be stored in the Data Store to the port of the Data Store element.

       3.      Define a virtual field in which to store the data:

                            a.      Right-click the Data Store element and from the context menu, choose Define Data.

                            b.      Define a virtual field for the Data Store by clicking the Add Field (+) button and choosing the type of data that you want to store. Add more fields as required.

                            c.      The field is added with a default name. If you want to give it a meaningful name, click the Rename Field button and enter a new name.

                            d.      To define a default value for each field, enter it in the Default Value column.

       4.      Define the event used to transfer data to the Data Store:

                            a.      Right-click the connecting line to the Data Store, and from the context menu choose Rename.

                            b.      Name the event with the same name as the action that adds items to the Data Store (defined in step 6), for example: Add_Item.

       5.      Map values from the UI element fields to the Data Store fields:

                            a.      Right-click the connecting line between the elements, and from the context menu choose Map Data.

                            b.      In the Assigned Value column, choose a UI element field, enter a field name, or define a dynamic expression to specify from where to take the value that is placed in the Data Store.

       6.      On the Layout board, add a toolbar button for transferring items to the Data Store:

                            a.      Select the UI component that contains the values to send to the Data Store and in the Configure task panel, select Show Toolbar.

                            b.      From the Compose task panel, drag a Button control to the toolbar, and assign it a custom action with the same name as the event you defined in step 4, for example, Add_Item. For more information, see Defining Actions.

       7.      On the Design board, drag a Form View icon from the Compose task panel to create a stand-alone form that displays the Data Store values at runtime in the component.

       8.      Define a virtual field to display the Data Store values:

                            a.      Right-click the Form View element and from the context menu choose Define Data.

                            b.      Define a virtual field for the form by clicking the Add Field (+) button and choosing the type of field.

                            c.      The field is added with a default name. Give the field a meaningful name (the name is displayed as the control label in the form), by clicking the Rename Field button and entering a new name.

                            d.      In the Control column, choose the type of control that you want to add to the form for the field.

                            e.      In the Default Value column, click the fx button to open the Dynamic Expression Editor dialog box. In the list of functions in the right pane, expand the Data Fieldsgroup, then expand the store group, and double-click the name of the field in the Data Store. This is the field whose values will be transferred from the Data Store to the form.

                              f.      Click OK to close the Dynamic Expression Editordialog box.

                            g.      Click Close in the Define Data dialog box.

Result

At runtime, when the user selects an item and clicks Add Item, the item name is displayed in the field in the stand-alone form. When additional items are selected, they are concatenated in this field.

Example

In this example, we will use the Flights model and add a Data Store to it. We will then create a form called Departures into which users can transfer flight departure times from the Flight List table. Departure times transferred to the form are concatenated into a single string separated by semicolons.

...

       1.      Open the Flights model that you created in Creating the Basic Model.

       2.      Drag a Data Store connector from the Compose task panel onto the Design board.

       3.      Drag from the out port of the Flight List table to the port of the Data Store element to connect them.

       4.      Define a virtual field of type String for the Data Store, named DepartureTimes.

       5.      Right-click the connecting line from the Flight List table to the Data Store, choose Rename from the context menu, and rename the line to Add_to_Departures.

       6.      Create a dynamic expression that maps values from the table to the Data Store.

                            a.      Right-click the connecting line and from the context menu, choose Map Data.

                            b.      Double-click the DepartureTimes row to open the Dynamic Expression Editor dialog box.

                            c.      Enter the following expression:

=IF(CONTAINS(store@DepartureTimes,@Deptime),store@DepartureTimes,store@DepartureTimes &(IF(LEN(store@DepartureTimes)>0,'; ',''))&@Deptime)

This expression checks whether the Deptime value transferred to the DepartureTimes field is already contained in the field. If it is not, the value is concatenated with the existing values.

                            d.      Click Check to validate the expression, and then click OK.

       7.      Create another instance of the Data Store as described in steps 2-6. However, name the connecting line Clear_Departures and map the value '' as the Assigned Value of the input field in the Dynamic Expression Editor dialog box (this assigns an empty value to the DepartureTimes field).

       8.      On the Layout board, create toolbar buttons for activating and clearing the Data Store items:

                            a.      Select the Flight List table and in the Configure task panel, select Show toolbar.

                            b.      From the Compose task panel, drag a Button control to the toolbar, name it Add to Departures and define a custom action for it called Add_to_Departures.

                            c.      Add a second button named Clear Departures, with Clear_Departures as the custom action.

       9.      On the Design board, drag a Form View icon from the Compose task panel to create a stand-alone form. Name it Departuresand place it above the Flight List table.

   10.      Define a virtual field in the form to display the Data Store (departure list) values and name the field Departures (following step 8 in the previous procedure).

Result

At runtime, when the user selects a flight and clicks Add to Departures, the departure time is displayed in the Departures form. When additional items are selected, they are concatenated in the DepartureTimes field. When the runtime user clicks the Clear Departures button, all departure times in the form are removed.

End of Content Area