/* REXX TBLGEN TBCREATE a new table of type AATBLID according to specifics stored in AAMSTR, the Master Table-of-Tables. The structure of AAMSTR is: Variable T Example (for the AA-row) -------- - ------------------- AATBLID K AA (for the AAMSTR table itself) AATBLNM N AAMSTR AAKEYS N AATBLID AANAMES N AATBLNM AADESC AAKEYS AANAMES AASORT AASORT N AATBLID,C,A AADESC N Master Table AALIBR N Canonical Table Location Use '(routine name) ?' for HELP-text. Written by Frank Clarke, Oldsmar FL, 19980528 rexxhead@yahoo.com Impact Analysis . SYSEXEC DFLTTLIB . SYSEXEC LA SYSEXEC TRAPOUT Modification History 20010223 fxc finally added help-text for DESCRIBE; wrapped CLEAR commands with NEWSTACK/DELSTACK; 20010720 fxc WIDEHELP; 20230401 fxc SYSUMON only if not testing 20230425 fxc adjust HELP; make sure ISPTABL has a value; use the computed or specified ISPTABL; 20230427 fxc better diagnostics when TBCREATE fails 20230506 fxc TBLGEN was not TBCLOSEing 20230518 fxc fixed quoted dataset problem 20230722 fxc upgrade to v.20230722; enable LEAVE; 20230724 fxc modernize logging; 20230806 fxc chg SYSPROC to SYSEXEC in Impact Analysis; 20230829 fxc DFLTTLIB returns FQ-U dsname; 20230908 fxc set log lrecl to 255; 20240209 fxc disable SYSUMON; 20240308 fxc chg dollar-sign to @ everywhere; 20240309 fxc add logpref; 20240328 fxc TBCLOSE to AALIBR; added LIBR to DESCRIBE string; 20240415 fxc DUMP_QUEUE quiet; */ arg argline address ISPEXEC /* REXXSKEL ver.20230722 */ 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 */ "CONTROL ERRORS RETURN" call A_INIT /* -*/ call B_READ_MSTR /* -*/ if \sw.0error_found then, call C_BUILD /* -*/ if sw.0savelog then call ZB_SAVELOG /* -*/ if \sw.0nested then call DUMP_QUEUE 'quiet' /* -*/ exit /*@ TBLGEN */ /* . ----------------------------------------------------------------- */ A_INIT: /*@ */ if branch then call BRANCH address TSO /* if tv = 'N' then, /* only if not testing */ "SYSUMON USER" Userid() "TOOL" exec_name */ call AA_SETUP_LOG /* -*/ call AK_KEYWDS /* -*/ openmode.0 = "WRITE" /* based on NOUPDT */ openmode.1 = "NOWRITE" return /*@ A_INIT */ /* . ----------------------------------------------------------------- */ AA_SETUP_LOG: /*@ */ if branch then call BRANCH address TSO msglim = SYSVAR( "SYSWTERM" ) - 12 parse value "0 0 0 0 0" with, log# log. . parse value Date("S") Time("S") Time("N") with, yyyymmdd sssss hhmmss . hhmmss = Space( Translate( hhmmss,' ',':' ) ,0 ) parse var yyyymmdd 4 yrdigit 5 mm 7 dd /* 9 12 14 maybe */ if Pos(yrdigit,"13579") > 0 then mm = mm + 12 /* mm=24 */ logtag = Substr("ABCDEFGHIJKLMNOPQRSTUVWX",mm,1) /* logtag=X */ subid = logtag""dd""Left( hhmmss,4 ) /* X141743 ? */ vb4k.0 = "NEW CATALOG UNIT(SYSDA) SPACE(1 5) TRACKS", "RECFM( V B ) LRECL( 255 ) BLKSIZE( 0 )" logdsn = "@LOG."exec_name"."subid".LIST" logpref = "("Branch("ID")")" call ZL_LOGMSG( exec_name "started by" Userid() yyyymmdd hhmmss ) call ZL_LOGMSG( logpref "Arg:" argline ) return /*@ AA_SETUP_LOG */ /* . ----------------------------------------------------------------- */ AK_KEYWDS: /*@ */ if branch then call BRANCH address ISPEXEC tblnm = KEYWD( "TBLNAME" ) sw.0savelog = SWITCH( "LOG" ) sw.0Leave = SWITCH( "LEAVE" ) sw.0testmode = SWITCH( "TEST" ) sw.0describe = SWITCH( "DESCRIBE" ) parse var info aatblid genparms return /*@ AK_KEYWDS */ /* Get the TBCREATE info from table AAMSTR . ----------------------------------------------------------------- */ B_READ_MSTR: /*@ */ if branch then call BRANCH address ISPEXEC "LIBDEF ISPTLIB DATASET ID( "isptlib" ) STACK" "TBSTATS" @aa@ "STATUS1(s1) STATUS2(s2)" if s1 > 1 then do say "Table" @aa@ "not available." exit end; else, if s2 = 1 then, /* not open */ "TBOPEN " @aa@ "NOWRITE" else "TBTOP" @aa@ "LIBDEF ISPTLIB" logpref = "("Branch("ID")")" "TBGET" @aa@ /* aatblid is already set */ if rc > 0 then do zerrsm = "TBGET failed for key="aatblid zerrlm = exec_name "("BRANCH("ID")")", "Row not found for ID" aatblid, "in "isptlib" member" @aa@".", " Are you using the correct ISPTLIB dataset?" address ISPEXEC "SETMSG MSG(ISRZ002)" if monitor then say zerrlm sw.0error_found = 1 end "TBEND" @aa@ /* AAMSTR is closed */ call ZL_LOGMSG( logpref "AATBLID="aatblid "AATBLNM="aatblnm, "AAKEYS="aakeys "AANAMES="aanames "AASORT="aasort, "AADESC="aadesc "AALIBR="aalibr ) return /*@ B_READ_MSTR */ /* A successful TBGET of AAMSTR has set (or reset) all the AA~ variables that are needed for the TBCREATE. . ----------------------------------------------------------------- */ C_BUILD: /*@ */ if branch then call BRANCH address ISPEXEC logpref = "("Branch("ID")")" parse value tblnm aatblnm with tblnm . if sw.0describe then do queue "KEYS("aakeys") NAMES("aanames") SORT("aasort")", "LIBR("aalibr")" return end else, if sw.0testmode then do address TSO "CLEAR" say "TBLGEN will issue the following commands:" say "" say, "TBCREATE" tblnm "KEYS("aakeys") NAMES("aanames")" genparms say "" end else do if aalibr = "*" then, aalibr = isptabl /* Use default */ /* genparms = genparms "LIBRARY(isptabl)" */ cmd = "TBCREATE" tblnm "KEYS("aakeys") NAMES("aanames")" genparms (cmd) call ZL_LOGMSG( logpref cmd "RC="rc ) end if rc > 4 then do zerrsm = "TBCREATE failed." zerrlm = zerrlm , "TBLNM="tblnm " GENPARMS="genparms " KEYS="aakeys, " NAMES="aanames zerrlm = exec_name "("BRANCH("ID")")", zerrlm "SETMSG MSG(ISRZ002)" if monitor then say zerrlm sw.0error_found = 1 ; return end ; else, if rc > 0 then do zerrsm = "Table was replaced." zerrlm = exec_name "("BRANCH("ID")")", "TBCREATE replaced existing table" aatblnm"." "SETMSG MSG(ISRZ002)" if monitor then say zerrlm end if aasort <> "" then do if sw.0testmode then do say "" say, "TBSORT" tblnm "FIELDS("aasort")" say "" end else do cmd = "TBSORT" tblnm "FIELDS("aasort")" (cmd) call ZL_LOGMSG( logpref cmd "RC="rc ) end end if WordPos( "NOWRITE",genparms ) > 0 then return /* leave it */ if sw.0Leave then return "LIBDEF ISPTABL DATASET ID( '"aalibr"' ) STACK" cmd = "TBCLOSE" tblnm (cmd) call ZL_LOGMSG( logpref cmd "RC="rc "To" aalibr ) if sw.0Leave = 1 then do /* Reopen */ cmd = "TBOPEN " tblnm (cmd) call ZL_LOGMSG( logpref cmd "RC="rc "From" aalibr ) end "LIBDEF ISPTABL" return /*@ C_BUILD */ /* . ----------------------------------------------------------------- */ LOCAL_PREINIT: /*@ customize opts */ address TSO rc = Trace("O") rc = trace( tv ) source = DFLTTLIB('AAMSTR') /* returns unquoted */ source = "'"source"'" /* TSO format */ parse value KEYWD("ISPTLIB") source with, /*AAMSTR location */ isptlib . parse value KEYWD("ISPTABL") isptlib with, /* target location */ isptabl . parse value KEYWD("USETBL") "AAMSTR" with, /* the Master Table */ @aa@ . return /*@ LOCAL_PREINIT */ /* subroutines below LOCAL_PREINIT are not selected by SHOWFLOW */ /* . ----------------------------------------------------------------- */ ZB_SAVELOG: /*@ */ if branch then call BRANCH address TSO if Symbol("LOG#") = "LIT" then return /* not yet set */ "ALLOC FI(@LOG) DA("logdsn") REU" vb4k.0 "EXECIO" log# "DISKW @LOG (STEM LOG. FINIS" "FREE FI(@LOG)" return /*@ ZB_SAVELOG */ /* . ----------------------------------------------------------------- */ ZL_LOGMSG: Procedure expose, /*@ */ (tk_globalvars) log. log# msglim rc = Trace("O") address TSO parse arg msgtext /* for making the msgline always reasonably short: */ do while Length(msgtext) > msglim pt = LastPos(" ",msgtext,msglim) slug = Left(msgtext,pt) if monitor then say, slug parse value log#+1 slug with, zz log.zz 1 log# . msgtext = " "Substr(msgtext,pt) end /* while msglim */ parse value log#+1 msgtext with, zz log.zz 1 log# . if monitor then say, msgtext return /*@ ZL_LOGMSG */ /* . ----------------------------------------------------------------- */ HELP: /*@ */ address TSO;"CLEAR" if helpmsg <> "" then say helpmsg ex_nam = Left(exec_name,8) /* predictable size */ say " " say " "ex_nam" builds a new ISPF table from parameters stored in the " say " Table Master table. " say " " say " Syntax: "ex_nam" tblid (Required)" say " LEAVE " say " LOG " say " TEST " say " DESCRIBE " say " TBLNAME tblnm (Defaults)" say " add'l TBCREATE parameters " say " (( ISPTLIB indsn " say " ISPTABL outdsn " say " USETBL mstrtbl " say " " say " tblid is the two-character identifier which is the key of " say " AAMSTR. " "NEWSTACK"; pull ; "CLEAR" ; "DELSTACK" say " " say " LEAVE directs that the newly-created table be left in an " say " 'open' condition. "exec_name" normally closes the " say " new table. " say " " say " LOG directs that the progress log be retained. " say " " say " TEST instructs" exec_name "to display the commands which " say " would have been issued in the absence of 'TEST'. " say " The commands are displayed but not executed. " say " " say " DESCRIBE instructs" exec_name "to return, via the data stack," say " a description of the table. The following line is " say " placed on the stack: " say " KEYS(...) NAMES(...) SORT(...) LIBR(...) " "NEWSTACK"; pull ; "CLEAR" ; "DELSTACK" say " " say " tblnm is the name to be given to the newly-created table. " say " If tblnm is not specified, the default name stored " say " in the master table, if any, is used. " say " " say " indsn is the name of the table library which contains the " say " mstrtbl. If no value is specified, DFLTTLIB will be" say " called to supply a value. " say " " say " outdsn is the name of the table library used for storing " say " the newly-created table. If not specified, the " say " value of AALIBR is used. If AALIBR is '*', the " say " current ISPTABL is substituted. " say " " say " mstrtbl is the name of the table from which to obtain the " say " definition used to build the new table. If not " say " specified, 'AAMSTR' will be used. " "NEWSTACK"; pull ; "CLEAR" ; "DELSTACK" say " Debugging tools provided include: " say " " say " NOUPDT: by-pass all update logic. " say " " say " BRANCH: show all paragraph entries. " say " " say " TRACE tv: will use value following TRACE to place the execution in" say " REXX TRACE Mode. " say " " say " " say " Debugging tools can be accessed in the following manner: " say " " say " TSO" exec_name" parameters (( debug-options " say " " say " For example: " say " " say " TSO" exec_name " (( 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")", info if wordpos(dlm,back) = 0 then /* search for ending delimiter*/ helpmsg = helpmsg, "No matching second delimiter("dlm") with KEYPHRS("kp")", info 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 zerrlm . 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.0nested = sysvar("SYSNEST") = "YES" sw.0batch = sysvar("SYSENV") = "BACK" sw.0inispf = 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 */