Data Types in Managed COBOL
*> Value types
condition-value
binary-char (unsigned)
character
binary-short (unsigned)
binary-long (unsigned)
binary-double (unsigned)
float-short
float-long
decimal
DateTime (not a built-in COBOL type)
*> Reference types
object
string
*> Initializing. Two methods shown.
*> Method 1, in working storage
01 isTrue condition-value value true.
01 hex binary-char unsigned value h"2a". *> Hex
01 octal binary-char unsigned value o"52". *> Octal
01 person object value null.
01 aName string value "Dwight".
01 grade character value "B".
01 today type DateTime value
type DateTime::Parse("12/3/2007 12:15:00")
01 amount decimal value 35.99.
01 gpa float-short value 2.9.
01 pi float-long value 3.14159265.
01 lTotal binary-double value 123456.
01 sTotal binary-short value 123.
01 usTotal binary-short unsigned value 123.
01 uiTotal binary-long value 123.
01 ulTotal binary-long unsigned value 123.
*> Method 2, local declaration
declare isTrue as condition-value = true.
declare hex as binary-char unsigned = h"2a". *> Hex
declare octal as binary-char unsigned = o"52". *> Octal
declare person as object = null.
declare aName as string = "Dwight".
declare grade as character = "B".
declare today as type DateTime =
type DateTime::Parse("12/3/2007 12:15:00")
declare amount as decimal = 35.99.
declare gpa as float-short = 2.9.
declare pi as float-long = 3.14159265.
declare lTotal as binary-double = 123456.
declare sTotal as binary-short = 123.
declare usTotal as binary-short unsigned = 123.
declare uiTotal as binary-long = 123.
declare ulTotal as binary-long unsigned = 123.
*> Type information
01 x string value "Hello".
display x::GetType *> Prints System.String
display type of string *> Prints System.String
display type of list[ANY] *> Prints System.Collections.Generic.IList'1[T]
display type of list[string] *> Prints System.Collections.Generic.IList'1[System.String]
display x::GetType::Name *> Prints String
*> Type conversion
01 d float-short value 3.5. *> automatic conversion
set i to d as binary-long *> set to 3 (truncates decimal)
*> COBOL types not supported in C# or Java
*> Only a few examples here
01 displayNumber pic 9(9).99.
01 computeNumber pic 9(9)V99.
01 alphaNumberic pic a(23).
01 binaryStorage pic x(12).
*> Also groups and redefines - a few examples
01 arecord.
03 aSubRecord pic x(10).
03 aUnion pic 9(10) redefines aSubrecord.
Data Types in C#
// Value Types
bool
byte, sbyte
char
short, ushort
int, uint
long, ulong
float, double
decimal
DateTime // (not a built-in C# type)
// Reference Types
object
string
// Initializing
bool isTrue = true;
byte hex = 0x2A; // hex
object person = null;
string aName = "Dwight";
char grade = 'B';
DateTime today = DateTime.Parse("12/31/2007 12:15:00");
decimal amount = 35.99m;
float gpa = 2.9f;
double pi = 3.14159265;
long lTotal = 123456L;
short sTotal = 123;
ushort usTotal = 123;
uint uiTotal = 123;
ulong ulTotal = 123;
// Type Information
int x;
Console.WriteLine(x.GetType()); // Prints System.Int32
Console.WriteLine(typeof(int)); // Prints System.Int32
Console.WriteLine(x.GetType().Name); // prints Int32
// Type Conversion
float d = 3.5f;
int i = (int)d; // set to 3 (truncates decimal)