FieldType class | QSYS API Reference Guide
Estimated reading time: 12 minutes
Represents the type of a field in a data structure.
Namespace: ASNA.DataGate.Common
Assembly: ASNA.QSys.DataGate.Client.dll
Inheritance: Object
Thread Safety
Any public static (Shared) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
The FieldType class provides a way to define the type of a field in a data structure,
including its data type, length, precision, scale, and format for date/time and DBCS fields.
It also provides methods to create new instances of FieldType for specific data types.
Properties
Type |
Name |
Description |
Int32 |
ByteLength |
Gets the byte length of the field. |
DataTypes |
DataType |
Gets the data type of the field. |
DateTimeFormat |
DateTime |
Gets the date/time format of the field. This is used for date and time types. |
DbcsFormat |
Dbcs |
Gets the DBCS format of the field. This is used for DBCS types. |
PropertyCollection |
ExtendedProperties |
Gets the collection of extended properties for the field. |
Int32 |
Precision |
Gets the precision of the field. This is used for decimal types. |
Int32 |
Scale |
Gets the scale of the field. This is used for decimal types. |
Methods
Signature |
Description |
GetSystemTypeOfType(DataTypes, Int32) |
Gets the corresponding .NET type for a given DataTypes value and byte length. |
NewBinary(Int32, Int32) |
Creates a new FieldType instance representing a binary field. |
NewByte() |
Creates a new FieldType instance representing a byte field. |
NewChar(Int32) |
Creates a new FieldType instance representing a character field. |
NewDate(DateTimeFormat) |
Creates a new FieldType instance representing a date field. |
NewDBCS(Int32, DbcsFormat) |
Creates a new FieldType instance representing a DBCS field. |
NewDontCare(Int32) |
Creates a new FieldType instance representing a DontCare field. |
NewFloat(Int32) |
Creates a new FieldType instance representing a floating point field. |
NewHex(Int32) |
Creates a new FieldType instance representing a hexadecimal field. |
NewInteger(Int32) |
Creates a new FieldType instance representing an integer field. |
NewPacked(Int32, Int32) |
Creates a new FieldType instance representing a packed decimal field. |
NewTime(DateTimeFormat) |
Creates a new FieldType instance representing a time field. |
NewTimestamp() |
Creates a new FieldType instance representing a timestamp field. |
NewUnicode(Int32) |
Creates a new FieldType instance representing a Unicode field. |
NewZoned(Int32, Int32) |
Creates a new FieldType instance representing a zoned decimal field. |
Gets the corresponding .NET type for a given DataTypes value and byte length.
Type GetSystemTypeOfType(DataTypes dt, int byteLength)
Parameters
Type |
Parameter name |
Description |
DataTypes |
dt |
The DataTypes value to get the .NET type for. |
Int32 |
byteLength |
The byte length of the data type. |
Returns
Type |
Description |
Type |
The corresponding .NET type, or null if no match is found. |
Creates a new FieldType instance representing a binary field.
FieldType NewBinary(int prec, int scale)
Parameters
Type |
Parameter name |
Description |
Int32 |
prec |
The total number of digits in the binary field. |
Int32 |
scale |
The number of digits to the right of the decimal point in the binary field. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
FieldType NewByte()
Creates a new FieldType instance representing a byte field.
Creates a new FieldType instance representing a character field.
FieldType NewChar(int length)
Parameters
Type |
Parameter name |
Description |
Int32 |
length |
The length of the character field. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
Creates a new FieldType instance representing a date field.
FieldType NewDate(DateTimeFormat fmt)
Parameters
Type |
Parameter name |
Description |
DateTimeFormat |
fmt |
The format of the date field. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
Creates a new FieldType instance representing a DBCS field.
FieldType NewDBCS(int length, DbcsFormat fmt)
Parameters
Type |
Parameter name |
Description |
Int32 |
length |
The length of the DBCS field. |
DbcsFormat |
fmt |
The format of the DBCS field. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
FieldType NewDontCare(int length)
Creates a new FieldType instance representing a DontCare field.
FieldType NewDontCare(int length)
Parameters
Type |
Parameter name |
Description |
Int32 |
length |
The length of the DontCare field. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
Creates a new FieldType instance representing a floating point field.
FieldType NewFloat(int length)
Parameters
Type |
Parameter name |
Description |
Int32 |
length |
The length of the floating point field. It should be either 4 or 8. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
Creates a new FieldType instance representing a hexadecimal field.
FieldType NewHex(int length)
Parameters
Type |
Parameter name |
Description |
Int32 |
length |
The length of the hexadecimal field. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
FieldType NewInteger(int length)
Creates a new FieldType instance representing an integer field.
FieldType NewInteger(int length)
Parameters
Type |
Parameter name |
Description |
Int32 |
length |
The length of the integer field. It should be either 2, 4, or 8. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
Creates a new FieldType instance representing a packed decimal field.
FieldType NewPacked(int prec, int scale)
Parameters
Type |
Parameter name |
Description |
Int32 |
prec |
The total number of digits in the packed decimal field. |
Int32 |
scale |
The number of digits to the right of the decimal point in the packed decimal field. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
Creates a new FieldType instance representing a time field.
FieldType NewTime(DateTimeFormat fmt)
Parameters
Type |
Parameter name |
Description |
DateTimeFormat |
fmt |
The format of the time field. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
FieldType NewTimestamp()
Creates a new FieldType instance representing a timestamp field.
FieldType NewUnicode(int length)
Creates a new FieldType instance representing a Unicode field.
FieldType NewUnicode(int length)
Parameters
Type |
Parameter name |
Description |
Int32 |
length |
The length of the Unicode field. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
Creates a new FieldType instance representing a zoned decimal field.
FieldType NewZoned(int prec, int scale)
Parameters
Type |
Parameter name |
Description |
Int32 |
prec |
The total number of digits in the zoned decimal field. |
Int32 |
scale |
The number of digits to the right of the decimal point in the zoned decimal field. |
Returns
Type |
Description |
FieldType |
A new FieldType instance. |
Example 1. Use of NewTimestamp method example.
/* Use the already initialized As400OProgram "timeProg" to set the
* value of a DateTime variable. This program accepts a timestamp data type
* whose time format is ISO as its sole parameter, which it does not
* read but uses to return data. */
ProgParmType as400Time = new ProgParmType("TimeISO", 0, FieldType.NewTimestamp());
ProgParm timeParm = new ProgParm(as400Time, DataDirection.Output);
timeProg.AppendParm(timeParm);
timeProg.Execute();
DateTime currentTime;
currentTime = Convert.ToDateTime(timeProg.ParmToObject(timeParm, Type.GetType("System.DateTime"), 0));
/* Unlike the IBM i FieldType NewTime or NewDate, NewTimeStamp contains both date and time
* values. */
Example 2. Use of NewDate method example.
/* Create a parms list to pass to a pre-initialized As400Program object.
* We want to pass one date with time format *USA and another with time
* format *ISO. Other time formats are available in the DateTimeFormat
* enumeration as well. */
DateTime DateUSA = System.DateTime.Now;
DateTime DateISO = System.DateTime.Now;
ProgParmType type1 = new ProgParmType("DateUSA", 0, FieldType.NewDate(DateTimeFormat.USA));
ProgParmType type2 = new ProgParmType("DateISO", 0, FieldType.NewDate(DateTimeFormat.ISO));
ProgParm parm1 = new ProgParm(type1, DataDirection.InputOutput);
ProgParm parm2 = new ProgParm(type2, DataDirection.InputOutput);
prog.AppendParm(parm1);
prog.AppendParm(parm2);
/* In the lines below, we assign the IBM i program parameters
* values from our .NET variables. */
prog.ObjectToParm(parm1, DateUSA, 0);
prog.ObjectToParm(parm1, DateISO, 0);
/* Call the program. */
prog.Execute();
/* The parameters can be bidirectional and thus return data as well.
* To use that data, we assign the values of the parameters back to our
* .NET variables. */
DateUSA = Convert.ToDateTime(prog.ParmToObject(parm1, DateUSA.GetType(), 0));
DateISO = Convert.ToDateTime(prog.ParmToObject(parm2, DateUSA.GetType(), 0));
/* IMPORTANT NOTE: The time and date data types do not return all the information
* which a .NET DateTime can contain. Specifically, if you specify a parm as a NewTime,
* the data portion of the returned DateTime will be set to MinValue. The same will
* happen to the time portion of a variable if its IBM i parm was set to be a NewDate. */