home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
cobol
/
library
/
comp
/
comp.doc
next >
Wrap
Text File
|
1990-07-24
|
8KB
|
163 lines
******************************************************************************
* *
* COMPS.LIB - Copyright 1990 Michael P. Deignan. All Rights Reserved. *
* *
* This product may be freely distributed as long as all copyright notices *
* appear intact. Source code is available to qualified users. Contact the *
* author, with either bug reports, or for source information, at: *
* *
* Internet: mpd@anomaly.sbs.com *
* UUCP: ...!uunet!anomaly.sbs.com!mpd *
* 'Anomaly': +1 401 455 0347 Telebit Trailblazer Plus *
* *
******************************************************************************
* *
* COMPS.LIB contains a series of routines which allow the user to store *
* data in the same format as IBM mainframe equipment does, as created by *
* IBM's COBOL compiler (thus, are generally compatible with just about any *
* language on an IBM mainframe, unless you do odd things in assembler with *
* these variable types. The routines allow you, the user, to retrieve and *
* store information as COMP1, COMP2, COMP3, COMP. Using these utilities, you *
* can download data from the mainframe, manipulate it on the PC, and then *
* transfer manipulated data back to the mainframe. *
* *
* The user merely passes a character string (compressed binary number) or *
* a numeral value to these routines. The routines then determine whether *
* the conversion has to be "from" compressed-binary to numeric, or from *
* numeric to a compressed-binary string. *
* *
* Those unfamiliar with the internal storage representation of these formats *
* should review their appropiate IBM documention, in conjunction with the *
* source code for these functions, and the technical description of how each *
* function operates, in COMPTECH.DOC (available to registered users only.) *
* *
* There are two additional functions in this library, which exist for as *
* support functions to the four main functions. These functions are COMP4() *
* which is the same as COMP() except uses all 64 bits for positive values, *
* instead of using the hi-order bit for a sign bit. The second function is *
* TWOS_COMPLIMENT(), which will calculate the two's compliment of a value *
* passed to it. IBM stored negative numbers in two's compliment form. *
* *
******************************************************************************
Function: Usage Description:
--------- ----------------------------------------------------
COMP(<expN>) Convert a display numeric value to binary. Result
returned will be either a fullword (4 bytes) or a
doubleword (8 bytes) binary value in a character
string. Numeric Limitation: +/- 2^32
COMP(<expC>) Convert a binary value to display numeric. Result
returned will be a positive or negative numeric value.
COMP1(<expN>) Convert display numeric to Internal Floating Point,
Short Precision. Returns a character string of 4 bytes
(one fullword).
COMP1(<expC>) Convert Internal Floating Point 4-character Short
Precision string to display numeric. Returns a numeric
value of variable length with decimal precision, if
appropiate (depending on input.)
COMP2(<expN>) Convert display numeric to Internal Floating Point,
Long Precision. Returns a character string of 8 bytes
(two fullwords).
COMP2(<expC>) Convert Internal Floating Point 4-character Long
Precision string to display numeric. Returns a numeric
value of variable length with decimal precision, if
appropiate (depending on input.)
COMP3(<expN>) Convert a display numeric value to packed decimal,
signed. This routine returns a character string of
variable length (depending on input) with appropiate
sign bits in the LSB.
COMP3(<expC>) Convert a packed decimal character string to display
numeric. The returned result is a numeric value,
signed negative if necessary.
COMP4(<expN>) Convert a display numeric value to binary. Result
returned will be either a fullword (4 bytes) or a
doubleword (8 bytes) binary value in a character
string. Numeric Limitation: +2^64. Signs are ignored
by this routine.
COMP4(<expC>) Convert a binary value to display numeric. Result
returned will always be a positive numeric value.
TWOS_COMPL(<expC>) Calculate the twos compliment of a character string's
binary value. Returns a character string of equal
length to the caller.
BINARY_ERR(<expC>) Display An Error Message On Line 0. Forces termination
of the program. This is a rudimentary routine, which
should be rewritten by the user to provide error
handling on an application-by-application basis. This
function does not return to the caller.
******************************************************************************
* *
* C A V E A T S *
* *
******************************************************************************
Function: COMP
This routine can only handle values up to 2^32 power. It uses the high-order
bit as a sign bit, thus will return a positive or negative value. It will
return a string (for numeric->binary conversion) which is either a fullword
(4 bytes) or two full-words (8 bytes). A high-bit set indicates a negative
value.
-=-
Function: COMP1
As this is a short-precision routine, it will always return 4 bytes when
converting to COMP1 from numeric display, and expects 4 bytes if converting
back to numeric display. Providing less than 4 bytes of short-precision data
may yield odd results.
-=-
Function: COMP2
As this is a long-precision routine, it will always return 8 bytes when
converting to COMP2 from numeric display, and expects 8 bytes if converting
back to numeric display. Providing less than 8 bytes of long-precision data
may yield odd results.
-=-
Function: COMP3
This routine is slightly different than IBM's COMP-3 data type, however, is
backwards compatible with it. The primary difference is that packed decimal
values created by this routine will have the number of decimals stored in the
sign half-byte, which will be re-used to properly place the decimal point upon
uncompression.
Should a character field be passed to this routine which contains a non-
packed-decimal value, then the routine will return '0' for the decimal
number.
When handling decimals, a maximum of seven decimals places are accounted
for. Any data beyond the seventh decimal is trucated by the function.
Since mainframes use logical decimal-point placement (via a PIC ...v...
clause) data from a mainframe will be treated as whole numbers.
-=-
Function: COMP4
This routine handles values up to 2^64 power. It is not "compatible" with
IBM's COMP4 function, as COMP4 is generally as a "COMP" on most mainframes
anyway. This routine will return a double-word (8 bytes) to the caller.
******************************************************************************
* End Of Text *
******************************************************************************