Previous Topic Next topic Print topic


Data Types - in COBOL and

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  condition-value       value true.
declare hex     binary-char unsigned  value h"2a".  *> Hex
declare octal   binary-char unsigned  value o"52".  *> Octal
declare person  object                value null.
declare aName   string                value "Dwight".
declare grade   character             value "B".
declare today   type DateTime         value 
                    type DateTime::Parse("12/3/2007 12:15:00)
declare amount  decimal               value 35.99.
declare gpa     float-short           value 2.9.
declare pi      float-long            value 3.14159265.
declare lTotal  binary-double         value 123456.
declare sTotal  binary-short          value 123.
declare usTotal binary-short unsigned value 123.
declare uiTotal binary-long           value 123.
declare ulTotal binary-long unsigned  value 123.
*> Type information
01 x binary-long.
display x::GetType            *> Prints System.Int32
display type of binary-long   *> Prints System.Int32
display x::GetType::Name      *> Prints Int32
*> 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.
Previous Topic Next topic Print topic