/* abstract: OCTAL returns the unsigned octal character string representation, without leading zeroes, of a FIXED BINARY(15,0) number. calling sequence: = OCTAL (num) returns: CHARACTER (*) [VARYING] the character representation of the fixed binary number argument: num FIXED BINARY (15,0) the number to be converted to octal. */ OCTAL: procedure(num) returns(char(*) varying); dcl s char(6) varying, (x, d) fixed bin(15), a_char char(1) based; dcl IAND entry(fixed bin(15), fixed bin(15)) returns(fixed bin(15)); dcl ISHFT entry(fixed bin(15), fixed bin(15)) returns(fixed bin(15)); s = ''; x = num; /* repeat */ digit: d = IAND(x,'7'B3) + '60'B3 /*ascii 0*/; s = addr(d)->a_char !! s; x = IAND( ISHFT(x,-3), '1FFF'B4); /*unsigned shift right 3 bits*/ /* until x = 0 */ if x^=0 then goto digit; return(s); end;