i am running this code 31 times using another REXX program. For the First run it gives " FILE INPUT NOT UNALLOCATED, DATA SET IS OPEN "
and the file gets created by no data and the rest 30 files are created with correct and properly data.

No, from the calling program i am processesing another dataset and from that i am retrieving relevant data. And then i am calling the above program with those relevant data i am creating the new datasets using the input dataset.

While in the whole process the error is coming when i am allocating "ALLOC DA('"DATASET"') F(INPUT) SHR REUSE" for the first time only rest 30 loops are running fine and all new datasets are created with proper data.