IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Determine Library REXX exec was executed from


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
WilliamDownie

New User


Joined: 01 Jul 2020
Posts: 18
Location: UK

PostPosted: Sun Feb 14, 2021 6:20 pm
Reply with quote

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
View user's profile Send private message
Joerg.Findeisen

Active Member


Joined: 15 Aug 2015
Posts: 607
Location: Bamberg, Germany

PostPosted: Sun Feb 14, 2021 6:32 pm
Reply with quote

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
View user's profile Send private message
WilliamDownie

New User


Joined: 01 Jul 2020
Posts: 18
Location: UK

PostPosted: Mon Feb 15, 2021 12:45 pm
Reply with quote

Hi Joerg, this is exactly what I was looking for. Thanks very much.
Back to top
View user's profile Send private message
prino
Warnings : 1

Senior Member


Joined: 07 Feb 2009
Posts: 1263
Location: Vilnius, Lithuania

PostPosted: Mon Feb 15, 2021 5:08 pm
Reply with quote

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
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2258
Location: Silicon Valley

PostPosted: Thu Feb 18, 2021 6:14 am
Reply with quote

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
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 708
Location: Whitby, ON, Canada

PostPosted: Thu Feb 18, 2021 9:30 am
Reply with quote

The QBASELIB service might be another option to consider. Given a ddname it returns all of the DSNs concatenated to it.
Back to top
View user's profile Send private message
Willy Jensen

Active User


Joined: 01 Sep 2015
Posts: 495
Location: Denmark

PostPosted: Thu Feb 18, 2021 2:04 pm
Reply with quote

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
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2258
Location: Silicon Valley

PostPosted: Fri Feb 19, 2021 12:37 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts SXP Tool for PL1 or Module library ma... PL/I & Assembler 0
No new posts How to modify file content using REXX CLIST & REXX 3
No new posts Same command as on commandline in REX... TSO/ISPF 6
No new posts Cobol program to determine the sequen... COBOL Programming 2
No new posts process statement for SUPREC, CMPCOLM... TSO/ISPF 4
Search our Forums:

Back to Top