just put define stream command to external procedure, run it, at the end of execution stream will be deleted.
<code>
OUTPUT TO VALUE(tblprocname).
put unformatted "/* Dump procedure for " tblname " */" skip.
put unformatted "/* " tblprocname " - created " TODAY " " STRING(TIME,"HH:MM:SS") " by " PROGRAM-NAME(1) " */" skip.
put unformatted " " skip.
put unformatted "define input parameter dumpfile as character. " skip.
put unformatted " " skip.
put unformatted "define variable i as integer." skip.
put unformatted "define stream outfile." skip(1).
find first _File where _File._File-Name = tblname NO-LOCK NO-ERROR.
if NOT available _File then
do:
put unformatted 'message STRING(TIME, "HH:MM:SS") ' + "Error. Table not found " + tblname' skip.
OUTPUT CLOSE.
RETURN "ERROR".
end.
put unformatted 'message STRING(TIME, "HH:MM:SS") ' + '"Dumping ' + _File._File-Name + ' ...".' skip.
put unformatted "i = 0." skip.
put unformatted "run src/cr_dir.p (dumpfile)." skip.
put unformatted "output stream outfile to value(dumpfile)." skip.
put unformatted "for each " + _File._File-Name + " no-lock:" skip.
put unformatted " export stream outfile" skip.
for each _Field OF _File NO-LOCK:
if _Field._Extent = ? OR _Field._Extent = 0 then
do:
put unformatted " " _File._File-Name + "." + _Field._Field-Name skip.
end.
else do:
do i = 1 to _Field._Extent :
put unformatted " " _File._File-Name + "." + _Field._Field-Name + "[" + STRING(i) + "]" skip.
end.
end.
end.
put unformatted " ." skip.
put unformatted " i = i + 1." skip.
put unformatted " if i MODULO 10000 = 0 then" skip.
put unformatted ' message STRING(TIME, "HH:MM:SS") ' + '"Processed "' + ' i "records".' skip.
put unformatted "end." skip.
put unformatted "output stream outfile close." skip.
put unformatted 'message STRING(TIME, "HH:MM:SS") ' + '"Total dumped "' + ' i "records".' skip.
put unformatted "if i = 0 then os-delete value(dumpfile)." skip.
OUTPUT CLOSE.
</code>