No, much less efficient (I assume). It's an external REXX exec; the caller feeds it a prefix, and it appends random numbers after the prefix until it hits a string that doesn't represent a DD that is currently allocated. It cannot be very fast, but then I need to call it only once or thrice in any given program. Here's the program in its entirety:
/* This REXX tries to return a free DD name of the form <pfx><nnnnn>. Supply a character string as prefix, and optionally a length, and TEMPDD will truncate the prefix to the length and try concatenating various random numbers to the end, looking for one that's not already allocated. After ten tries it gives up, but so far that's never happened to me. */ arg pfx,stemlen /* DDN prefix and trunc length */ if pfx='' then pfx='TEMP' else pfx=strip(pfx) if datatype(stemlen)<>'NUM' then stemlen=7 else stemlen=min(stemlen,8) lpfx=length(pfx) if lpfx>stemlen then do; pfx=left(pfx,stemlen); lpfx=stemlen; end if lpfx=8 then return pfx lsfx=min(8-lpfx,5) sfxmax=copies('9',lsfx) /* Now look for a free DD */ do 10; testdd=pfx||right(random(0,sfxmax),lsfx,'0') if \dsdd(testdd,'DD') then return testdd; end return '!NoFree' /* Call tree: DSDD */ The external call to DSDD uses LISTDSN to check whether the DD exists. It checks up to ten DDs before giving up, but I've never had it fail. Really, I'd expect nothing else; if a routine asks for a DD name starting with "TEST", what are the odds that TEST4914 is already used? I could execute such a command dozens of times without it having to look for a second choice, much less a tenth. Still, I get that this is truly ugly. It just works. Actually I haven't looked at it in some years; now that I do, I notice a bug in it, one I've never triggered so it never came to my attention before. I'll have to fix it; maybe I can improve the ugliness at the same time. What's a "race condition"? --- Bob Bridges, robhbrid...@gmail.com, cell 336 382-7313 /* For Sale: Parachute. Only used once, never opened, small stain. */ -----Original Message----- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Paul Gilmartin Sent: Tuesday, March 31, 2020 17:57 I suspect that uses SVC 99 (what else?) Is that easier than BPXWDYN( 'ALLOC RTDDN(name) ...')? (But do you want finer control of the name space, as GIMSMP does?) What about race conditions? --- On Tue, 31 Mar 2020 17:35:52 -0400, Bob Bridges wrote: >I have a TEMPDD routine that returns a DD name guaranteed to be unused; >otherwise many of my routines would end up conflicting whenever I use them >recursively (sort of). ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN