/* REXX FLTTBL Cloned from DUMPTBL 960619 to produce a flat version (up to 32K characters wide) of any ISPF table. Use '(routine name) ?' for HELP-text. Written by Frank Clarke rexxhead@yahoo.com 19960619 Impact Analysis . SYSEXEC LA . SYSEXEC TRAPOUT Modification History 19960918 fxc added some error-checking 19970115 fxc upgrade REXXSKEL from v.960606 to v.970113; add RESTARTability; 19991231 fxc upgrade REXXSKEL from v.970113 to v.19991109; RXSKLY2K; DECOMM; LRECL reduced from 32K to "min needed"; 20210510 fxc upgrade HELP; 20210530 fxc add 'bytes_to_add' blanks to every line; if new LRECL is larger than an existing LRECL, delete and allocate NEW; 20230203 fxc made callable from READY; 20230519 fxc use 'eaea'x (²²) as the separator; adjust HELP; 20230730 fxc adjust HELP; 20230806 fxc chg SYSPROC to SYSEXEC in Impact Analysis; 20240308 fxc chg dollar-sign to @ everywhere; */ arg argline address TSO /* REXXSKEL ver.19991109 */ arg parms "((" opts signal on syntax signal on novalue call TOOLKIT_INIT /* conventional start-up -*/ rc = Trace(tv) info = parms /* to enable parsing */ if \sw.inispf then do arg line line = line "(( RESTARTED" /* tell the next invocation */ address TSO "ISPSTART CMD("exec_name line")" /* Invoke ISPF if nec. */ exit /* ...and restart it */ end call A_INIT /* -*/ "NEWSTACK" if \sw.0error_found then, call C_TABLE_OPS /* -*/ if \sw.0error_found then, call D_PUMP_TBL /* -*/ "DELSTACK" if sw.0restarted then do rc = OutTrap("ll.") exit 4 end exit /*@ FLTTBL */ /* . ----------------------------------------------------------------- */ A_INIT: /*@ */ if branch then call BRANCH address TSO call AA_KEYWDS /* -*/ parse var info @tn@ . /* table-name required */ if @tn@ = "" then do helpmsg = "Tablename is required." call HELP end parse value outdsn "FLATTBLS."@tn@ with, outdsn . if Sysdsn(outdsn) = "OK" then do rc = listdsi( outdsn ) currrecl = syslrecl end else currrecl = 0 hexchar = X2C( 'EA' ) /* convert to hexadecimal */ hexsep = Copies( hexchar,2 ) if tblds = "" then do call AB_FIND_LIBRARY /* -*/ if tblds = "" then do helpmsg = "Table" @tn@ "was not found in ISPTLIB. Please", "restart specifying a library name as shown below." call HELP /* ...and don't come back */ end end else, if Left(tblds,1) = "'" then tblds = Strip(tblds,,"'") else tblds = Userid()"."tblds return /*@ A_INIT */ /* . ----------------------------------------------------------------- */ AA_KEYWDS: /*@ */ if branch then call BRANCH address TSO tblds = KEYWD("IN") outdsn = KEYWD("OUTPUT") sortseq = KEYWD("SORT") sw.0purge = SWITCH("DELETEBEHIND") parse value KEYWD("ADD") "0" with bytes_to_add . return /*@ AA_KEYWDS */ /* was not specified. Locate the table in ISPTLIB. . ----------------------------------------------------------------- */ AB_FIND_LIBRARY: /*@ */ if branch then call BRANCH address TSO "NEWSTACK" "LA ISPTLIB ((STACK LINE" pull tliblist "DELSTACK" do Words(tliblist) /* each library */ parse var tliblist tblds tliblist if Sysdsn("'"tblds"("@tn@")'") = "OK" then return end /* tliblist */ tblds = "" return /*@ AB_FIND_LIBRARY */ /* . ----------------------------------------------------------------- */ C_TABLE_OPS: /*@ */ if branch then call BRANCH address ISPEXEC call CA_OPEN_TBL /* -*/ call CS_SPIN_TBL /* -*/ call CZ_DROP_TBL /* -*/ return /*@ C_TABLE_OPS */ /* . ----------------------------------------------------------------- */ CA_OPEN_TBL: /*@ */ if branch then call BRANCH address ISPEXEC "LIBDEF ISPTLIB DATASET ID('"tblds"') STACK" "TBSTATS" @tn@ "STATUS1(s1) STATUS2(s2) ROWCURR(rowct)" if s1 > 1 then do say "Table" @tn@ "not available." sw.0error_found = "1"; return end; else, if s2 = 1 then, /* not open */ "TBOPEN " @tn@ "NOWRITE" else "TBTOP" @tn@ "LIBDEF ISPTLIB" if sw.0error_found then return "TBQUERY" @tn@ "KEYS(keylist)", "NAMES(nmlist)" parse var keylist "(" keylist ")" parse var nmlist "(" nmlist ")" namelist = keylist nmlist if sortseq <> "" then "TBSORT" @tn@ "FIELDS("sortseq")" return /*@ CA_OPEN_TBL */ /* . Given: contains all the defined names for this table. The table has been TOPped. . ----------------------------------------------------------------- */ CS_SPIN_TBL: Procedure expose, /*@ hide everything */ expose (tk_globalvars), /* except these */ @tn@ namelist hexsep tblds rows keylist nmlist maxlen, bytes_to_add cs_tv = Trace() if branch then call BRANCH address ISPEXEC maxlen = 0 /* maximum line length */ do forever "TBSKIP" @tn@ "SAVENAME(xvars)" if rc > 0 then leave /* we're done... */ line = "" /* set empty */ /* add blocks of "var .. varvalue .." */ do cx = 1 to Words(namelist) thiswd = Word(namelist,cx) line = line thiswd hexsep Value(thiswd) hexsep end /* cx */ rc = Trace("O"); rc = Trace(cs_tv) parse var xvars "(" xvars ")" /* add a block of "XVARS .. xvarlist .." */ line = line "XVARS" hexsep xvars hexsep /* add blocks of "xvar .. xvarvalue .." */ do cx = 1 to Words(xvars) thiswd = Word(xvars,cx) line = line thiswd hexsep Value(thiswd) hexsep end /* cx */ rc = Trace("O"); rc = Trace(cs_tv) line = line Left(" ",bytes_to_add)"." maxlen = Max(maxlen,Length(line)) queue line end /* forever */ lines_in_stack = queued() line = "Contents of" @tn@ "in" tblds, "("lines_in_stack" rows) KEYS("keylist") NAMES("nmlist")." push line /* make it the first line */ maxlen = Max(maxlen,Length(line)) if monitor then say "Maximum line length is" maxlen return /*@ CS_SPIN_TBL */ /* . ----------------------------------------------------------------- */ CZ_DROP_TBL: /*@ */ if branch then call BRANCH address ISPEXEC if s2 = 1 then, /* table was not open at start*/ "TBEND" @tn@ return /*@ CZ_DROP_TBL */ /* . ----------------------------------------------------------------- */ D_PUMP_TBL: /*@ */ if branch then call BRANCH address TSO if monitor then say, "Writing text." maxlen = maxlen + 4 /* set LRECL */ if currrecl <> "0" then, /* exists */ if maxlen > currrecl then "DEL" outdsn /* must be reallocated */ vbmax.0 = "NEW CATALOG UNIT(SYSDA) SPACE(1 5) TRACKS", "RECFM(V B) LRECL("maxlen") BLKSIZE(0)" vbmax.1 = "SHR" /* if it already exists... */ tempstat = Sysdsn(outdsn) = "OK" /* 1=exists, 0=missing */ "ALLOC FI(@TMP) DA("outdsn") REU" vbmax.tempstat rcx = rc "EXECIO" queued() "DISKW @TMP (FINIS" rcx = max(rcx,rc) "FREE FI(@TMP)" if rcx = 0 & sw.0purge then do address ISPEXEC "LIBDEF ISPTLIB DATASET ID('"tblds"') STACK" "TBERASE" @tn@ if rc = 0 then say @tn@ "was deleted" "LIBDEF ISPTLIB" end return /*@ D_PUMP_TBL */ /* . ----------------------------------------------------------------- */ LOCAL_PREINIT: /*@ customize opts */ if branch then call BRANCH address TSO sw.0restarted = SWITCH( "RESTARTED" ) return /*@ LOCAL_PREINIT */ /* . ----------------------------------------------------------------- */ HELP: /*@ */ address TSO;"CLEAR" if helpmsg <> "" then say helpmsg ex_nam = Left(exec_name,8) /* predictable size */ say " " say " "ex_nam" produces a flattened version of any ISPF table into a " say " VB-form PS dataset. " say " " say " The field contents are written in KEYPHRS format " say " (var .. varval ..) " say " key-fields first, followed by name-fields, followed by the names of any" say " extension variables KEYPHRaSed by 'XVARS', followed by the extension " say " variables themselves in KEYPHRS format. " say " " say " The first record on the file identifies the table name, the source " say " library, the number of rows processed, and the key- and name-fields. " say " This information is useful to RSTTBL, the anti-process of FLTTBL. " say " " say " more.... " "NEWSTACK"; pull; "CLEAR"; "DELSTACK" say " " say " Syntax: "ex_nam" tbl (Required)" say " IN libdsn " say " OUTPUT outdsn (Defaults)" say " SORT sortspec " say " ADD bytes (Defaults)" say " DELETEBEHIND " say " " say " tbl identifies the table to be dumped. " say " " say " libdsn identifies the ISPF Table library which holds 'tbl'." say " If libdsn is not specified, ISPTLIB will be searched" say " to find the correct dataset. " say " " say " outdsn (default: FLATTBLS.'tbl') names the output file. " say " 'outdsn' will be created if it does not exist. " say " " say " more... " "NEWSTACK"; pull; "CLEAR"; "DELSTACK" say " " say " sortspec causes the table to be sorted as indicated before " say " being dumped. " say " " say " bytes (default=0) causes the LRECL of the output dataset " say " to be extended to enable updating. " say " " say " DELETEBEHIND if set, purges the table after it has been " say " successfully copied to OUTPUT. " say " " say " more... " "NEWSTACK"; pull; "CLEAR"; "DELSTACK" say " Debugging tools provided include: " say " " say " MONITOR: displays key information throughout processing. " say " Displays most paragraph names upon entry. " 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" vt2231 add 17 (( MONITOR TRACE ?R " if sysvar("SYSISPF") = "ACTIVE" then, address ISPEXEC "CONTROL DISPLAY REFRESH" if sw.0restarted then do rc = OutTrap("ll.") exit 4 end 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 /* form is 'KEY DATA' */ 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 /* form is 'KEY ;: DATA ;:' */ 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 ssct . /* 'call ss 122 6' maybe */ if ssct = "" then ssct = 10 if \datatype(ssbeg,"W") | \datatype(ssct,"W") then return ssend = ssbeg + ssct do ssii = ssbeg to ssend ; say Strip(sourceline(ssii),'T') ; end return /*@ SS */ /* . ----------------------------------------------------------------- */ SWITCH: Procedure expose info /*@ */ arg kw /* form is 'KEY' */ 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 */