Type Conversion Functions

This section describes functions that are used to perform conversions between different types.

The following functions for Type Conversion described here are:


baToBigInt

Converts a bytearray to a big integer (two complement).

void baToBigInt
 (bigint bigintVar,
 bytearray baValue)
ParameterDescription

bigintVar

Bigint variable to set

baValue

Bytearray value

Returns

Nothing


baToHexString

Converts a bytearray to a string containing the hexadecimal values.

string baToHexString(bytearray baValue)
ParameterDescription

baValue

Bytearray value

Returns

A hexadecimal string


baToStr

Converts a bytearray to a string.

string baToStr
 (bytearray array,
 string charEncoding) //Optional
ParameterDescription

array

The bytearray to convert

charEncoding

The character encoding to use. If no encoding is specified, ISO-8859-1 (Latin 1) is used.

If you specify character encoding, it must match the character encoding included in the standard charsets found in https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/charset/Charset.html or the extended charset of the target Java implementation. If you specify a character encoding that cannot be found, a compilation error occurs.

Returns

The result string


dateToString

Converts a date to a string and assigns the result to a string variable (or field). Returns true if the conversion succeeded. The only time the conversion can fail, is if the date is null or the format is invalid.

boolean dateToString
 (string stringVar,
 date dateValue,
 string format) //optional
ParameterDescription

stringVar

String identifier to set.

dateValue

The date value.

format

If no format string is specified, the default system format is used as specified in the property mz.server.dateformat. For further information about this property, see Cell in the System Administrator's Guide.

The date formatting is based on standard Java syntax. For further information, see https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/text/SimpleDateFormat.html.

Returns

true or false.


strToBA

Converts a string to a bytearray and assigns the result to a bytearray variable (or field).

void strToBA
 (bytearray array,
 string stringValue,
 string charEncoding) //Optional
ParameterDescription

array

The resulting bytearray

stringValue

The string value

charEncoding

The character encoding to use. If no encoding is specified, ISO-8859-1 (Latin 1) is used.

If you specify character encoding, it must match the character encoding included in the standard charsets found in https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/charset/Charset.html or the extended charset of the target Java implementation. If you specify a character encoding that cannot be found, a compilation error occurs.

Returns

Nothing


strToBigInt

Converts a string to a big integer. If the conversion was successful true is returned.

If one of the keywords dec or hex are specified, the string is assumed to be decimal or hexadecimal respectively. Decimal is the default.

boolean strToBigInt
 (bigint bigintVar,
 string stringValue, 
 dec|hex) //Optional
ParameterDescription

bigintVar

Big integer variable to set

stringValue

String value

Returns

true or false


strToDate

Converts a string to a date and assigns the result to a date variable (or field). Returns true if the conversion succeeded.

You can enable lenient interpretation of the date/time in the string to be converted by setting the Cell property mz.drdate.lenient to true in the cell.conf. With lenient interpretation, a date such as "January 32, 2016" will be treated as being equivalent to the 31nd day after January 1, 2016. With strict (non-lenient) interpretation, an invalid date will cause the function to leave the submitted date variable unchanged. The default value of mz.drdate.lenient is false.

boolean strToDate
 (date dateVar,
 string stringValue,
 string format, //Optional 
 string timeZone) //Optional
ParameterDescription

dateVar

Date identifier to set

stringValue

Date value

format

If no format string is specified, the default system format is used as specified in $MZ_HOME/common/config/cell/default/master/cell.conf, the mz.server.dateformat property.

The date formatting is based on standard Java syntax. For further information, see https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/text/SimpleDateFormat.html.

Note!

Even though the syntax conforms to SimpleDateFormat, it is not directly based on this class.

You can enable date format handling based on the SimpleDateFormat class in the installed Java version by setting the Execution Context property mz.use.drdateformat to false. This enables use of additional patterns that are available in the installed Java version.

$ mzsh topo set topo://container:<container>/pico:<pico name>/val:config.properties.mz.use.drdateformat false



When mz.use.drdateformat is set to true (default), the function does not apply the timezone offset at conversion. The timezone can be specified but the date is not modified.

Note!

Unlike SimpleDateFormat the strToDate function does not accept the Locale parameter and uses the default JVM locale instead, which may result in parsing errors.

If this is an issue, it can be solved by setting the locale to US_en in the JVM arguments of the relevant EC.

$ mzsh topo set topo://container:<container>/pico:<pico name>/obj:config.jvmargs \
'usercountry: ["-Duser.country=US"]
userlanguage: ["-Duser.language=en"]'

timeZone

An optional string stating the time zone to set.

It is recommended that you specify the time zone id using the long format, e g "America/St_Johns". It is possible to also use the abbreviated format, e g "PST". However, this can lead to ambiguous results and should be avoided. If an invalid time zone format is entered, no error is returned. Instead, the time zone is automatically set to "GMT". If the time zone is specified in the stringValue , it overrides the timeZone parameter.

Returns

true or false.


strToDouble

Converts a decimal string to a double and assigns the result to a double variable (or field). Returns true if the conversion succeeded.

boolean strToDouble
 (double doubleVar,
 string stringValue)
ParameterDescription

doubleVar

Double identifier to set.

stringValue

String value.

Returns

true or false.


strToFloat

Converts a decimal string to a float and assigns the result to a float variable (or field). Returns true if the conversion succeeded.

boolean strToFloat
 (float floatVar,
 string stringValue)
ParameterDescription

floatVar

Float identifier to set

stringValue

String value

Returns

true or false


strToInt

Converts a decimal or hexadecimal string to an integer and assigns the result to an integer variable (or field). Returns true if the conversion succeeded.

If one of the keywords dec or hex are specified, the string is assumed to be decimal or hexadecimal respectively. Decimal is the default.

boolean strToInt
 (int intVar,
 string stringValue, 
 dec|hex) //Optional



ParameterDescription

intVar

Integer identifier to set.

stringValue

String value.

Returns

true or false.

Example - Using strToInt

Provided that the field CallTime is a string containing a hexadecimal string, it converts its content to an integer.

int a;
int b;
strToInt( a, CallTime, hex );
strToInt( b, "12345" ); /* dec is default */

strToLong

Converts a decimal or hexadecimal string to a long and assigns the result to an long variable (or field). Returns true if the conversion succeeded.

If one of the keywords dec or hex are specified, the string is assumed to be decimal or hexadecimal respectively. Decimal is the default.

boolean strToLong
 (long longVar,
 string stringValue, 
 dec|hex) //Optional
ParameterDescription

longVar

Long identifier to set

stringValue

String value

Returns

true or false


strToBigDec

Converts a decimal or hexadecimal string to a BigDecimal and assigns the result to a BigDecimal variable (or field). Returns true if the conversion succeeded.

boolean strToBigDec
 (bigdec bigdecVar,
 string stringValue)
ParameterDescription

bigdecVar

BigDecimal identifier to set

stringValue

String value

Returns

true or false

udrToString

Converts a UDR to a string. Each UDR will be preceded with the internal class name, and each of its field will be preceded with the field name.

string udrToString(drudr myUDR)
ParameterDescription

myUDR

The UDR to convert

Returns

A string containing the UDR fields. The output will be in the following format:

Field values for: 
<internal UDR reference>
field1: <value>
field2: <value>