Using RTL classes

The Report Template Language (RTL) expressions are typed; that is, the expression must return a particular class.

RTL expressions do not contain the primitive data types "byte", "short", "int", "long", "float", "double", "boolean" and "char". Instead, everything is expressed as objects. All methods are member functions. There are no global functions.

Basic Object Classes

There are object classes for each type of the report item properties. See the Properties documentation to identify the type of a specific property.

The basic object class types for properties are:

  • String - contains methods used for all string operations
  • Numeric - contains methods used for all numeric operations; the class has the precision of a double and the arithmetic operators are defined for objects of this type.
  • Boolean - contains methods used for all logical operations
  • Color - contains methods and static member variables related to color.
  • Enum - a set consisting of a class for each property of this type; each class contains static member variables that provide a list of valid values for the corresponding property.
  • Date - a class representing a Date value; contains methods for parsing and formatting strings.

Members

Instance Member Methods

Instance Member methods are called on an object instance. You can get an object instance by referencing a 4GL variable or by calling a method on another object. You can also use a literal value as an object instance.

When you invoke the method, it is prefixed with the object instance name and the "." character.

Examples of instance methods are expressions like "order_line.customer_name.trim()". This is valid because the 4GL variable order_line.customer_name has a CHAR data type, which is converted within the RTL Expression to an object of the type String. And, the method trim() is a member function of a String object.

Methods always yield objects, so it is also legal to call methods on the return value of a method.

Static Member Methods
Static Member methods do not require an object instance. When you invoke the method, it is prefixed with the classname and the '.' character.
Static Member Objects
Static Member objects are member variables that do not require an object instance. The objects are prefixed with the classname and the '.' character. Examples of static member objects are expressions like "Color.RED" or "Numeric.PI".

Examples

  1. This example concatenates the first and last names of a customer, using the trim method of the String class and the + operator:
     order_line.shipfirstname.trim()+" "+order_line.shiplastname.trim()

    This expression prints the first name (trimmed of trailing blanks), a string consisting of a single space, and the last name (trimmed). Use double quotes instead of single quotes to delimit strings.

  2. Parenthesis can be used to change the order of operations. For example:
    (order_line.unitprice+10).toString()

    Parentheses are used to force the addition to be done prior to the conversion to a String.

  3. This conditional expression used in the color property of the order_line.unitprice WordBox will change the color to red if the value is less than 20:
     order_line.unitprice<20?Color.RED:Color.BLACK

    This expression specifies that the return value when the boolean expression is TRUE is the static member variable RED of the Color class, otherwise the return value is the static member variable BLACK.

  4. It is legal to call methods on the return value of a method. For example, this is a valid expression:

    Figure: order_line.customer_name.trim().toUpperCas().substring(1)


    This figure shows a valid expression example as described in this topic.

    In this example, the object order_line.customer_name is a BDL CHAR variable; this variable is assigned to the String type. The String method trim() is called first, returning the String object a. The method toUpperCase() is called for the object a, returning object b which will be in upper case. Finally, the method substring() is called for the object b, returning object c. If the customer_name is "Springs", the resulting object c is the string "PRINGS".

    There are many additional examples of expressions in the properties of report elements defined in the 4rp programs that are part of the GRWDemo project.