Hello,
Urmmmm, Vishwa, you want to remove duplicates and sort the i/p file, and that is it, right; and maybe have the sorted record in one file with duplicates in another (because of the usage of LASTDUP)???
If the requirement is to simply sort the file, remove the duplicates, and have them written somewhere, then maybe this SELECT can help you:
SELECT FROM(IN) TO(OUT) ON(17,8,CH) ALLDUPS DISCARD(DUPS) <-- this is considering the i/p to be VB
Your JCL will have another DD statement, with a DS for 'DUPS'.