/* REXX MEMIDX Generates an index-member for a partitioned dataset. Use '(routine name) ?' for HELP-text. Written by Frank Clarke rexxhead@yahoo.com 20210419 Impact Analysis . SYSEXEC DIRSTATS . SYSEXEC SYSUMON . SYSEXEC TRAPOUT . SYSEXEC UPOE Modification History 20230401 fxc SYSUMON only if not testing 20230414 fxc minor alignment for easier reading 20230531 fxc make sure the 'Directory' line has the right DSN; 20230726 fxc adjust HELP; 20230806 fxc chg SYSPROC to SYSEXEC in Impact Analysis; 20240308 fxc chg dollar-sign to @ everywhere; 20240411 fxc DIRSTATS output format changed because size and init were not separated; 20240415 fxc DUMP_QUEUE quiet; 20240604 fxc recreate stats after update; */ arg argline address TSO /* REXXSKEL ver.20210402 */ arg parms "((" opts signal on syntax signal on novalue call TOOLKIT_INIT /* conventional start-up -*/ rc = Trace("O"); rc = Trace(tv) info = parms /* to enable parsing */ call A_INIT /* initialization -*/ call D_GETDIR /* run DIRSTATS -*/ call M_MERGE /* post existing to table -*/ call X_MAKEINDX /* write the #INDEX member -*/ if \sw.nested then call DUMP_QUEUE 'quiet' /* -*/ queue cmd /* */ exit /*@ MEMIDX */ /* Initialization . ----------------------------------------------------------------- */ A_INIT: /*@ */ if branch then call BRANCH address TSO if tv = 'N' then, /* only if not testing */ "SYSUMON USER" Userid() "TOOL" exec_name parse value "" with , zlvers zlmod zlcdate zlmdate zlmtime zlcnorc , zlinorc zlmnorc zlc4date zlm4date zotz cmd parse value "0 0 0 0 0 0 0 0 0" with, hdr. , . parse var parms targetds . /* TSO-format DSN */ if Sysdsn(targetds) <> "OK" then do helpmsg = "Target dataset missing or invalid." call HELP /* -*/ end if Left(targetds,1) = "'" then, targetds = Strip(targetds,,"'") /* unquoted */ else, /* originally unquoted */ targetds = Userid()"."targetds /* fully-qualified */ targetmbr = targetds"(#INDEX)" if Sysdsn("'"targetmbr"'") <> "OK" then, call AH_LOAD_HDRS /* guarantee headers -*/ else do call AS_SNAP_STATS /* -*/ "ALLOC FI(@IDX) DA('"targetmbr"') SHR REU" end return /*@ A_INIT */ /* #INDEX is empty. Load headers only. . ----------------------------------------------------------------- */ AH_LOAD_HDRS: /*@ */ if branch then call BRANCH address TSO "ALLOC FI(@IDX) DA('"targetmbr"') SHR REU" "NEWSTACK" queue " " queue " '"targetds"' - Directory" queue " " queue " " queue " Usage or" queue " Member Caller Description" queue " ======== ========= =====================================" "EXECIO" queued() "DISKW @IDX (FINIS" "DELSTACK" return /*@ AH_LOAD_HDRS */ /* Get the existing stats for #INDEX and save. . ----------------------------------------------------------------- */ AS_SNAP_STATS: /*@ */ if branch then call BRANCH address ISPEXEC "CONTROL ERRORS RETURN" /* I'll handle my own */ "LMINIT DATAID( ZOTZ ) DATASET( '"targetds"' ) " if rc > 0 then do zerrsm = "LMINIT failed" zerrlm = lminit.rc "SETMSG MSG(ISRZ002)" sw.0error_found = 1 end else do /* LMINIT OK */ "LMOPEN DATAID( "zotz" ) OPTION( INPUT )" if rc > 0 then do zerrsm = "LMOPEN failed" zerrlm = lmopen.rc "SETMSG MSG(ISRZ002)" sw.0error_found = 1 end else do /* LMOPEN OK */ "LMMFIND DATAID("zotz") MEMBER( #INDEX ) STATS(YES)" if rc > 0 then do zerrsm = "LMMFIND failed" zerrlm = lmmfind.rc "SETMSG MSG(ISRZ002)" sw.0error_found = 1 end end "LMCLOSE DATAID("zotz")" end "LMFREE DATAID("zotz")" return /*@ AS_SNAP_STATS */ /* Run DIRSTATS, load to table . ----------------------------------------------------------------- */ D_GETDIR: /*@ */ if branch then call BRANCH address TSO "NEWSTACK" "DIRSTATS '"targetds"'" call DL_LOAD_TABLE /* TBADD each member -*/ "DELSTACK" return /*@ D_GETDIR */ /* TBCREATE IXTBL KEYS(IXMBR) NAMES(IXSIZE IXDATE IXUSER IXTYPE IXREMKS) NOWRITE REPLACE TBADD each member found in the stack. . ----------------------------------------------------------------- */ DL_LOAD_TABLE: /*@ */ if branch then call BRANCH address ISPEXEC "CONTROL ERRORS RETURN" /* I'll handle my own */ "TBCREATE IXTBL KEYS(IXMBR)", /* leaves table open */ "NAMES(IXSIZE IXDATE IXUSER IXTYPE IXREMKS)", "NOWRITE REPLACE" do queued() /* every line from DIRSTATS */ pull line /* and shift upper */ parse var line ixmbr, 10 tag 16, 32 chgdt chgtm size 52, 65 user . if tag = "STATS?" then, nop /* only IXMBR valid */ else, if tag = "*ALIAS" then, iterate /* skip this entry */ else do ixdate = chgdt chgtm ixuser = user ixsize = size + 0 end /* not alias, not stats */ "TBADD IXTBL" /* load the row */ "TBVCLEAR IXTBL" /* wipe all values */ end /* queued */ "TBTOP IXTBL" return /*@ DL_LOAD_TABLE */ /* Merge existing #INDEX by posting Remarks to table . ----------------------------------------------------------------- */ M_MERGE: /*@ */ if branch then call BRANCH address TSO "NEWSTACK" "EXECIO * DISKR @IDX (FINIS" call ML_LOAD_TABLE /* -*/ "DELSTACK" return /*@ M_MERGE */ /* Read the #INDEX and add any needed material to the table. . ----------------------------------------------------------------- */ ML_LOAD_TABLE: /*@ */ if branch then call BRANCH address ISPEXEC do queued() /* every line */ parse pull line /* keep it mixed-case */ if sw.0GotHdrs = 0 then do if Pos( '- Directory',line ) > 0 then do push " '"targetds"' - Directory" parse pull line end /* Directory */ parse value hdr.0+1 line with, @z hdr.@z 1 hdr.0 . if Pos('====',line) > 0 then sw.0GotHdrs = 1 iterate end /* GotHdrs off */ if line = "" then iterate parse var line ixmbr usage remarks "TBGET IXTBL" if rc > 0 then iterate /* table read failed */ ixtype = Strip(usage) ixremks = Strip(remarks) "TBMOD IXTBL" /* add values */ end /* queued */ return /*@ ML_LOAD_TABLE */ /* All the values are in the table. Missing members have been excised. Write the #INDEX member from the table data starting with the hdr. stem, then reload stats (if any), tagging the #INDEX as having been modified by user=MEMIDX. . ----------------------------------------------------------------- */ X_MAKEINDX: /*@ */ if branch then call BRANCH address TSO "NEWSTACK" do zz = 1 to hdr.0 /* each header */ queue hdr.zz end /* zz */ call XD_DUMP_TABLE /* table -> queue -*/ zlcnorc = queued() /* current size */ parse value zlinorc zlcnorc with zlinorc . parse value zlmnorc zlcnorc with zlmnorc . "EXECIO" queued() "DISKW @IDX (FINIS" "DELSTACK" "FREE FI( @IDX ) " parse value zlvers '03' with zlvers . parse value zlmod '03' with zlmod . parse value zlmtime Left( Time(),5 ) with zlmtime . today = Translate( 'CcYy/Mm/Dd',Date( 'S' ),'CcYyMmDd' ) parse value zlc4date today with zlc4date . parse value zlm4date today with zlm4date . "UPOE #INDEX "targetds zlvers zlmod zlc4date zlm4date zlmtime, zlcnorc zlinorc zlmnorc "MEMIDX" return /*@ X_MAKEINDX */ /* Transfer the table data to the queue so it can be written to #INDEX. . ----------------------------------------------------------------- */ XD_DUMP_TABLE: /*@ */ if branch then call BRANCH address ISPEXEC "TBTOP IXTBL" do forever "TBSKIP IXTBL" /* next row */ if rc > 0 then leave /* all done */ queue " " /* separator */ if ixtype = "" then ixtype = "(new)" if ixremks = "" then , if ixuser <> "" then , ixremks = "Lst chg" ixdate "by" ixuser else, ixremks = "(new)" queue " "Left(ixmbr,10)Left(ixtype,12)ixremks end /* forever */ "TBEND IXTBL" return /*@ XD_DUMP_TABLE */ /* . ----------------------------------------------------------------- */ LOCAL_PREINIT: /*@ customize opts */ address TSO lminit. = "Unknown return code" lminit.8 = "Data set or file not allocated because DDname not", "found or Data set or file organization not supported." lminit.12 = "Invalid parameter value " lminit.16 = "Truncation or translation error in accessing dialog", "variables." lminit.20 = "Severe error " lmopen. = "Unknown return code" lmopen.8 = "Open failed because Data set record format not", "supported by ISPF " lmopen.10 = "No data set associated with the dataid " lmopen.12 = "Invalid parameter value: Data set is already open", "or Cannot open data set allocated 'SHR' for output" lmopen.16 = "Truncation or translation error in storing defined", "variables " lmopen.20 = "Severe error" lmmfind. = "Unknown return code" lmmfind.4 = "Member not available" lmmfind.8 = "Member not found " lmmfind.10 = "No data set or file associated with the given dataid" lmmfind.12 = "Data set or file not open or not open for input", "because Data set is not an ISPF library or MVS", "partitioned data set or Invalid parameter value" lmmfind.16 = "Truncation or translation error in accessing dialog", "variables " lmmfind.20 = "Severe error " lmmstats. = "Unknown return code" lmmstats.4 = "No members match pattern or No member in data set" lmmstats.8 = "Member not found " lmmstats.10 = "No data set associated with the given dataid " lmmstats.12 = "Invalid parameter value: Data set is not open or is", "not partitioned " lmmstats.20 = "Severe error " lmclose. = "Unknown return code" lmclose.8 = "Data set is not open " lmclose.10 = "No data set associated with the given data id " lmclose.20 = "Severe error " lmfree. = "Unknown return code" lmfree.8 = "Free data set or file failed " lmfree.10 = "No data set or file associated with dataid " lmfree.20 = "Severe error " return /*@ LOCAL_PREINIT */ /* subroutines below LOCAL_PREINIT are not selected by SHOWFLOW */ /* . ----------------------------------------------------------------- */ HELP: /*@ */ address TSO;"CLEAR" if helpmsg <> "" then say helpmsg; say "" ex_nam = Left(exec_name,8) /* predictable size */ say " "ex_nam" creates or revises an index member (#INDEX) for the " say " target dataset. " say " " say " Syntax: "ex_nam" target (Required)" say " " say " target is the TSO-format dataset name to be indexed. If " say " #INDEX does not exist, it will be created. If it " say " does exist, any data will be preserved for all " say " members still present. " say " " "NEWSTACK"; pull ; "CLEAR" ; "DELSTACK" say " Debugging tools provided include: " say " " say " BRANCH show all paragraph entries. " say " " say " TRACE tv will use value following TRACE to place the " say " execution in REXX TRACE Mode. " say " " say " " say " Debugging tools can be accessed in the following manner: " say " " say " TSO "ex_nam" parameters (( debug-options " say " " say " For example " say " " say " TSO "ex_nam" (( MONITOR TRACE ?R " if sysvar("SYSISPF") = "ACTIVE" then, address ISPEXEC "CONTROL DISPLAY REFRESH" exit /*@ HELP */ /* . ----------------------------------------------------------------- */ BRANCH: Procedure expose, /*@ */ sigl exec_name rc = trace("O") /* we do not want to see this */ arg brparm . origin = sigl /* where was I called from ? */ do currln = origin to 1 by -1 /* inch backward to label */ if Right(Word(Sourceline(currln),1),1) = ":" then do parse value sourceline(currln) with pgfname ":" . /* Label */ leave ; end /* name */ end /* currln */ select when brparm = "NAME" then return(pgfname) /* Return full name */ when brparm = "ID" then do /* wants the prefix */ parse var pgfname pgfpref "_" . /* get the prefix */ return(pgfpref) end /* brparm = "ID" */ otherwise say left(sigl,6) left(pgfname,40) exec_name "Time:" time("L") end /* select */ return /*@ BRANCH */ /* . ----------------------------------------------------------------- */ DUMP_QUEUE: /*@ Take whatever is in stack */ rc = trace("O") /* and write to the screen */ address TSO arg mode . "QSTACK" /* how many stacks? */ stk2dump = rc - tk_init_stacks /* remaining stacks */ if stk2dump = 0 & queued() = 0 then return if mode <> "QUIET" then, say "Total Stacks" rc , /* rc = #of stacks */ " Begin Stacks" tk_init_stacks , /* Stacks present at start */ " Excess Stacks to dump" stk2dump do dd = rc to tk_init_stacks by -1 /* empty each one. */ if mode <> "QUIET" then, say "Processing Stack #" dd " Total Lines:" queued() do queued();parse pull line;say line;end /* pump to the screen */ "DELSTACK" /* remove stack */ end /* dd = 1 to rc */ return /*@ DUMP_QUEUE */ /* Handle CLIST-form keywords added 20020513 . ----------------------------------------------------------------- */ CLKWD: Procedure expose info /*@ hide all except info */ arg kw kw = kw"(" /* form is 'KEY(DATA)' */ kw_pos = Pos(kw,info) /* find where it is, maybe */ if kw_pos = 0 then return "" /* send back a null, not found*/ rtpt = Pos(") ",info" ",kw_pos) /* locate end-paren */ slug = Substr(info,kw_pos,rtpt-kw_pos+1) /* isolate */ info = Delstr(info,kw_pos,rtpt-kw_pos+1) /* excise */ parse var slug (kw) slug /* drop kw */ slug = Reverse(Substr(Reverse(Strip(slug)),2)) return slug /*@CLKWD */ /* Handle multi-word keys 20020513 . ----------------------------------------------------------------- */ KEYWD: Procedure expose info /*@ hide all vars, except info*/ arg kw kw_pos = wordpos(kw,info) /* find where it is, maybe */ if kw_pos = 0 then return "" /* send back a null, not found*/ kw_val = word(info,kw_pos+Words(kw))/* get the next word */ info = Delword(info,kw_pos,2) /* remove both */ return kw_val /*@ KEYWD */ /* . ----------------------------------------------------------------- */ KEYPHRS: Procedure expose, /*@ */ info helpmsg exec_name /* except these three */ arg kp wp = wordpos(kp,info) /* where is it? */ if wp = 0 then return "" /* not found */ front = subword(info,1,wp-1) /* everything before kp */ back = subword(info,wp+1) /* everything after kp */ parse var back dlm back /* 1st token must be 2 bytes */ if length(dlm) <> 2 then /* Must be two bytes */ helpmsg = helpmsg, "Invalid length for delimiter("dlm") with KEYPHRS("kp")" if wordpos(dlm,back) = 0 then /* search for ending delimiter*/ helpmsg = helpmsg, "No matching second delimiter("dlm") with KEYPHRS("kp")" if helpmsg <> "" then call HELP /* Something is wrong */ parse var back kpval (dlm) back /* get everything b/w delim */ info = front back /* restore remainder */ return Strip(kpval) /*@ KEYPHRS */ /* . ----------------------------------------------------------------- */ NOVALUE: /*@ */ say exec_name "raised NOVALUE at line" sigl say " " say "The referenced variable is" condition("D") say " " zsigl = sigl signal SHOW_SOURCE /*@ NOVALUE */ /* . ----------------------------------------------------------------- */ SHOW_SOURCE: /*@ */ call DUMP_QUEUE /* Spill contents of stacks -*/ if sourceline() <> "0" then /* to screen */ say sourceline(zsigl) rc = trace("?R") nop exit /*@ SHOW_SOURCE */ /* . ----------------------------------------------------------------- */ SS: Procedure /*@ Show Source */ arg ssbeg ssend . if ssend = "" then ssend = 10 if \datatype(ssbeg,"W") | \datatype(ssend,"W") then return ssend = ssbeg + ssend do ssii = ssbeg to ssend ; say Strip(sourceline(ssii),'T') ; end return /*@ SS */ /* . ----------------------------------------------------------------- */ SWITCH: Procedure expose info /*@ */ arg kw sw_val = Wordpos(kw,info) > 0 /* exists = 1; not found = 0 */ if sw_val then /* exists */ info = Delword(info,Wordpos(kw,info),1) /* remove it */ return sw_val /*@ SWITCH */ /* . ----------------------------------------------------------------- */ SYNTAX: /*@ */ errormsg = exec_name "encountered REXX error" rc "in line" sigl":", errortext(rc) say errormsg zsigl = sigl signal SHOW_SOURCE /*@ SYNTAX */ /* Can call TRAPOUT. . ----------------------------------------------------------------- */ TOOLKIT_INIT: /*@ */ address TSO info = Strip(opts,"T",")") /* clip trailing paren */ parse source sys_id how_invokt exec_name DD_nm DS_nm, as_invokt cmd_env addr_spc usr_tokn parse value "" with tv helpmsg . parse value 0 "ISR00000 YES" "Error-Press PF1" with, sw. zerrhm zerralrm zerrsm if SWITCH("TRAPOUT") then do "TRAPOUT" exec_name parms "(( TRACE R" info exit end /* trapout */ sw.nested = sysvar("SYSNEST") = "YES" sw.batch = sysvar("SYSENV") = "BACK" sw.inispf = sysvar("SYSISPF") = "ACTIVE" if Word(parms,1) = "?" then call HELP /* I won't be back */ "QSTACK" ; tk_init_stacks = rc /* How many stacks? */ parse value SWITCH("BRANCH") SWITCH("MONITOR") SWITCH("NOUPDT") with, branch monitor noupdt . parse value mvsvar("SYSNAME") sysvar("SYSNODE") with, #tk_cpu node . parse value KEYWD("TRACE") "N" with tv . tk_globalvars = "exec_name tv helpmsg sw. zerrhm zerralrm ", "zerrsm zerrlm tk_init_stacks branch monitor ", "noupdt" call LOCAL_PREINIT /* for more opts -*/ return /*@ TOOLKIT_INIT */