[Info-vax] COBOL example $MGBLSC

Arne Vajhøj arne at vajhoej.dk
Fri Sep 8 22:38:13 EDT 2023


On 9/8/2023 10:18 PM, Arne Vajhøj wrote:
> On 9/8/2023 12:45 PM, Brian Schenkenberger wrote:
>> It'd be great too if there was a way to DISPLAY them in HEX
> 
> I don't know the right Cobol way to display as hex, but
> FAO work in Cobol as well.
> 
> identification division.
> program-id.hex1.
> *
> data division.
> working-storage section.
> 01  v       pic 9(9) comp.
> 01  fmt     pic x(7) value "!SL !XL".
> 01  buflen  pic 9(9) comp.
> 01  buf     pic x(100).
> *
> procedure division.
> main-paragraph.
>      move 123 to v
>      call "LIB$SYS_FAO"
>          using
>             by descriptor fmt
>             by reference buflen
>             by descriptor buf
>             by value v
>             by value v
>      end-call
>      display buf(1:buflen)
>      stop run.

Or if you really want to hack it:

identification division.
program-id.hex2.
*
data division.
working-storage section.
01  v       pic 9(9) comp.
01  fmt     pic x(11) value "%d %08x%c%c".
01  cr      pic 9(9) comp value 13.
01  lf      pic 9(9) comp value 10.
*
procedure division.
main-paragraph.
     move 123 to v
     call "DECC$GXPRINTF"
         using
            by reference fmt
            by value v
            by value v
            by value cr
            by value lf
     end-call
     stop run.

Arne





More information about the Info-vax mailing list