/* BEGIN DOCUMENTATION Name: CHARZ Created: 07/26/83 J Mele Last Update: 07/26/83 J Mele Title: Converts fixed bin to character(*) with leading zeros. Index: charz, char, conversion Abstract: This function accepts a number and length and returns a character string of the given length consisting of the number's absolute value with leading zeros. Usage: DCL CHARZ ENTRY(FIXED BIN(31), FIXED BIN(15)) RETURNS(CHAR(n)) (the n depends on your use - see description below) S = CHARZ(number,length) Parameters: number IN FIXED BIN(*) - number to be converted lenth IN FIXED BIN(15) - length of resulting string Environment: RSX-11M, AIS PL/I Description: This function accepts a number and length and returns a character string of given length containing the number's absolute value with leading zeros rather than leading blanks. Thus CHARZ(x,n) is like the PL/I builtin CHAR(x,n), except that it gives leading zeros, it truncates from the left rather than the right, and it is limited to FIXED BIN arguments. S=CHARZ(x,3) is equivalent to P=x; S=P, where P is PICTURE'999'; however the latter brings in as much as a couple thousand bytes additional runtime. Note that the number argument may be any FIXED BIN(*,0) - if it is not FIXED BIN(31), PL/I will automatically convert it. Until we have a compiler that supports RETURNS(CHAR(*)), how you declare the entry depends on your use. If all of your calls request the same length, say n, then declare it RETURNS(CHAR(n)). If you need more than one size on different calls, then declare it RETURNS(CHAR(m)) or RETURNS(CHAR(m) VARYING), where m is the largest size. If the number is longer than will fit in the given length it is truncated from left with no warning (neither SIZE nor STRINGSIZE are raised); in other words, CHARZ(x,n) gives the low order n digits. If the given string length is more than thirteen, the returned string will contain trailing blanks. Example(s): YZ = CHARZ(Y,3); Z = CHARZ(NUM,NDIGITS); CHARZ(123,6) returns '000123' CHARZ(-123,6) returns '000123' CHARZ(123,3) returns '123' CHARZ(123,2) returns '23' Internal: This program makes use of the automatic conversion built into PL/I for converting from number to string and then translates the leading blanks (and minus sign if there is one) into zeros substringing to obtain the desired length. In order to obtain the correct conversion the local character string must be of length thirteen (for fixed bin(31)) since that is the length string PL/I generates on conversion - if the variable was smaller, digits would be lost to truncation; if bigger, it would receive trailing blanks. Update History: NONE END DOCUMENTATION */ charz: procedure (fixbin,lenth) returns(char(*)); dcl fixbin fixed bin(31), lenth fixed bin(15), zchr char(13); zchr=fixbin; call trnslt(zchr,'00',' -'); return(substr(zchr,13-lenth+1)); end charz;