Conversions

DataBasic performs a subset of the input and output conversions available in English (see English Reference.). DataBasic conversions operate in the same way as their English equivalents. Input and output conversions are performed by the ICONV and OCONV functions respectively; output conversions can also be performed by format strings and the FMT function.

Input conversions (ICONV) are equivalent to the processing English carries out when an attribute value in an English statement is converted for comparison with a stored value.

Output conversions (OCONV) are equivalent to the processing English carries out on values before output to a terminal or printer.

Output Conversions

Output conversions, for the most part, convert from some internal format or internally stored data to an output format. Date and time are stored internally as integers and converted to normal date and time strings by an output conversion.

The format strings are, themselves, output conversions. Therefore, output conversions that are to be printed (with the PRINT or CRT statements) can be executed as a type of format string. The conversion expression is used as the parameter of the format string. For example:

PRINT OCONV(DATE(),'D2/')

The above example can be output as a format string:

PRINT DATE() 'D2/'

Output conversions can be assigned, as:

DAY=OCONV(DATE(),'D')

The same output conversion performed as a format string can also be assigned. The following example is equivalent to the above example:

DAY=DATE() 'D' 

Additional examples of equivalent output conversions are shown below.

Examples of output conversions

ASC = "ABC123"
PRINT OCONV(ASC,"MX")
ASC = "ABC1123"
PRINT ASC "MX"

Both of the above examples convert the ASCII string "ABC123" to ASCII hexadecimal and print the value 414243313233.

Input Conversions

Input conversions convert from an external format to a format for internal data storage. They are accomplished by the ICONV function.

Date Output Conversions

You can use English date conversions with output format strings and the OCONV function.

External to Internal Date Conversion

Conversion from external date format to internal date format is an input conversion normally performed by the ICONV function. However, dates can be stored in a file in external format and you might have the need to convert to internal format as an output function. For that, the DI conversion is provided.

DI is a special case of date conversion. It allows you to convert from external to internal format as an output conversion, the inverse of the normal D conversion.

Because DI is used as an output conversion, it can also be specified as a type of DataBasic format string to convert a date to internal format.

All three of the following examples produce the same result:

INPUT EXTERNAL.DATE
INTERNAL.DATE = ICONV(EXTERNAL.DATE,'D')
CRT INTERNAL.DATE
INPUT EXTERNAL.DATE
INTERNAL.DATE = OCONV(EXTERNAL.DATE,'DI')
CRT INTERNAL.DATE
INPUT EXTERNAL.DATE
INTERNAL.DATE = EXTERNAL.DATE 'DI'
CRT INTERNAL.DATE

Mask Character Conversions

You can use English mask character conversions with output format strings and the OCONV and ICONV functions. For details, refer to Conversion Codes in English Reference.

User Exit Conversions

User exit codes can be used with both the ICONV and OCONV intrinsic functions to perform input and output conversions.

TCL Commands that Modify Conversions

TCL command DATE-FORMAT allows you to override, for the local port and for the duration of the current session only, the default date format for the database, as produced by, for example, the D2/ conversion (this outputs in one of the numeric formats mm/dd/yy or dd/mm/yy, known as 'US' and 'International' date format respectively).

You can set options in your operating environment to modify some system functionality, including the operation of F conversion codes and of D conversion codes that produce alphabetic output. D code operation can be changed so that output with initial capitals can be produced instead in all upper case, which is especially useful for providing compatibility with earlier releases.