Saturday, January 4, 2014

Data types

RPG and Java have differences in Data types. This too requires an adjustment in perspective.  iSeries is primarily a EBCDIC based platform, where as JAVA is an UNICODE based platform.  And such a difference affects issues such as space requirements and collating sequence.  Unicode is ASCII based so therefore the numbers 0-9 are a lower binary value than the alphabet, whereas in EBCDIC the numbers are a higher binary value.. So if your RPG program tests for a value being LESS than '0' to determine if it's numeric or alpha the opposite logic would apply in Java.

Furthermore, UNICODE is a double byte character system.  This means each alpha character in Java actually takes two bytes instead of one.   This generally only presents itself as a problem when dealing with data structures, which I'll address in another post.

For now the basic RPG-Java data x-reference is as follows.



Character

In RPG a Character field is generally one of fixed length.  There are variable length fields in RPG, but this is a rather new introduction.    Java Strings are much like RPG variable length fields.  Keep in mind that these Strings are storing characters in UNICODE.   

Sometimes we have a situation where we only need the value of a SINGLE Character.. Java does have a primitive data type called 'char'.   This is a single UNICODE Character. Java treats primitives such as char, int, byte differently than it does complex classes like String.   A review of the String class can be valuable.


Graphic

In RPG Graphic fields represent a string of binary information.   Java can accommodate this same concept in a Stirng class or use of a byte array.   Byte arrays are arrays of binary bytes (rather than Unicode) and thus can preserve the actual binary value of the data.

UNICODE

In RPG there has been provided a Unicode data type, which is much like a Double Byte Character field.   This is obviously handled by the String class, which stores it's characters in Unicode.

Binary, Integer, Unsigned Integer

RPG Binary data types come in sizes of 1, 2, 4 and 8 byte lengths.  These are represented in Java in either byte (1 byte, 8 bits) ,  short (2 bytes, 16 bits), int (4 bytes, 32 bits) or long (8 bytes, 64 bits) .

Date, Time, Timestamp

RPG provides for storing data in a Date or Timestamp format.   Java has an equivalent but it's not persisted in memory the same way.  Java employs a Date class or a Calendar class that has various methods for storing and modifying date / time stamp values.  See the post on working with dates in Java.

Packed Decimal, Zoned Decimal

In the business world it often very important to manage pennies precisely.  In the world from which Java comes from there is no exact replication of Packed or Zoned Decimal and that such numeric precision is managed with the BigDecimal and BigInteger classes.   These classes store the number in a byte array and then have methods to work with the data.   It's important to note that BigDecimal and BigInteger like Strings are not simple primitive data types , but instead a complex class.  And there is no distinguished difference between Packed and Zoned.

Indicator   

RPG indicators fields are equivalent to Java Boolean primitive data types.


Float

RPG has two float lengths 4 bytes, and 8 bytes.  These are represented in Java by the float and double data types.


Pointers

By design Java has NO pointers.  This is kind of a misnomer, as all Java properties are pointers, but the pointers value can not be altered, so in essence there is no pointer data types.

No comments:

Post a Comment