Where Clause for the Expand Businessobject Command

When expanding business objects, you can use where clauses as another means of specifying which objects to list. When using this technique, you must always insert select bus or select rel before the where clause. This tells the system whether to apply the where clause to the relationships it finds or to the objects on the other end of those relationships. It does not, however, select and print out any information about the connected objects or expanded relationships (unless another SELECT_BO or SELECT_REL clause is included.

This page discusses:

Rules for Where Clauses

  • Always enclose the entire where clause in single quotes and a space.
  • Always surround operators with spaces.
  • In expand bus, if you can safely be specific about the relationship type and direction to be expanded, this syntax is quicker:
    expand bus T N R <direction> rel <relnameList> select <rel-or-bus> where...

    It returns only the correctly named and directed relationships and filter those relationships (or the business objects on the other ends for select bus ) through the Where clause.

  • If you also know which Types you are looking for, use the type modifier for expand bus rather than relegate it to the Where clause:
    expand bus T N R from rel Rel type "Type two"
      select rel where ' <other qualifiers on the rel>; '
      select bus where ' <other qualifiers on the TO obj's> '

Applying the Where Clause to Business Objects

Use this syntax for where clauses to filter based on business objects:

mql expand bus Type_one Object_1 Rev_1
  select bus 
  where ' (type == "Type two") && (1 == 1) ' dump

Applying the Where clause to Relationships

Since the where clause works off the rel, you must use ‘to.type’.

mql expand bus Type_one Object_1 Rev_1 
  select rel
  where ' (to.type == "Type two") && (1 == 1) ' dump

Alternatively, you can let expand bus check the object type for you (for more information, see Rules for Where Clauses):

mql expand bus Type_one Object_1 Rev_1
  type "Type two"
  select rel
  where ' (1 == 1) ' dump

The first command above is more general, ignoring the direction of the relationship, and the second command only finds Type two’s at the end of relationships pointing from Object_1 to the Type 2 object.

If you only want objects connected to Object_1 by the relationship Rel, add ‘rel Rel’:

mql expand bus Type_one Object_1 Rev_1 
  rel Rel
  select bus
  where ' (type == "Type two") && (1 == 1) ' dump

If you only want to look at the relationship Rel coming from Object_1, add ‘from rel Rel’. This is equivalent to the REL syntax above:

mql expand bus Type_one Object_1 Rev_1
  from rel Rel
  select bus
  where ' (type == "Type two") && (1 == 1) ' dump

Using Where Clauses to Filter Connections and Business Objects

To include more extensive filtering, you can also include Where clause criteria in the square brackets of select from[].to[] or to[].from[] clauses. The relationship or type name pattern is specified first, and then can be followed by the Where clause, the fields delimited by the “|” character. For example:

print bus Drawing My Drawing 0 select from[D*|attribute[RelCount] ~~ "*1"];

The Where clauses are handled exactly as expand bus would handle them. For example, consider a business object Drawing “My Drawing” 0 which has 3 “Drawing of” relationships coming from it, and 2 “Part of Drawing” relationships. On the “Drawing of” relationships, the attribute values for RelCount are 1, 11, and 12. The 3 “Drawing of” relationships point to objects of types Drawing, Sketch and Drawing Markup and these objects have attribute Count values of 1, 11, and 12. The following shows all of this information (and a bit more):

print bus Drawing “My Drawing” 0 select from.type
 	from[Drawing of].attribute[RelCount]
 	from[Drawing of].to.type 	from.to.attribute[Count];
business object  Drawing "My Drawing" 0
  from[Drawing of].type = Drawing of
  from[Drawing of].type = Drawing of
  from[Drawing of].type = Drawing of
  from[Part of Drawing].type = Part of Drawing
  from[Part of Drawing].type = Part of Drawing
  from[Drawing of].attribute[RelCount] = 1
  from[Drawing of].attribute[RelCount] = 12
  from[Drawing of].attribute[RelCount] = 11
  from[Drawing of].to.type = Drawing
  from[Drawing of].to.type = Drawing Markup
  from[Drawing of].to.type = Sketch
  from[Drawing of].to.attribute[Count] = 11
   from[Drawing of].to.attribute[Count] = 1
  from[Drawing of].to.attribute[Count] = 12
  from[Part of Drawing].to.attribute[Count] = 1
  from[Part of Drawing].to.attribute[Count] = 1

To get back ONLY the “Drawing of” relations with specified values of RelCount, we could use:

print bus Drawing "My Drawing" 0 select from[Drawing of|attribute[RelCount] ~~ 
"*2"].attribute[RelCount]; 
business object  Drawing "My Drawing" 0
  from[Drawing of].attribute[RelCount] = 12

To specify the type of other objects for “Drawing of” relations:

print bus Drawing "My Drawing" 0 select
 	from[Drawing of].to[*|type ~~ "*up*"].type; 
business object  Drawing "My Drawing" 0 
  from[Drawing of].to[Drawing Markup].type = Drawing Markup

To specify attribute values on the other object for “Drawing of” relations:

print bus Drawing "My Drawing" 0 select
 	from[Drawing of].to[*|attribute[Count] ~~ "*1"].attribute[Count]; 
business object  Drawing "My Drawing" 0
  from[Drawing of].to[Drawing Markup].attribute[Count] = 11
  from[Drawing of].to[Sketch].attribute[Count] = 1