Try OpenEdge Now
skip to main content
GUI for .NET Programming
Using .NET data types in ABL : Passing ABL data types to .NET constructor and method parameters : Data type widening
 

Data type widening

Object-oriented programming, in support of strong typing, typically requires any argument that you pass to a constructor or method parameter to have a data type that exactly matches the data type used to define the parameter. Widening is a feature of many object-oriented programming languages that allows you to pass a different data type to a constructor or method than the data type that is defined for the parameter itself. Widening typically allows this, as long as the passed data type is structurally capable of handling the data that you are passing through the parameter to the data type of the destination. ABL supports widening for passing parameters to ABL class-based constructors and methods. For more information, see OpenEdge Development: Object-oriented Programming.
ABL also supports a form of widening for passing parameters to .NET constructors and methods. In this case, there are more .NET data types that can be involved in passing data to a widened data type than ABL data types in an ABL user-defined constructor or method. Thus, ABL provides special support for data type widening when passing .NET parameters involving ABL primitive and .NET mapped data types.
Note: ABL does not support widening when passing parameters between ABL primitive array types and .NET arrays of mapped types. For ABL and .NET array mappings, the element types of the source and target arrays must match exactly. For more information, see Accessing and using .NET arrays.
The following table lists .NET data types with default ABL data type mappings that support other ABL widening data types for passing primitive data to a .NET INPUT parameter. In general, for each ABL data type passed as an INPUT parameter, if another ABL data type exists that can hold a smaller value acceptable to the corresponding .NET data type, you can use that other ABL data type to pass the value. For example, where the default ABL data type mapping is DECIMAL, the INTEGER and INT64 data types can also hold values that the .NET data type can accept for INPUT. For all other implicit data type mappings (see Table 10), you can use only the specified ABL data type to pass a .NET parameter for INPUT.
.NET parameter object type
C# parameter primitive type
ABL implicit mapping data type
ABL INPUT widening data type
System.DateTime
DATETIME
DATE
System.Decimal
decimal
DECIMAL
INTEGER, INT64
System.UInt32
uint
INT64
INTEGER1
System.Int64
long
INT64
INTEGER
System.UInt64
ulong
DECIMAL
INTEGER2, INT64 3
System.Double
double
DECIMAL
INTEGER, INT64
System.Single
float
DECIMAL
INTEGER4, INT645

1 If you pass a negative ABL data type to an unsigned data type, the AVM raises a run-time error.

2 If you pass a negative ABL data type to an unsigned data type, the AVM raises a run-time error.

3 If you pass a negative ABL data type to an unsigned data type, the AVM raises a run-time error.

4 You can lose precision if you pass an ABL INTEGER or INT64 to a System.Single parameter.

5 You can lose precision if you pass an ABL INTEGER or INT64 to a System.Single parameter.

The following table lists .NET data types with default ABL data type mappings that support other ABL widening data types for passing primitive data to a .NET OUTPUT parameter. In general, for each ABL data type passed as an OUTPUT parameter, if another ABL data type exists that can accept a larger value that is passed from the corresponding .NET data type, you can use that other ABL data type to accept the value. For example, where the default ABL data type mapping is INTEGER, the INT64 and DECIMAL data types can also accept values passed from the .NET data type for OUTPUT. For all other implicit data type mappings (see Table 10), you can use only the specified ABL data type to pass a .NET parameter for OUTPUT.
.NET parameter object type
C# parameter primitive type
ABL implicit mapping data type
ABL OUTPUT widening data type
System.Byte
byte
INTEGER
INT64, DECIMAL
System.SByte
sbyte
INTEGER
INT64, DECIMAL
System.Char
char
CHARACTER
LONGCHAR
System.DateTime
DATETIME
DATETIME-TZ
System.Int16
short
INTEGER
INT64, DECIMAL
System.UInt16
ushort
INTEGER
INT64, DECIMAL
System.Int32
int
INTEGER
INT64, DECIMAL
System.UInt32
uint
INT64
DECIMAL
System.Int64
long
INT64
DECIMAL
Note that similar to passing ABL parameters to ABL class-based methods, data widening is not supported for passing INPUT-OUTPUT parameters to .NET methods. Because the data is moving in both directions, no single widening choice can work for both directions. Thus, for INPUT-OUTPUT parameters that you pass to a .NET method, you must use the appropriate ABL implicit mapping data type.