Data Structure in Mainframe

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 10

Data Structure in Mainframe

- Rajesh K Gupta
Bits and Bytes explained

 The computer memory consists of a series of switches known as "Bits" in either the
ON or the OFF position. A combination of eight switches is called a "Byte", and one
byte is used for each character on your keyboard.
 Data on IBM midrange (AS/400 and iSeries) and IBM compatible mainframe systems
is transmitted using 8-bit Extended Binary Coded Decimal Interchange Code
(EBCDIC). In contrast, UNIX and PC operating systems transmit data using 7-bit
American Standard Code for Information Interchange (ASCII). Because of this,
alphanumeric and special characters on IBM AS/400 and mainframe systems have
different binary representations to those on UNIX and PC systems.
 The letter A, for instance, is stored in AS/400 and IBM compatible mainframe
computer memory as 1100 0001, and in UNIX and PC computer memory as 0100
0001 (where 1 represents an 'on' bit, and 0 represents an 'off' bit).
 It is useful to be able to refer to a byte of data, and know its bit configuration. But
using a string of 1's and 0's is laborious and leads to errors. For this purpose we use
Hexadecimal Representation.
Binary Explained
 The following table shows the structure of a three digit numeric field using the
Binary format that is used on an IBM Mainframe System (i.e. the COBOL syntax
would be USAGE IS COMP). The field contains a value of one-hundred-twenty-
three (or 123). Since the binary format stores the number as an actual binary value
the field will only be two (2) bytes in length.

 A binary field that is defined as "Unsigned" (i.e. PIC 999) is an implied positive value. A two (2)
byte unsigned, binary field may contain a range of implied positive values from 0 to 65,535.
 A binary field that is defined as "Signed" (i.e. PIC S999) will use the high-order, leftmost bit as the
sign. A zero (0) is a positive sign and a one (1) is a negative sign. A two (2) byte signed, binary
field may contain a range of implied positive values from -32,767 to +32,767.
Hexadecimal explained
 The first four bits of any byte are, broadly speaking, coded to distinguish
between numbers, letters and special characters. It is therefore convenient
to split the byte into two groups of four bits.

 The highest possible value of a four digit binary number is 1111 which is
equivalent to 15 in base 10. This means, that to represent this number as
a single digit, we have to work in base 16.

Base 16 (Hex) Binary Base 16 (Hex) Binary


0 0 8 1000
1 1 9 1001
2 10 A 1010
3 11 B 1011
4 100 C 1100
5 101 D 1101
6 110 E 1110
7 111 F 1111
Hexadecimal explained

 If we refer to each group of four digits as a single hexadecimal (base


sixteen) digit, we can then represent an eight digit number (one byte) with
two hexadecimal digits.
 As we have already seen, the EBCDIC letter A is stored in AS/400 and IBM
mainframe computer memory as 1100 0001. This can be represented in hex
as X'C1', which tells us that the first two and the last bits are on, and all the
rest are off. Similarly, the ASCII letter A, stored in UNIX and PC computer
memory as 0100 0001, can be represented in hex as X'41', which tells us
that the second and the last bits are on, and all the rest are off. We
distinguish hex numbers from other data by enclosing them in quotes and
preceding them with an X.
 It is important to realise that hex and character format are for our benefit
only. The computer does everything at the bit level.
Packed Decimal explained

 Packed decimal is, in fact, the default numeric field type used by
many programs (e.g. SELCOPY) arithmetic functions.

 A single digit number is stored in the memory of the computer as an


eight bit binary field. The first four bits are coded to signify a numeric
value, i.e. binary 1111 (X'F') for AS/400 and mainframe, binary 0011
(X'3') for UNIX and PC. However, if we already know that we are
dealing with a number, the code becomes unnecessary, and the first
four bits are only wasting valuable storage space.

 To save this storage space we "pack" the data - that is we leave out
the coded bits - thus reducing the storage space needed by half.

 Consider the numeric string '987': Normally it would be stored as


X'F9F8F7' for AS/400 and mainframe, and X'393837' for UNIX and
PC, but if we pack the data it becomes X'987C', and we have saved
one byte of storage.
Packed Decimal explained

 The X'C' (or 1100 in binary) denotes a Positive value, while a


Negative value is normally represented by X'D'.
The hex values X'A', X'C', X'E' and X'F' are all valid Positive codes.
The hex values X'B' and X'D' are both valid Negative codes.
 The representation X'2C' to us means the same thing, because we
recognise it as Packed Decimal data holding the number 2. But to
the computer it is totally different. It is a combination of eight
switches set as 00101100.
 Packed decimal data is unprintable and must therefore be converted
(unpacked) into a character representation, called Zoned Decimal,
before it can be printed.
Zoned Decimal explained

 Zoned Decimal representation uses a full byte for each numeric digit, but the
junior (right-most) byte is zoned according to the sign of the complete numeric
string, thus differentiating between positive and negative values.
 As we saw above, the first four bits (left-most) of a byte are coded to signify a
numeric value by having all four bits either set to binary 1111 (X'F') for AS/400
and mainframe, or binary 0011 (X'3') for UNIX and PC.
These "first four bits" are known as the Zone portion of a byte, while the last 4
bits (right-most) are known as the Numeric portion of a byte.
 Only the junior (right-most) byte of a zoned decimal string may be zoned to
indicate the sign, or to be more precise, it is only the junior byte which is used
for defining the sign. All other zones on other bytes in the string are ignored for
arithmetic purposes.
Zoned Decimal explained

 Conveniently, the sign representations for zones are identical to


those used for Packed Decimal data:
The hex values X'A', X'C', X'E' and X'F' are all valid Positive codes.
The hex values X'B' and X'D' are both valid Negative codes.
 The positive numbers like +1 +2 through to +0 in the junior byte will
print as 1 2 3 4 5 6 7 8 9 0.
 X'D' is used for negative because this is traditionally the standard.
Thus -1 -2 through to -9 in the junior byte will print as J K L M N O P
Q R, and the byte containing -0 (X'D0') will print as a "brace" (right-
hand curly bracket) on some printers, but on others it will be
unprintable.
THAT’S ALL!!!

You might also like