Show TOC

Creating ExpressionsLocate this document in the navigation structure

Prerequisites

You have opened the Process Development or the Service Composer perspective in the SAP NetWeaver Developer Studio and have expanded your project in Project Explorer view .

Context

The expression is a combination of values, variables and functions that are evaluated at runtime to produce a new value. You create expressions in an expression editor using a subset of the XML Path Language (XPath) grammar. For more information about XPath, see http://www.w3.orgInformation published on non-SAP site.

The expression editor contains a context and functions. The context contains all the data, relevant for the expression scope. You use the functions to process the data from the context.

You can use comments in the expression editor. Comments delimited in the following way are supported:

  • // some text

    The text after the // delimiter until the end of the line is part of the comment.

  • /* some text */

    The text, which can consist of multiple lines, between the delimiters /* */ is part of the comment.

After creating an expression, you can extract it to create a new function directly from the expression editor. For more information about creating functions, see Performing Complex Data Transformation with Functions .

Using Functions from Different DCs

In the expression editor, you can also use functions that were created in different development components (DC) than the one you create your project in. To do that, you proceed as follows:

  1. You configure dependencies to the DC containing the function you want to use. For more information about dependencies, see Defining Development Component Dependencies .

  2. You define in the expression editor the namespace prefix of the DC containing the function you want to use, before using the function.

    Example

    You want to use the function "ExampleFunction" , created in the project "my.company.com/myProject1" . You define the namespace prefix of the DC containing the project in the following way:

                         xmlns:myProject1="my.company.com/myProject1"
                      
    Example

    You use the function "ExampleFunction" after you defined the namespace prefix, in the following way:

                         myProject1:ExampleFunction( argument1,argument2... )
                      

When you use functions created in the current DC, you can omit the namespace prefix.

Note

When you apply changes to an expression or a mapping function defined in one DC and referenced in other DCs, you must rebuild and redeploy all referencing DCs.

Casting Data Types

You can use the cast as function in case you want to process one data type as another. With the cast as function you define how the expression editor must treat the original data type when it evaluates the expression.

Example

The required data type is xsd:byte but you provide myDecimalRef as xsd:decimal. You cast xsd:decimal as xsd:byte in the following way:

               myDecimalRef cast as xsd:byte
            

When you cast data types, you have to do that in compliance with the World Wide Web Consortium data type hierarchy. For more information about the data type hierarchy, see http://www.w3.orgInformation published on non-SAP site.

Procedure

  1. Open the expression editor.
  2. Expand Rules and Functions , containing the type of functions you want to use to process the data.

    You can use both the built-in functions and functions you have created in your project, or other existing functions in different development components.

    Note

    A list with all built-in functions and their descriptions is available in the expression editor. To show the list, click the empty editing area of the expression editor and press CTRL + SPACEBAR . The list with all functions appears. To show the description of a function, click the function's name. The description appears on the right of the list. You can also place a function in the editing area by double-clicking the function's name in the list.

    For more information about built-in functions, see Built-In Functions and Generic Functions .

    For more information about EJB functions and using them as mapping functions, see Creating an External Function, Exposing It as an EJB, and Using It as a Mapping Function .

  3. Drag a function or functions from the Rules and Functions node in the expression editor to the editing area of the expression editor.

    Alternatively, double-click a function from the Rules and Functions node in the expression editor. It appears in the editing area of the expression editor.

  4. Expand Context and drag the necessary data that is processed by the function to the editing area of the expression editor.

    You can also enter data that is different from the data in Context directly in the editing area.

    Note

    Each function in Rules and Functions contains information about what data it expects and processes. This information is written in parentheses ((...)).

  5. Use the XPath grammar to create a valid expression using the functions and the data. Choose the OK pushbutton.
    Caution

    An error marker next to the expression means that the expression has an error and cannot be evaluated. Errors in expressions are only visible in the expression editor but are not visible on the modeling surface or in the Problems view.

    After the data transformation, that is, after the expression is evaluated, a new value is produced (principal, Boolean value and so on).

    Note

    If you want to construct a list using the values produced by a complex expression, such as ( Expr1, Expr2, ..., ExprN), you need to use custom function to construct the list. This rule applies to all expressions, except the expressions you use to define data mappings.

  6. (Optional) Click Extract Function... to extract the expression you created as a new function.
  7. (Optional) In the dialog that appears, specify a name for the new function. Choose the OK pushbutton.

    The new function is extracted in the Functions folder of your project.

Example

Here is a list of examples for creating expressions in the expression editor.

The context to use in the examples is the following:

            SourceRoot1
        SubRoot
                mInt( xsd:int )
                mInt1( xsd:int )
         
            SourceRoot2
        mInt2( xsd:int )
        mStr( xsd:string )
         
  • In this example, the data in the context is of type integer and the expected result after the expression is evaluated is also integer (xsd:int):

                      SourceRoot1/SubRoot/mInt + SourceRoot2/mInt2
                   
  • In this example, the data in the context is of type integer and the expected result after the expression is evaluated is String (xsd:string). The expression converts the xsd:int into xsd:string:

                      string( SourceRoot1/SubRoot/mInt )
                   
  • In this example, the data in the context is of type String and the expected result after the expression is evaluated is also String:

                      concat( "Prefix ", concat( SourceRoot2/mStr, " Sufix") )
                   
  • This example shows the usage of list of function arguments. The data used is of type String and the expected result is also String. The list is defined in the following way:

                      ( "ElementOne", "ElementTwo", "ElementThree" )
                   

    The defined list is used as function argument in the following way:

                      myFunc( ( "ElementOne", "ElementTwo", "ElementThree" ) )
                   
  • The following is an example of an expression, which returns a Boolean value:

                      not( true AND 1<=2 )