Dear Alexey Maslove

n fileno,seq,resfile,ind,ind2,seq2
s resfile=""
s ind="" f  s ind=$o(^ztonEDI("TXT","OUT-DATA",ind)) q:$g(ind)=""  d
.s fileno="" f  s fileno=$o(^ztonEDI("TXT","OUT-DATA",ind,fileno)) q:$g(fileno)=""  d
..s resfile="/Flatfile/"_fileno_".txt"
..o resfile:"RSK\CP874\"
..u resfile
..s seq="" f  s seq=$o(^ztonEDI("TXT","OUT-DATA",ind,fileno,"SEQ",seq)) q:$g(seq)=""  d
...w $g(^ztonEDI("TXT","OUT-DATA",ind,fileno,"SEQ",seq))_$c(13),$c(10)
..c resfile
.k ^ztonEDI("TXT","OUT-DATA",ind)
q