[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [GNU-COBOL] New to list



Davyd Ondrejko wrote:

> > COBOL doesn't have that many native data types, does it?
>
> Well, no, not really.  You can have PIC 9() which is numeric or PIC X()
> which is alphanumeric.  There are also 88-level variables, which are
> essentially Booleans whose content is determined automatically by the
> contents of its parent field.
>
> The internal storage of PIC 9() fields is weird, as well.  Normally, a
> PIC 9()) is stored in the same way as a PIC X(); that is, one byte per
> digit.  You can attach qualifiers to numerics, though; COMP stores it in
> native binary format and COMP-3 stores it in what's known as packed
> decimal format.  (I'll explain that if you really want me to.)  Also,
> with COMP storage, you can (and in most cases should) specify the SYNC
> qualifier as well, which causes the storage to be optimized along word
> boundaries.
>
> You need to take into consideration such techniques as REDEFINES clauses
> (and the related though seldom-used RENAMES clauses), which use a
> different mapping to access the same region of storage, and OCCURS,
> which is the COBOL version of an array.  (There's also the OCCURS
> DEPENDING ON, where the length of the array is not determined until
> runtime, and the related topic of variable-length records.)  In COBOL
> '85, of course, you get into other data possibilities such as pointers,
> which introduces the possibility of linked lists and similar things.
>
> Numeric-edited fields and alphanumeric-edited fields would be
> particularly enjoyable.  Floating or fixed insertion symbols (+, - or
> $), zero suppression with blank or asterisk replacement, CR and/or DB
> symbols, BLANK WHEN ZERO, and so forth.
>
> This is, of course, only for straight COBOL.  Adding such packages as
> CICS and/or DB2 -- to mention the two most commonly used extensions --
> could introduce other factors.

Some comments are permitted, I hope.

Alphabetic fields : PIC string contains B and A characters, where B is a
placeholder for a space and A for an alphabetic character. B's are in general
only used in PIC strings for output formatting.

Alphanumeric fields : PIC strings contains A, X and 9 characters !

Numeric fields are possible in some formats :

Fixed point with sign :
PIC  strings with S as sign indicator, 9 as placeholder for the numeric digits,
V for the place of the assumed decimal point and P for scaling.
If the field is in USAGE IS DISPLAY mode the sign is indicated by the characters
used in the byte at the right-hand end-address : in EBCDIC hex code C0-C9 and
F0-F9 are positive, negative numbers are represented by B0-B9, D0-D9 and E0-E9
.  I never saw A0-A9 :-). Do you want to know how this translates to ASCII ?
That's difficult as I've never seen an official translation tabel for the whole
EBCDIC set. I did make one 10 years ago but it's just my own.
If the field is in USAGE IS COMP format the field is a binary numeric field
signed as usual on the target system.
If the field is in USAGE IS COMP-3 format (the well-known packed decimal format)
each byte holds two digits except the right-hand end-address, where the right
digit represents the sign : in hex code F and C represents a positive value and
B, D ans E represents a negative value.

Fixed point without sign :
PIC  strings with 9 as placeholder for the numeric digits, V for the place of
the assumed decimal point and P for scaling.
If the field is in USAGE IS DISPLAY mode all cyphers are represented by 0-9 and
the value is assumed to be positive.
The usage of the USAGE IS COMP format is impossible as it always assumes a sign.

If the field is in USAGE IS COMP-3 format (the well-known BCD code format) each
byte holds two digits.

The effect of SYNC in combination with USAGE IS COMP depends upon the length of
the field : alignment is done at the length of the field. If the field is 2
bytes in length the alignment is done at a 16-bit boundary, otherwise it's done
at a 32-bit boundary. Note that (as far as I know) Cobol support numeric
variables at a maximum length of 18 cyphers.

Do you want to know how Cobol works with floating-point variables ? Just tell
me, but I have to investigate it as I've never used it before in Cobol :-).

Regards,

Fred Mobach



--
This message was sent through the gnu-cobol mailing list.  To remove yourself
from this mailing list, send a message to majordomo@lusars.net with the
words "unsubscribe gnu-cobol" in the message body.  For more information on
the GNU COBOL project, send mail to gnu-cobol-owner@lusars.net.