Siebel eScript Language Reference > Siebel eScript Language Overview > Data Types in Siebel eScript >

Implicit Type Conversion in Siebel eScript


Siebel eScript performs implicit data type conversion in many mixed-type contexts. However, to make sure that your code performs conversions as you expect it to, you should use conversion functions that are provided for that purpose, and you should test your code prior to putting it into production.

For more information on conversion methods, see Conversion Methods.

The rules governing run-time conversion of data types vary and depend on:

  • Whether the type mismatch is in the context of a value assignment or the result of concatenation
  • Whether the variables involved are typeless or strongly typed

Implicit Type Conversion Resulting from Concatenation in eScript

Data type conversion of typeless variables occurs implicitly during concatenation involving both strings and numbers and is subject to the following rules.

  • Subtracting a string from a number or a number from a string converts the string to a number and performs subtraction on the two values.
  • Adding a string to a number or a number to a string converts the number to a string and concatenates the two strings.
  • Strings always convert to a base 10 number and must not contain any characters other than digits. The string "110n" does not convert to a number because the n character is meaningless as part of a number in Siebel eScript.

The following examples illustrate these implicit conversions:

s = "dog" + "house"   // s = "doghouse", two strings are concatenated.
t = "dog" + 4         // t= "dog4", a number is converted to a string
u = 4 + "4"           // u = "44", a number is converted to a string
v = 4 + 4             // v = 8, two numbers are added
w = 23 - "17"          // w = 6, a string is converted to a number

To make sure that type conversions are performed when doing addition, subtraction, and other arithmetic, use conversion methods. The following example uses a conversion method to transform string input to numeric to perform arithmetic:

var n = "55";
var d = "11";
var division = Clib.div(ToNumber(n), ToNumber(d));

To specify more stringent conversions, use the parseFloat() Method of the global object. Siebel eScript has many global functions to convert data to specific types. Some of these are not part of the ECMAScript standard.

NOTE:  There are circumstances under which conversion is not performed implicitly. If you encounter such a circumstance, you must use one of the conversion functions to get the desired result. For an explanation of conversion functions, see Conversion Methods.

Implicit Type Conversion Resulting from Assignment in eScript

Implicit type conversion resulting from assignment differ for typeless and strongly typed variables.

  • Typeless variables. Conversion occurs implicitly during assignment involving typeless variables only. For example, the following assignments result in variable a assuming the String type.

    var a = 7.2;
    var b = "seven point 2"
    a = b;

  • Strongly Typed variables. Table 6 provides a mapping of types and the results of implicit type conversion during assignment of mixed types. Interpret the table as follows:
    • For the assignment a = b, types for variable a are in the left column, and types for variable b are in the top row. Thus, the assignment attempts to convert a's data type to that of b.
    • For a given data type for each of a and b, the intersection cell in the table specifies whether a's type is implicitly converted to that of b.
      • "Y" indicates that the implicit conversion occurs.
      • "w" indicates that a message may display at compile time warning that the conversion may not occur. Whether a conversion occurs and whether a warning displays depends on the properties of the variables involved in the assignment.
      • "err" indicates that a compilation error occurs.
      • "NA" indicates that there is no conversion needed. Typically, conversion is not required when a variable of Object (a generic object) is converted to a specialized object type.
      • "-" indicates that a and b are of the same type.
    • "value" denotes a typeless variable. Thus, the row and column with "value" headings specify conversions when strongly typed variables are assigned to typeless variables, and vice-versa.
    • "*" denotes objects other than the eScript built-in objects Object, String, Number, and Boolean. These other objects include prebuilt objects and user-defined objects.
      Table 6. Implicit Type Conversion of Strongly Typed Variables that Are Assigned
      a
      = b
      value
      chars
      bool
      float
      Object
      String
      Number
      Boolean
      *

      value

      -

      Y

      Y

      Y

      Y

      Y

      Y

      Y

      Y

      chars

      Y

      -

      Y

      Y

      Y

      Y

      Y

      Y

      Y, w1

      bool

      Y

      Y

      -

      Y

      Y

      Y

      Y

      Y

      Y

      float

      Y

      Y, w

      Y

      -

      Y, w

      Y, w

      Y

      Y

      Y, w

      Object

      Y

      err

      err

      err

      -

      NA

      NA

      NA

      NA

      String

      Y

      Y

      err

      err

      err

      -

      err

      err

      err

      Number

      Y

      err

      err

      Y

      err

      err

      -

      err

      err

      Boolean

      Y

      err

      Y

      err

      err

      err

      err

      -

      err

      *

      Y

      err

      err

      err

      err

      err

      err

      err

      -

      1toString

Siebel eScript Language Reference Copyright © 2007, Oracle. All rights reserved.