Show TOC Start of Content Area

Define a Dynamic Expression  Locate the document in its SAP Library structure

Use

A dynamic expression is a formula that you define in order to generate a dynamic field value in a property of a model element. Dynamic expressions can define conditions for field initialization, calculation, validation and text manipulation. They can also be used to define element behavior, such as whether an element is visible, editable or selectable. For example, you can define the following dynamic expression for a Plain Text control (a static text-display field) that indicates how many seats remain in economy class on a flight:

“Book your flight soon! There are only "&NSTR(@Econofree,"")&" seats left in economy class on this flight."

The Dynamic Expression Editor assists you in writing and validating the syntax of dynamic expressions. You access the editor by:

·        Clicking the function (fx) icon that appears to the right of an attribute field and selecting Enter formula.

·        Clicking a Formula button to the right of a field in the Control Properties dialog box.
This enables you to define a formula that computes a new value for the field based on results returned in the function.

·        Clicking a Condition button to the right of a field in the Control Properties dialog box.
This is used to define when a control is Hidden, Disabled or Required. For more information, see Control Properties Dialog Box in the
SAP NetWeaver Visual Composer Reference Guide.

Note that when creating a dynamic expression for the Hidden option, this parameter can operate only on columns, rather than on single cells. The value can be specified as either the Boolean true/false or else activated by a control external to the table (rather than according to a value in another field of the same table).

For examples of many commonly-used dynamic expressions, see Tables of Functions.

 

Procedure

...

       1.      Click one of the buttons that displays the Dynamic Expression Editor or click the function (fx) icon and choose Enter formula, as appropriate. The Dynamic Expression Editor dialog box, named according to the property that you are defining, is displayed as follows:

This graphic is explained in the accompanying text

       2.      In the Function pane at the right, expand the node of the category that contains the function that you want to use. The different functions are grouped into categories (nodes), including:

FOUR BULLETS

Data Fields, which contains all of the fields available from the data services in your model. This can be useful if, for example, you want a particular action type, such as a hyperlink, to represent a specific output in a query.

Entry Lists, which display the values listed in all available global static entry lists.

All available functions, divided into the following categories: Text Functions, Numeric Functions, Date Functions, Time Functions, Conditional Functions and Scientific Functions.

Operators, which lists all the mathematical, logical, and comparison operators available for use in the expression.

LIST CONTINUE Each function has an explanatory tooltip. In addition, the icon to the left of each function represents the data type returned when the function is evaluated, as follows:

Icon

Data Type

This graphic is explained in the accompanying text

Boolean

This graphic is explained in the accompanying text

Date

This graphic is explained in the accompanying text

Number

This graphic is explained in the accompanying text

Text

This graphic is explained in the accompanying text

Time

 

NOTE UNDER NUMBER 2

Make sure that the icon of the function that you choose matches the required data type. You can read the text displayed above the Expression pane to see what data type is expected in the result.

       3.      Drag the required function to the Expression pane on the left of the dialog box.

For example, you may want to expand the Conditional Functions node and use the IF function. In this case, the following expression is displayed in the Expression pane:

IF(test,expr1,expr2)
where test is any value or expression that can be evaluated to
TRUE or FALSE, expr1 is the value that is returned if test is TRUE, and expr2 is the value that is returned if test is FALSE.

When you click on a function or drag it to the Expression pane, the Help pane opens at the bottom left, displaying an explanation of the function and an example.

       4.      Use the formula to create your custom expression. You can write the expression by entering free text in the Expression pane, by dragging additional functions from the Function pane to the Expression pane, or by using a combination of the two methods.

You can use the Data Fields node to locate another field whose value you want to include in your expression. To do this, expand the node and drag the field to the required position in the expression.

LIST CONTINUE Note the following rules:

FOUR BULLETS UNDER NOTE

@@ = current field value

@FieldName = value of the field with the specified name

A reference to a field in an element other than that in focus uses the following format: #ID<ElementCode>@FieldName

Do not concatenate strings that need to be translated.

       5.      When you have completed your expression, click Check to ensure that the expression is valid. If an error occurs, a message explaining the problem is displayed. For more information about validation messages, see Messages in the Dynamic Expression Editor.

       6.      When your expression is valid, click OK. The expression is displayed in the text box from which you accessed the Dynamic Expression Editor.

NOTE UNDER STEP 6

To view and validate all expressions defined in your model, you can click the Inspect button in the task-panel toolbar, and review all the expressions, listed in the Inspect Formulas task panel.

REGULAR For an example of using the Expressions Editor, see Adding a Second Data Service.

For examples of common expressions, see Tables of Functions.

End of Content Area