I have a file to convert that has cobol COMP-6 fields.
These fields store 2 decimal digits per character (Byte) e.g. a 2 char comp-6 field storing the value 123 is stored as two chars with the hex values of 01 23.
How can I extract each single value from each character so that I end up with 3 chars 123.
T.I.A.
Barry
OCONV should do the trick:
charvar = hexvar 'HEX'
I cannot remember if or where comp-6 carries the sign nibble - but it will (if present) be the first or last character in 'charvar'.
numeric.string=input.recordoffset, bytesize 'HEX'
I cannot recall comp-6. It may be specific to a particular compler. Are you sure that it is unsigned. If it is signed, the relevant nibble will be expanded into the either the first or last charcter of numeric.string. You'll have to work out the appropriate values for + and -.
Chris.
Thanks heaps, that did the trick - from the manual I did not interpret that that is how it would convert.
BTW. Just in case, Do you know how to do COMP-1, COMP-2
Thanks again
Barry
If COMP-1 and COMP-2 are BINARY data types, then something like the following should do it.
(by the way - what Cobol compiler do you use - is it perchance an NCR implementation).
…
numval=binval(inputrecoffset, bytesize)
…
FUNCTION BINVAL(INPUT)
OUTPUT=0REPS=LEN(INPUT)FACTOR=1FOR REP=REPS TO 1 STEP -1OUTPUT += SEQ(INPUTREP, 1) * FACTORFACTOR=FACTOR * 256NEXT REPRETURN OUTPUT
This example assumes unsigned binary with both bitwise and bytewise ascendency from right to left.
eg.
hex(010203) would be evaluated as
(3 * 1) + (2 * 256) + (1 * 65536)=65051
hex(aabbcc) would be evaluated as
(204 * 1) + (187 * 256) + (170 * 65536)=11189196
ry with both bitwise and bytewise ascendency from right to left.
eg
hex(010203) would be evaluated as
(3 * 1) + (2 * 256) + (1 * 65536)=65051
hex(aabbcc) would be evaluated as
(204 * 1) + (187 * 256) + (170 * 65536)= 11189196