OCONV function

Syntax

OCONV (string, conversion)

Description

Use the OCONV function to convert string to a specified format for external output. The result is always a string expression.

string is converted to the external output format specified by conversion.

conversion must evaluate to one or more conversion codes separated by value marks (ASCII 253).

If multiple codes are used, they are applied from left to right as follows: the leftmost conversion code is applied to string, the next conversion code to the right is then applied to the result of the first conversion, and so on.

If string evaluates to the null value, null is returned. If conversion evaluates to the null value, the OCONV function fails and the program terminates with a run-time error message.

The OCONV function also allows PICK flavor exit codes.

The STATUS function reflects the result of the conversion:

0
The conversion is successful.
1
An invalid string is passed to the OCONV function; the original string is returned as the value of the conversion. If the invalid string is the null value, null is returned.
2
The conversion code is invalid.
3
Successful conversion of possibly invalid data.

For information about converting strings to an internal format, see the ICONV function.

Examples

The following examples show date conversions:

Source Line
Converted Value
DATE=OCONV('9166',"D2")
3 Feb 93
DATE=OCONV(9166,'D/E')
3/2/1993
DATE=OCONV(9166,'DI')1
3/2/1993
DATE=OCONV('9166',"D2-")
2-3-93
DATE=OCONV(0,'D')
31 Dec 1967

1For IN2, PICK, and REALITY flavor accounts.

The following examples show time conversions:

Source Line
Converted Value
TIME=OCONV(10000,"MT")
02:46
TIME=OCONV("10000","MTHS")
02:46:40am
TIME=OCONV(10000,"MTH")
02:46am
TIME=OCONV(10000,"MT.")
02.46
TIME=OCONV(10000,"MTS")
02:46:40

The following examples show hex, octal, and binary conversions:

Source Line
Converted Value
HEX=OCONV(1024,"MX")
400
HEX=OCONV('CDE',"MX0C")
434445
OCT=OCONV(1024,"MO")
2000
OCT=OCONV('CDE',"MO0C")
103104105
BIN=OCONV(1024,"MB")
10000000000
BIN=OCONV('CDE',"MB0C")
010000110100010001000101

The following examples show masked decimal conversions:

Source Line
Converted Value
X=OCONV(987654,"MD2")
9876.54
X=OCONV(987654,"MD0")
987654
X=OCONV(987654,"MD2,$")
$9,876.54
X=OCONV(987654,"MD24$")
$98.77
X=OCONV(987654,"MD2-Z")
9876.54
X=OCONV(987654,"MD2,D")
9,876.54
X=OCONV(987654,"MD3,$CPZ")
$987.654
X=OCONV(987654,"MD2,ZP12#")
####9,876.54