/* Sort the table. contains the sortspec in the format: {, { } } If is specified, it must be A or D. Additional sortspecs may be appended. . ----------------------------------------------------------------- */ BDS_SORT: /*@ */ if branch then call BRANCH address ISPEXEC if tbldata = "" then, call BDSA_DESCRIBE /* -*/ sortspec = "" /* init empty */ origtext = text /* save */ if origtext = "DEFAULT" then, /* restore canonical order */ sortspec = origsort else, do while text <> "" parse var text spec text /* isolate next spec */ parse var spec fld "," dir if fld = "" then do zerrsm = "Error in SORT specification" zerrlm = exec_name "("BRANCH("ID")")", "You specified:", "<"Strip(origtext)">. ", " SORT specifications must contain table", "field names with optional directional indicators,", "(e.g.) 'ZORT,A BLAT GORF,D'. " exec_name, "detected a missing field-name." "SETMSG MSG(ISRZ002)" return end /* no fld ! */ if Wordpos(fld,keys names) = 0 then do zerrsm = "Error in SORT specification" zerrlm = exec_name "("BRANCH("ID")")", "You specified:", "<"Strip(origtext)">. ", " SORT specifications must contain table", "field names with optional directional indicators,", "(e.g.) 'ZORT,A BLAT GORF,D'. " exec_name, "detected an incorrect field-name. ", "The valid field-names are:" , "<"Strip(keys names)">." "SETMSG MSG(ISRZ002)" return end /* unknown field name */ parse value dir "A" with dir . /* default to A */ if Wordpos(dir,"A D") = 0 then do zerrsm = "Error in SORT specification" zerrlm = exec_name "("BRANCH("ID")")", "You specified:", "<"Strip(origtext)">. ", " SORT specifications must contain table", "field names with optional directional indicators.", " Directional indicators may be either A or D. ", exec_name "detected an incorrect directional", "indicator." "SETMSG MSG(ISRZ002)" return end /* bad dir ! */ sortspec = sortspec fld",C,"dir end /* text */ sortspec = Strip(sortspec) sortspec = Translate(sortspec , "," , " ") "TBSORT" $tn$ "FIELDS("sortspec")" return /*@ BDS_SORT */ /* Ask TBLGEN to describe the table. . ----------------------------------------------------------------- */ BDSA_DESCRIBE: /*@ */ if branch then call BRANCH address TSO "NEWSTACK" "TBLGEN" tbltype "DESCRIBE" pull tbldata "DELSTACK" parse var tbldata "KEYS(" keys ")" , "NAMES(" names ")" , "SORT(" origsort ")" return /*@ BDSA_DESCRIBE */