Re: convert packed CHAR to unpacked DIGIT



In article <1113616966.172135.175650@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"ssb" <mail_ssb@xxxxxxxxx> wrote:

> Hi,
>
> Input record has a field of size 5 bytes containing packed numbers. But
> this field is defined as CHARACTER.
>
> E.g. WS-A PIC X(5) '1212343455'
>
> My task is to display '1212343455' on a report. Obviously, it requires
> converting packed to unpacked numbers.
>
> I tried doing something like this:
>
> MOVE X(5) TO 9(9) COMP-3.
> REDEFINE 9(9) COMP-3 AS 9(10)
>
> Any suggestions/help..? Thanks.

77 I Pic S9(8) comp.
77 X Pic S9(4) comp.
77 Y Pic S9(4) comp.
77 Z Pic S9(4) comp.
77 HEX Pic X(16) value '0123456789abcdef'.
77 WS-A-OUT Pic X(10).

Perform varying I from 1 by 1
until I > length of WS-A

Move 0 to X Y Z
Move WS-A (I:1) to X (2:1)
Divide X by 16 giving Y remainder Z
Move HEX (Y:1) to WS-A-OUT (I*2:1)
Move HEX (Z:1) to WS-A-OUT (I*2+1:1)

End-Perform

Happy hacking --- btw, there is one small gotcha left as an exercise for
the reader...
.



Relevant Pages

  • Re: convert packed CHAR to unpacked DIGIT
    ... ssb wrote: ... Input record has a field of size 5 bytes containing packed numbers. ... My task is to display '1212343455' on a report. ... you could try stepping through the input field one character at a time, using ORD to find its binary value, dividing that value by 16, and using the dividend and remainder respectively to index into a table of hexadecimal characters, and moving the results into the output record. ...
    (comp.lang.cobol)
  • convert packed CHAR to unpacked DIGIT
    ... Input record has a field of size 5 bytes containing packed numbers. ... this field is defined as CHARACTER. ... Any suggestions/help..? ... Prev by Date: ...
    (comp.lang.cobol)
  • Re: convert packed CHAR to unpacked DIGIT
    ... ssb wrote: ... > Input record has a field of size 5 bytes containing packed numbers. ... > this field is defined as CHARACTER. ... half-byte of the rightmost byte, if indeed the real field size is six ...
    (comp.lang.cobol)