Issues with exit after running jobs in background

I have the following sample script to run a script the jobs with the same
priority(in this case field3) in parallel; wait for the jobs to finish
and run the next set of jobs in parallel.When all the lines are read
exit the script.
I have the following script which is doing evrything I want to, but the
script does not exit after completing all the jobs.
Would appreciate any input as to why the script doesnt exit

#!/bin/ksh

a=1

cat abc.txt | while read field1 field2 field3

do

F1=$field1
F2=$field2
priority=$field3

if[[ $priority -eq $a ]] ; then

 run\_some_job.ksh - $F1 -$F2 $F3&

else
wait
a=`expr $a + 1`
fi

done

exit

According to the ksh man page: "Waits for the specified job and report its termination status. If job is not given then all currently active child processes are waited for."

My feeling is that you have a child process to operate your loop. Then your wait statement inside the loop is actually waiting for the loop to terminate. Put a "ps -f" in front of the "wait" to see what you are waiting for.

You may eliminate the child process by losing your UUOC.

Instead of:
cat file | while read ; do
done

Try:
exec < file
while read ; do
done

or try:
while read ; do
done < file