Few things I noticed is the use of shell() commands. You are hard-coding the OS commands into Baan code, instead of using the available tools functions. Refer to the Programmer's manual - Directory and file operations synopsis
You can replace all the cp, mv, rm commands by file.cp(), file.mv() and file.rm() which are platform independent.
ls.path.name = "ls " & strip$(path.input.o) &" > " & strip$(path.log.o) & "/CSCN_ASN_files"
ret = shell(ls.path.name, 0)
Refer to the thread for the sample code to read the files in the directory - reading Ascii file
The script does need some code clean up to use arrays, coding standards etc.
if not valid.asn.file.new() then
err.hap = tcyesno.yes
The file pointer should be closed before the 1st return. The other statement will fail in case of duplicate records, missing db.skip.dupl option.