User Level
Business Administrator
User LevelBusiness Administrator SyntaxThe command uses this syntax.
Add ExpressionTo define an expression from within MQL use the add expression command. Syntax
The add expression clauses are:
Value ClauseThis clause is the string that defines the expression. It can contain selects, comparisons, equations, and so on. Enclose the value string in double quotes if it contains any space. For more information, see Formulating Expressions for Collections and Evaluating Expressions. Formulating Expressions on Business Objects or RelationshipsIf-Then-ElseIf-then-else logic is available for expressions. The syntax is:
For example: eval expr' if (attribute[Actual Weight] > attribute[Target Weight]) then ("OVER") else ("OK")' on bus 'Body Panel' 610210 0; SubstringThe substring operator works within an expression to provide the ability to get a part of a string; the syntax is:
The substring operator works as follows:
For example, to obtain the last 4 characters of a 10-character phone number, use:
DateperiodDateperiod lets you determine the period (year, quarter, month, week and/or day) in which a given date has occurred. You include 2 arguments with the keyword dateperiod; the first defines the period to evaluate; the second is the date in question. To define a dateperiod, you can include one or more of the following periods to inquire about:
Any other characters are simply returned with the expression’s output. For example, the following expression determines in which fiscal quarter the objects it is evaluated against are due:
Other examples:
Dates in ExpressionsThe following calculations can be performed on dates within an expression:
For example, the following could be used to determine how old an object is (in hours):
The following returns the average age of all objects in the set M6000-panels (in hours):
Formulating Expressions for CollectionsCertain kinds of expressions are applicable to collections of business objects (such as Query results or sets) or connections, returning a single answer for the entire collection. KeywordsThese expressions are formed using one of several keywords. They are:
All but the last of these keywords is expected to be followed by one expression, its argument, that applies to business objects. The last one, correlation, needs to be followed by two such expressions. Alternative spellings are indicated in parentheses. For each keyword, you can use all lowercase, all uppercase, or first character uppercase followed by all lowercase. Count The For example, when the following expression is evaluated, it indicates the number of objects of Type ‘Body Panel’ in the database:
Evaluating the following returns the number of objects in the set “NewBooks” whose cost is between 10 and 50:
To do the same, but exclude children’s books, you could use the following:
Or change the expression to:
Sum
The following commands evaluate the ratio of total price to total cost for all objects in the set “Components”:
Maximum, Minimum, Average
Median
For example, the following shows the values, listed in numerical order, for the attribute Actual Weight for seven business objects that comprise the set FprSet:
Since the middle number of seven numbers is the fourth number, the median in this case is 25. That is the value returned for the following command:
Standard Deviation
Use For example, if you know the average age of all employees, you might want to know how many people are close to that age. The standard deviation will tell you, on average, how much the ages of the group differ from the mean. If the standard deviation is a small number, it could indicate that most of the people are close to the average age. If the standard deviation is a large number, it could indicate that there is a broader spread of ages. The following example performs a standard deviation on the age attribute of all persons in the set Employees:
Correlation
For example, the following expression can be used to check how well cost correlates with price for all objects of Type “tire frame”.
Evaluating ExpressionsThe SyntaxTo evaluate an expression, use the evaluate expression command:
Expressions can be evaluated against individual objects or against groups of objects. When the on clause is used, the expression will be evaluated as a single-object expression. The on clause can be repeated to get the value for multiple separate objects. For example:
You can also identify a collection of objects for the expression evaluation
using the keywords set, query, temp set, temp query, or expand in the
SEARCHCRITERIA. When any of these keywords are used, the expression will be
evaluated as a collection, and must use one of these collection expressions:
If you use a single-object expression and provide a searchcriteria that identifies a collection or vice-versa, there will be no output. Expressions can be evaluated on these items:
The DUMP and recordseparator clauses can occur anywhere in the command, but
the This command outputs the result of evaluating each expression for each
Evaluating Saved ExpressionsYou can evaluate a saved expression as part of an expression string, or by using the Select Expression clause with print bus or print connection commands. For example: eval expr ‘count expression[SAVEDEXPRESSION]’ on set myset; print bus OBJECTID select expression[SAVEDEXPRESSION]; print connection CONNECTID select expression[SAVEDEXPRESSION]; You can also do this in a webreport:
In this last example the expression object is being evaluated against a collection. SEARCHCRITERIA ClauseSEARCHCRITERIA is defined recursively as one of:
The values of
The values of
Leaf is not allowed in the expand bus command, but is allowed here. An “expand” searchcriteria does not make sure that returned objects are unique. That is, any objects that are connected more than once to the object(s) being expanded (or recursed to) will be listed more than once. This affects webreports, eval expression, and other commands using searchcriteria. For example, the following might return a list containing duplicate entries: MQL<18>eval expres "count TRUE" on ( expand bus t2 t2-1 0 );
To avoid the duplication, you could change the searchcriteria to the following: temp query * * * over expand bus t2 t2-1 0 The output from evaluating two expressions, E1 and E2, on two sets, A and B, with values V1A, V2A, V1B, and V2B would look like the following (using default separators):
SEARCHCRITERIAs can be linked with binary operators, which follow simple, intuitive rules:
If there is more than one binary operator in a SEARCHCRITERIA , parentheses must be used to disambiguate the clause. (There is no implied order of operations.) You must include a space before and after each parenthesis. In addition, the number of left and right parentheses must match each other. For example: ( set A + set B ) - set C would probably evaluate differently than: set A + ( set B - set C ) Examples: This list of examples shows the power of the SEARCHCRITERIA concept. The following command returns the number of objects in the set Projects:
The same thing could be written as follows (you need to include the spaces around the parentheses):
The following command returns the number of objects returned by a query named “ask1” that are not Project 1029 0:
The following command returns the number of Jim’s open Projects that originated before the beginning of this year:
The following command returns the number of open, new Projects that do not belong to Jim:
The following command returns the number of Projects that are either owned by Jim or included in the set “Q4 Projects”:
Copy ExpressionAfter an expression is defined, you can clone the definition with the copy expression command. This command lets you duplicate defining clauses with the option to change the value of clause arguments.
Cloning an expression definition requires expression Business Administrator privileges. These can be granted using MQL. Modify ExpressionUse the Modify expression command to add or remove defining clauses and change the value of clause arguments.
Each modification clause is related to the arguments that define the expression. To change the value of one of the defining clauses or add a new one, use the Modify clause that corresponds to the desired change. Delete ExpressionIf an expression is no longer required, you can delete it using the Delete expression command.
Searches the list of defined expressions. If the name is found, that expression is deleted. If the name is not found, an error message is displayed. For example, to delete the expression named “Used Parts,” enter the following:
After this command is processed, the expression is deleted and you receive an MQL prompt for another command. ExamplesThe following example combines several of the capabilities available for expressions. This example shows how to obtain the average number of days spent to move a feature from Open to Test for v7.0 and v7.1 through one MQL command. We divide by (3600 * 24) (the number of seconds in a day) because we want the number of days and the difference of two dates is given in seconds.
The next example calculates the number of Features connected to v7.2 that have been promoted to Test in the past week (and have not been demoted).
|