Skip to main content

Constants

String

All string literals must be contained within single quotation marks ( ' ' ). All ECL code is UTF-8 encoded, which means that all strings are also UTF-8 encoded, whether Unicode or non-Unicode strings. Therefore, you must use a UTF-8 editor (such as the ECL IDE program).

To include the single quote character (apostrophe) in a constant string, prepend a backslash (\). To include the backslash character (\) in a constant string, use two backslashes (\\) together.

STRING20 MyString2 := 'Fred\'s Place';
                     //evaluated as: "Fred's Place"
STRING20 MyString3 := 'Fred\\Ginger\'s Place';
                    //evaluated as: "Fred\Ginger's Place"

Other available escape characters are:

\ttab
\nnew line
\rcarriage return
\nnn3 octal digits (for any other character)
\uhhhhlowercase "u" followed by 4 hexadecimal digits (for any other UNICODE-only character)
MyString1 := 'abcd'; 
MyString2 := U'abcd\353';    // becomes 'abcdë'

Hexadecimal string constants must begin with a leading "x" character. Only valid hexadecimal values (0-9, A-F) may be in the character string and there must be an even number of characters.

DATA2 MyHexString := x'0D0A'; // a 2-byte hexadecimal string

Data string constants must begin with a leading "D" character. This is directly equivalent to casting the string constant to DATA.

MyDataString := D'abcd'; // same as: (DATA)'abcd'

Unicode string constants must begin with a leading "U" character. Characters between the quotes are utf8-encoded and the type of the constant is UNICODE.

MyUnicodeString1 := U'abcd';        // same as: (UNICODE)'abcd'
MyUnicodeString2 := U'abcd\353';    // becomes 'abcdë'
MyUnicodeString3 := U'abcd\u00EB'; // becomes 'abcdë'«'

UTF8 string constants must begin with leading "U8" characters. Characters between the quotes are utf8-encoded and the type of the constant is UTF8.

MyUTF8String := U8'abcd\353';

VARSTRING string constants must begin with a leading "V" character. The terminating null byte is implied and type of the constant is VARSTRING.

MyVarString := V'abcd'; // same as: (VARSTRING)'abcd'

QSTRING string constants must begin with a leading "Q" character. The terminating null byte is implied and type of the constant is VARSTRING.

MyQString := Q'ABCD'; // same as: (QSTRING)'ABCD'

Numeric

Numeric constants containing a decimal portion are treated as REAL values (scientific notation is allowed) and those without are treated as INTEGER (see Value Types). Integer constants may be decimal, hexadecimal, or binary values. Hexadecimal values are specified with either a leading "0x" or a trailing "x" character. Binary values are specified with either a leading "0b" or a trailing "b" character.

MyInt1  := 10;     // value of MyInt1 is the INTEGER value 10
MyInt2  := 0x0A;   // value of MyInt2 is the INTEGER value 10
MyInt3  := 0Ax;    // value of MyInt3 is the INTEGER value 10
MyInt4  := 0b1010; // value of MyInt4 is the INTEGER value 10
MyInt5  := 1010b;  // value of MyInt5 is the INTEGER value 10
MyReal1 := 10.0;   // value of MyReal1 is the REAL value 10.0
MyReal2 := 1.0e1;  // value of MyReal2 is the REAL value 10.0

Compile Time Constants

The following system constants are available at compile time. These can be useful in creating conditional code.

__ECL_VERSION__A STRING containing the value of the platform version. For example, '6.4.0'
__ECL_VERSION_MAJOR__ An INTEGER containing the value of the major portion of the platform version. For example, '6'
__ECL_VERSION_MINOR__An INTEGER containing the value of the minor portion of the platform version. For example, '4'
__ECL_LEGACY_MODE__A BOOLEAN value indicating if it is being compiled with legacy IMPORT semantics.
__OS__A STRING indicating the operating system to which it is being compiled. Possible values are: 'windows', 'macos', or 'linux'.
__STAND_ALONE__A BOOLEAN value indicating if it is being compiled to a stand-alone executable.
__TARGET_PLATFORM__A STRING containing the value of the target platform (the type of cluster the query was submitted to). Possible values are: 'roxie', 'hthor', or 'thorlcr'.

Example:

IMPORT STD;
  STRING14 fGetDateTimeString() :=
  #IF(__ECL_VERSION_MAJOR__ > 5) or ((__ECL_VERSION_MAJOR__ = 5) AND (__ECL_VERSION_MINOR__ >= 2))
    STD.Date.SecondsToString(STD.Date.CurrentSeconds(true), '%Y%m%d%H%M%S');
  #ELSE
    FUNCTION
      string14 fGetDimeTime():= // 14 characters returned
      BEGINC++
      #option action
      struct tm localt;         // localtime in "tm" structure
      time_t timeinsecs;        // variable to store time in secs
      time(&timeinsecs);  
      localtime_r(&timeinsecs,&localt);
      char temp[15];
      strftime(temp , 15, "%Y%m%d%H%M%S", &localt); // Formats the localtime to YYYYMMDDhhmmss 
      strncpy(__result, temp, 14);
      ENDC++;
      RETURN fGetDimeTime();
    END;
  #END;

Runtime Expressions

The following system constants are evaluated at runtime. Technically, these are runtime expressions, not constants. Therefore, they cannot be used in conditional code that requires a constant.

__PLATFORM__A STRING that represents the type of engine where the query is executing on. Possible values are: 'roxie', 'hthor', or 'thorlcr'.