Home > Coding, ISPF, Mainframe, REXX > Finding out where a Rexx exec was loaded from

Finding out where a Rexx exec was loaded from

I had a need to find out which data set a Rexx exec was being loaded from within the exec. Whilst there are examples out there that trawl through the TIOT, since I was in an ISPF environment I came up with the following little bit of code:

/* rexx */

/* Find out where I came from.             */

address ispexec

PARSE SOURCE . . pgm execdd .

"qbaselib "execdd" id(dsns)"

dsns = Translate(DSNS,' ',',')
dsnum = words(dsns)

do n = 1 to dsnum

   dsn = strip(word(dsns,n),"B","'")
   "lminit dataid(id) dataset('"||dsn||"')"
   "lmopen dataid("id")"
   "lmmfind dataid("id") member("pgm") stats(yes)"
   findrc=rc
   "lmclose dataid("id")"
   "lmfree dataid("id")"
   if findrc = 0 then leave

   end /* do dsnum */

if findrc = 0 then do
   say pgm "was loaded from <"dsn">"
   return 0
   end
else do
   say "cannot determine where "pgm" was loaded from"
   return 4
   end

It would be easy to make this into a function to return the data set name (in the dsn variable).

Advertisements
Categories: Coding, ISPF, Mainframe, REXX
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: