Previous Topic Next topic Print topic


Data Types - in COBOL and Java

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 Java

// Value Types
boolean
byte
char
short
int
long
float, double

Date   // (not a built-in Java type)

// Reference Types
java.lang.Object
java.lang.String	
	
Initializing
boolean correct = true;
byte    b       = 0x2A;   // hex

Object  person  = null;
String  name    = "Dwight";
char    grade   = 'B';
Date    today   = Date.parse("12/31/2007 12:15:00");


float   gpa     = 2.9f;
double  pi      = 3.14159265;
long    lTotal  = 123456L;
short   sTotal  = 123;
int     iTotal  = 123;
 


// Type Information
Use reflection



 
// Type Conversion
float d = 3.5f;
int i = (int)d;   // set to 3  (truncates decimal)

Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.

Previous Topic Next topic Print topic