apjohn1986 wrote:... The return code i am getting is -23.
Before writing a file, i have verified that whether it is already present. if so, i have deallocate and free the file and then write it. FREE command is working fine after deallocation. but its not working after closing a file.
You may have an issue with terminology. "Freeing" an allocation is the same as deallocating the allocation. What method are you using to determine if the data set is allocated?
For that matter, the spell check in Google Chrome claims "deallocation" or "deallocate" is not valid, though I use the word myself.
If you think about it, it is not too terribly important if the data set is allocated to your job when you start this sequence; what is probably more important is if the DD name you intend to use is is already allocated to your job. Then you have to free the DD name, not the data set. Similarly, when you allocate the data set you are - I hope - using ALLOCATE FILE(xxx) DSN('the data set'). Once you have done this, just free the DD name - use FREE FILE(xxx). I'm not a Cobol programmer; I use Assembler almost exclusively, so I do not use BPXWDYN. I have been using dynamic allocation, either TSO dynamic allocation before MVS, or MVS dynamic allocation. I generally do not specify a DD name in the allocation; I have allocation return the DD name it created for the allocation to me, and then use and free the DD name created by allocation. I use FRE DSN as a TSO command, but I can't recall that I have ever used FREE DSN as a direct use of dynamic allocation.
Does the documentation for BPXWDYN tell you what RC = -23 means?