Show TOC

Procedure documentationCreating Expressions Locate this document in the navigation structure

 

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.org.

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 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:

    End of the example.

    Syntax Syntax

    1. xmlns:myProject1="my.company.com/myProject1"
    End of the code.

    Example Example

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

    End of the example.

    Syntax Syntax

    1. myProject1:ExampleFunction( argument1,argument2... )
    End of the code.

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

Note 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.

End of the note.
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 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:

End of the example.

Syntax Syntax

  1. myDecimalRef cast as xsd:byte
End of the code.

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.org.

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.

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 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.

    End of the note.

    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 Note

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

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

    Caution 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.

    End of the caution.

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

    Note 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.

    End of the note.
  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:

Syntax Syntax

  1. SourceRoot1
    	SubRoot
    		mInt( xsd:int )
    		mInt1( xsd:int )
End of the code.

Syntax Syntax

  1. SourceRoot2
    	mInt2( xsd:int )
    	mStr( xsd:string )
End of the code.
  • 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):

    Syntax Syntax

    1. SourceRoot1/SubRoot/mInt + SourceRoot2/mInt2
    End of the code.
  • 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:

    Syntax Syntax

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

    Syntax Syntax

    1. concat( "Prefix ", concat( SourceRoot2/mStr, " Sufix") )
    End of the code.
  • 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:

    Syntax Syntax

    1. ( "ElementOne", "ElementTwo", "ElementThree" )
    End of the code.

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

    Syntax Syntax

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

    Syntax Syntax

    1. not( true AND 1<=2 )
    End of the code.