Batch files were never intended to do what you are requesting. In general they just run a series of commands that you could just as easily have typed at the command prompt. Branching and decision making in a batch file is fairly primitive.
One good language for DOS is REXX. REXX runs on everything from mainframes, DOS, Windows, and Linux. The best part is that it's free.
REXX is easy to learn, can read records from a file, manipulate the data and produce formatted output. You can run DOS commands and other programs from within REXX. REXX also has specialized function libraries (download separately) for database access, system functions, high-level math, and communications.
You can download REXX from:
http://kilowattsoftware.com/r4page.htmIf you need any REXX libraries try this site:
http://www.borg.com/~jglatt/rexx/win32/rxusrw32.htmGood luck.