Sorry, but you have to read some basic documents (at least help) about script logic.
No space between "*" and statement!
*SELECT can't be used inside *FOR/*NEXT
* FOR% TP =%%% TIME_SET - absolutely strange!
*COMMIT is useless here
etc...
Please read also: How To: Ask questions about Script Logic issues
to clearly explain your requirements.