Ranges Defined Within a Program for the Add Attribute Command

The range clause allows you to use a program to define range values. This allows the flexibility to change range values depending on conditions. Use the range program clause to specify the name of the program to execute.

For example:

range program SetRanges;

In this example, the name of the program to execute is SetRanges.

You can define arguments to be passed into the program. Your program could change the attribute range depending on the argument passed. For example:

range program SetRanges attrang1;

When you pass arguments into the program they are referenced by variables within the program. Variables 0, 1, 2. . . and so on are reserved by the system for passing in arguments.

Environment variable “0” always holds the program name and is set automatically by the system.

Arguments following the program name are set in environment variables “1”, “2”, . . . and so on.

Programs should return the list of choices in the variable that has the same name as the program name, which can be obtained through argument “0.” Be sure to use the global keyword on your set env command when passing the list back.

The following is output from a MQL session. The attribute type ‘designerName’ produces the choices ‘Tom,’ ‘Dick,’ ‘Harry,’ ‘Larry,’ ‘Curly,’ and ‘Moe.’ An attribute type can have any number of ranges, but only one range can be of type program.

MQL<1>print attr designerName;
attribute designerName
 type string
 description
 default Tom
 range = Tom
 range = Dick
 range = Harry
 range uses program nameRange
 not multiline
MQL<2>print prog nameRange;
program nameRange
 mql
 description
 code 'tcl;
eval {
 # set the event
 set event [mql get env EVENT]
 # set the choices
 set names {Larry Curly Moe}
 # set the output variable (arg 0 is this program's name)
 set output [mql get env 0]
# test event, and either generate choices, or test value
 if { $event == "attribute choices"} {
    # note that choices are returned in a global RPE variable
    mql set env global $output $names
 } else {
    # assume that it is safe to unset global RPE variable during value
 test
    mql unset env global $output
    # set the value
    set value [mql get env ATTRVALUE]
# test the value
    if {[lsearch -exact $names $value] == -1} {
      # value not in list, return non-zero
      exit 1
   } else {
      # value in list, return zero
      exit 0
   }
 }
}

The following macros are available to Range Programs:

  • Owning item information macros:
    • If the attribute is “owned” by a business object, these macros are available: OBJECT, TYPE, NAME, and REVISION.
    • If a relationship instance “owns” the attribute, the RELID macro is provided.
    • During query formulation the owner is unknown so no owner macros are available.
  • INVOCATION will always equal “range”.
  • EVENT and possibly ATTRVALUE. For example:
    • When the range program is being asked to produce all legal values, EVENT equals “attribute choices”.
    • When the range program is being asked to check the legality of a given value, EVENT equals “attribute check” and the ATTRVALUE macro is also provided.
  • ATTRNAME and ATTRTYPE. For example:

    ATTRNAME=designerName

    ATTRTYPE=String

  • Basic information: VAULT, USER, TRANSACTION, HOST, APPLICATION, and LANGUAGE.

For more information about macros, see Appendix: Macros.