This question, https://stackoverflow.com/q/26912463/1927206, is resolved by fixing two typos, the value tested for termination of loops was written in uppercase, but the value inserted to mark the last entry was in mixed-case. The last entry was also output to the file in error in another location.
However, the program itself needs a lot of work.
The coding of the solution chosen can be improved on (better use of names, types), improved upon by reversing the driving table, and perhaps completely re-written with a sequential matching algorithm (two file match) if that is appropriate to the task.
Getting all the required information from the OP would be discursive at best, which doesn't fit with the Q&A, and would also presume that the OP attends before asking another question.
OP has also posted an answer revealing the second issue (not included in the code in the question).
So, do I write an answer: suggesting improvement to the existing code?; suggesting a better implementation of the chosen solution?; suggesting a re-write, which may not fit with OP's situation?
Or vote to close, flag the answer as Not An Answer (that'll be fun getting it accepted) and hope the thing gets deleted?; or something else?
In my Main Section I was also performing 'write-mismtch' s
read asneeded code to answer was not shown
?. I'm not familiar with cobol.... must include ....
?