It does not make sense to put CTL-D inside a script file for purposes of exiting the script. As previously suggested, use "exit".
If you want to enter CTL-D into the file, using vi, just use CTL-V CTL-D sequence.
When a program is receiving input from stdin, you can enter CTL-D at the beginning of a line to signal "end of file". I think that's what you're getting mixed up. "end of file" for a Unix file is just signaled by end of file (no more content), period. Putting CTL-D in the middle of the file does not signal "end of file". You can verify with a test. Put CTL-D somewhere toward the top of the file, and cat the file. The whole file is shown, not just the part before the CTL-D.
Can you tell us what exactly you are trying to do?
If you are trying to instruct a script to handle certain task while it is already running, then you can use trap to catch a user-defined signal and perform an action.
For example, here is a script:
#!/bin/ksh
while :
do
trap "echo Date: $(date)" USR1
echo "Sleeping for 5 seconds..."
sleep 5
done
If you run this script on a session and from another session if you send a USR1 signal to the running script PID, the trap argument will be executed:
kill -USR1 <PID>
Modify it as per your requirement. I hope this helps.