korn shell for loops with expect issue

Hi I have the following Korn script having multiple for loops.

#!/bin/ksh
EXPECT=/usr/local/bin/expect
exp_internal
for d in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 i22 23 24 25 26; do
for i in 01 02 03 04 05 06 07 ; do
for h in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ; do
for m in 00 30; do
for ent in nic board area ; do
$EXPECT << DONE
set stty_init raw
spawn dbisql -c \"uid=dc\;pwd=dc\" -host 100.120.11.5 -port 2640 -nogui
expect ">"
send "insert into DC_RAW_01 \(name, OS_ID, FDN, ENTRY, STATUS, Activation, Update, SelfDeactivation, CompletedActiv
ation,TimeoutDeactivation,IdleTimeoutDeactivation,CompletedUpdate, DATETIME_ID\) values (\'A$i\',\'Lin1\',\Doc,fix,A$i\',\'$ent\',\'UP\',
 4500, 8000, 15000, 1800, 12000, 17000, \'2012-06-$d $h:$m:00\'\)\r"
expect eof
close $fp
DONE
done
done
done
done
done

Issue is when script runs for purpose of Insert statement, each time it runs spawn also, slowing down script execution. I have tried re-arraging for loops and spanw placing but have had no luck so far. Anyone see how to remove spawn after initial loop?

How about this:

#!/bin/ksh
EXPECT=/usr/local/bin/expect
exp_internal
(
cat << EOF
set stty_init raw
spawn dbisql -c \"uid=dc\;pwd=dc\" -host 100.120.11.5 -port 2640 -nogui
EOF
for d in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 i22 23 24 25 26; do
for i in 01 02 03 04 05 06 07 ; do
for h in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ; do
for m in 00 30; do
for ent in nic board area ; do
cat << DONE
expect ">"
send "insert into DC_RAW_01 \(name, OS_ID, FDN, ENTRY, STATUS, Activation, Update, SelfDeactivation, CompletedActiv
ation,TimeoutDeactivation,IdleTimeoutDeactivation,CompletedUpdate, DATETIME_ID\) values (\'A$i\',\'Lin1\',\Doc,fix,A$i\',\'$ent\',\'UP\',
 4500, 8000, 15000, 1800, 12000, 17000, \'2012-06-$d $h:$m:00\'\)\r"
DONE
done
done
done
done
done
echo close $fp ) | $EXPECT

This works a treat. 3 times faster now.
Thank you.