parm inputfile="?", linkfile="?", outputfile="?" if "!inputfile" = "?" or "!linkfile" = "?" or "!outputfile" = "?" then echo Usage: linkcmd unique_file, multi_file, output_file echo echo This command file does many-to-many links echo with Suprtool Self-Describing files echo This generic link is done by the primary sort key. echo echo The unique_file must have unique keys. echo The multi_file may have duplicate keys. echo The output_file must not exist. echo escape 0 endif comment comment Check existence of input files comment if not finfo("!inputfile","Exists") then echo Sorry, I can't seem to access !inputfile. escape endif if not finfo("!linkfile","Exists") then echo Sorry, I can't seem to access !linkfile escape 52 endif if finfo("!outputfile","Exists") then echo Sorry, !outputfile exists already. echo Please purge it or choose another name. escape endif comment comment Make sure that files are self-describing comment if not finfo("!inputfile","FILE CODE") = 1084 then echo Sorry, !inputfile is not a Self-Describing file. escape 52 endif if not finfo("!linkfile","FILE CODE") = 1084 then echo Sorry, !linkfile is not a Self-Describing file. escape 52 endif comment comment This step makes sure that workfiles do not exist comment already. comment setjcw insideqedit 0 purge mtomout > $null purge mtomout,temp > $null purge mtomlog > $null purge mtomlog,temp > $null purge mtomlnk > $null purge mtomlnk,temp > $null copy !linkfile,mtomlnk comment comment Find the primary sort key comment purge mtomkey > $null purge mtomkey,temp > $null purge mtomsort > $null purge mtomsort,temp > $null file formout=mtomkey;temp echo Form !inputfile > linkkey echo i mtomkey >> linkkey echo def keyinfo,43,12 >> linkkey echo def keyname,11,16 >> linkkey echo if keyinfo="<>" >> linkkey echo ext "sort ", keyname >> linkkey echo o mtomsort,temp >> linkkey echo e >> linkkey setjcw cierror 0 continue run suprtool.pub.robelle;parm=36;info="Use linkkey" >> mtomlog if cierror <> 0 then echo Suprtool encountered a serious error. Please see mtomlog. escape endif comment comment This step performs the initial link operation. comment It will create and initialize all the files. comment Parm=36 means : comment execute info string and do not suspend comment comment This step will perform the initial link operation comment with the first set of records. comment echo link i !inputfile > link1st echo link link mtomlnk >> link1st echo link o mtomout >> link1st echo link x >> link1st comment comment This step writes the initial link results to another file. All comment subsequent link results will be appended to that file. By default, comment Suprtool creates the output file with the same size as the input. comment Since you will be appending more records, you should use the comment numrecs command to specify the maximum number of records you expect. comment setvar output_size finfo('!inputfile', 'eof')*finfo('!linkfile','eof') echo i mtomout >> link1st echo numrecs !output_size >> link1st echo set squeeze off >> link1st echo o !outputfile >> link1st echo e >> link1st echo Initial Link pass setjcw cierror 0 continue run suprtool.pub.robelle;parm=36;info="u link1st" >> mtomlog if cierror <> 0 then echo Suprtool encountered a serious error. Please see mtomlog. escape endif comment comment This loop performs subsequent link operations comment with the remaining records in the complete comment secondary link file. comment WARNING comment The number of iterations of this loop is equal comment to the largest number of records having the same comment key value. comment ex.: if 5000 records have key value 123 then comment the loop will execute 5000 times. It also comment means that it will read the primary link comment file that many times. It adds up very comment quickly. comment comment This step scans the secondary link file and comment extracts the next set of records with duplicate comment key values. comment echo i mtomlnk > linkops echo use mtomsort >> linkops echo dupl only keys >> linkops echo o=input >> linkops echo x >> linkops comment comment This step will perform the next link operation with the new set of comment link records. comment echo link i !inputfile >> linkops echo link link mtomlnk >> linkops echo link o mtomout,erase >> linkops echo link x >> linkops comment comment This step appends the current link results to the cumulative file. comment echo i mtomout >> linkops echo o !outputfile,append >> linkops echo e >> linkops while finfo('mtomlnk','eof') > 0 setjcw cierror 0 continue run suprtool.pub.robelle;parm=36;info="u linkops" >> mtomlog if cierror <> 0 then echo Suprtool encountered a serious error. Please see mtomlog. escape endif setvar rec_left finfo('mtomlnk','eof') echo There are !rec_left record(s) left to process. endwhile comment comment This step sorts the final file and displays its comment content on the screen. comment setvar multi_eof finfo("!outputfile","eof") echo The output file, !outputfile, contains !multi_eof entries. echo i !outputfile > linkfin echo use mtomsort >> linkfin echo o=input >> linkfin echo e >> linkfin setjcw cierror 0 continue run suprtool.pub.robelle;parm=36;info="u linkfin" >> logfile if cierror <> 0 then echo Suprtool encountered a serious error. Please see mtomlog. escape endif