You need to define a linecounter and a pagecounter in working-storage. For the first line written and every n
lines written, you need to write the "page heading with the page#, increment the pagecounter, and zero the linecounter. You would increment the linecounter each time you write a line.
Pleased if some one provide the code.
We will help you work on your code, but will not do the work for you. If someone (other than you) posts a whole solution, it will be deleted.