View previous topic :: View next topic
|
Author |
Message |
WilliamDownie
New User
Joined: 01 Jul 2020 Posts: 21 Location: UK
|
|
|
|
Hello,
It is possible for a REXX exec to determine the library it is executing from ? The reason I'd like to know is if it's being executed from the development library I'd like to LIBDEF the development panel library, otherwise use the panel library allocated to ISPPLIB.
When running in development I "EX" the REXX member from the ISPF Member list. Otherwise it is ran via "TSO EXECNAME" from the command prompt and the REXX is executed from the library allocated to SYSEXEC. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1256 Location: Bamberg, Germany
|
|
|
|
You mean sth like this?
Code: |
PARSE SOURCE
parses data describing the source of the program running. The language
processor returns a string that is fixed (does not change) while the
program is running. |
Code: |
/* REXX */
trace ?o
parse source allsource
parse var allsource . . . . dsn . . . |
|
|
Back to top |
|
|
WilliamDownie
New User
Joined: 01 Jul 2020 Posts: 21 Location: UK
|
|
|
|
Hi Joerg, this is exactly what I was looking for. Thanks very much. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Except that it won't work when running from the next library in a concatenation...
Code: |
/* REXX exec to find dataset from which an exec is running */
/*** trace ?r ***************************************************** \| *
* (C) Copyright Frank Clarke, 2005-2007 *
************************************************************************
* ------------------------------------------------------------------ *
* | Date | By | Remarks | *
* |------------+------+----------------------------------------------| *
* | | | | *
* |------------+------+----------------------------------------------| *
* | 2007-09-04 | RAHP | Enclose URL in '<..>' | *
* |------------+------+----------------------------------------------| *
* | 2005-12-08 | FC | Initial version | *
* |------------+------+----------------------------------------------| *
************************************************************************
* ORIGIN is a REXX exec to find the library where the code was run *
* from. It assumes cataloged data sets. *
* *
* Original code by Doug Nadel, with SWA code lifted from Gilbert *
* Gilbert Saint-flour's SWAREQ exec. *
* *
* From: <http://www.tek-tips.com/viewthread.cfm?qid=1162402&page=3> *
***********************************************************************/
say find_origin()
exit
find_origin: procedure
numeric digits 10 /* allow up to 7FFFFFFF */
answer = "* UNKNOWN *" /* assume disaster */
parse source . . name dd ds . /* get known info */
call listdsi(dd "FILE") /* get 1st ddname from file */
if name = "?" then /* if sequential exec */
answer = "'"ds"'" /* use info from parse source */
else /* now test for members */
if sysdsn("'"sysdsname"("name")'") = "OK" then /* if in 1st ds */
answer = "'"sysdsname"("name")'" /* go no further */
else /* hooboy! Lets have some fun!*/
do /* scan tiot for the ddname */
tiotptr = 24 + ptr(12 + ptr(ptr(ptr(16))))/* get ddname array */
tioelngh = c2d(stg(tiotptr, 1)) /* length of 1st entry */
do until tioelngh = 0 | tioeddnm = dd /* scan until dd found */
tioeddnm = strip(stg(tiotptr + 4, 8)) /* get ddname from tiot */
if tioeddnm \= dd then /* if not a match */
tiotptr = tiotptr + tioelngh /* advance to next entry */
tioelngh = c2d(stg(tiotptr, 1)) /* length of next entry */
end
if dd = tioeddnm then /* if we found it, loop through
the data sets doing an swareq
for each one to get the
dsname */
do until tioelngh = 0 | stg(4 + tiotptr, 1) \= " "
tioejfcb = stg(tiotptr + 12, 3)
jfcb = swareq(tioejfcb) /* convert SVA to 31-bit addr */
dsn = strip(stg(jfcb,44)) /* dsname JFCBDSNM */
vol = storage(d2x(jfcb + 118),6)/* volser JFCBVOLS (unused) */
if sysdsn("'"dsn"("name")'") = 'OK' then /* found it? */
leave /* we is some happy campers! */
tiotptr = tiotptr + tioelngh /* get next entry */
tioelngh = c2d(stg(tiotptr, 1)) /* get entry length */
end
answer = "'"dsn"("name")'" /* assume we found it */
end
return answer
ptr: return c2d(storage(d2x(arg(1)), 4))
stg: return storage(d2x(arg(1)), arg(2))
swareq: procedure
if right(c2x(arg(1)), 1) \= 'F' then /* SWA=BELOW ? */
return c2d(arg(1)) + 16 /* yes, return sva + 16 */
sva = c2d(arg(1)) /* convert to decimal */
tcb = c2d(storage(21c, 4)) /* TCB PSATOLD */
tcb = ptr(540) /* TCB PSATOLD */
jscb = ptr(tcb + 180) /* JSCB TCBJSCB */
qmpl = ptr(jscb + 244) /* QMPL JSCBQMPI */
qmat = ptr(qmpl + 24) /* QMAT QMADD */
do while sva > 65536
qmat = ptr(qmat + 12) /* next QMAT QMAT + 12 */
sva = sva - 65536 /* 010006F -> 000006F */
end
return ptr(qmat + sva + 1) + 16
|
|
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
There is a possibility that the ALTLIB command was used to set an user library for rexx programs. And ALTLIB command can be used to stack different files. Use ALTLIB DISPLAY command, and for each file name the response provides, search each data set for the member. Then search SYSEXEC and SYSPROC. Search using the code provided by Prino / Doug Nadel. |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
The QBASELIB service might be another option to consider. Given a ddname it returns all of the DSNs concatenated to it. |
|
Back to top |
|
|
Willy Jensen
Active Member
Joined: 01 Sep 2015 Posts: 712 Location: Denmark
|
|
|
|
Outtrap a LISTALC command, run through the list of datasets excluding STEPLIB, *LIST* etc. Of course you must also check the RECFM for each dataset. Not very efficient but doable. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
I am not sure this was clear from earlier comments. The question was about where the rexx program was loaded from, so I think you have to follow the same 'search order' as what rexx would do.
- PARSE SOURCE results
- DD names from ALTLIB DISPLAY result
- SYSEXEC concatenation
- SYSPROC concatenation |
|
Back to top |
|
|
|