alternatively, you can look for AK3 or AK4 -- then you would know you had a rejected transaction.
Otherwise, here's a sample of some 'rudimentary' code I use on a daily basis. There may be an easier way, but I'm sorta new to Procomm. You'll have to tweak it for your use:
integer FileCounter = 0, Len = 0
string FileSpec, LineBuffer, sFullPath, sString, sFileRename, sLogFile, sWriteString
proc main
strcpy sLogFile s0
strcat sLogFile "\IN\logfile.txt"
if fopen 1 sLogFile CREATE TEXT
strcpy FileSpec s0
strcat FileSpec "\IN\mail*"
if findfirst FileSpec ; Find first file matching spec.
FileCounter++
strcpy sFullPath s0
strcat sFullPath "\IN\"
strcat sFullPath $FILENAME
strcpy sFileRename s0
strcat sFileRename "\IN\"
if fopen 0 sFullPath READ TEXT
fgets 0 LineBuffer
substr sString LineBuffer 1 2
if strfind LineBuffer "~ST*997"
strcat sFileRename "997."
call RenameFile
else
if strfind LineBuffer "~ST*835"
strcat sFileRename "835."
call RenameFile
else
if strcmp sString " H"
strcat sFileRename "ACK."
call RenameFile
else
fgets 0 LineBuffer
if strfind LineBuffer "submission id"
strcat sFileRename "TRANS."
call RenameFile
else
strcat sFileRename "NSF."
call RenameFile
endif
endif
endif
endif
endif
while findnext ; Loop while still finding files.
strcpy sFullPath s0
strcat sFullPath "\IN\"
strcat sFullPath $FILENAME
strcpy sFileRename s0
strcat sFileRename "\IN\"
if fopen 0 sFullPath READ TEXT
fgets 0 LineBuffer
substr sString LineBuffer 1 2
if strfind LineBuffer "~ST*997"
strcat sFileRename "997."
call RenameFile
else
if strfind LineBuffer "~ST*835"
strcat sFileRename "835."
call RenameFile
else
if strcmp sString " H"
strcat sFileRename "ACK."
call RenameFile
else
fgets 0 LineBuffer
if strfind LineBuffer "submission id"
strcat sFileRename "TRANS."
call RenameFile
else
strcat sFileRename "NSF."
call RenameFile
endif
endif
endif
endif
endif
FileCounter++
endwhile
endif
fclose 1
endif
pwexit
endproc
proc RenameFile
strcat sFileRename $FILENAME
strcat sFileRename ".txt"
fclose 0
rename sFullPath sFileRename
strcpy sWriteString sFullPath
strcat sWriteString " "
strcat sWriteString sFileRename
strlen sWriteString Len
fputs 1 sWriteString
endproc