Mighty, I was expecting an example with some sort of data.
We have Response in which address are returned.
From where do u receive this RESPONSE,do you call a module and it returns certain value,where it gets stored?So,for each RESPONSE u have a single address and an associated level number or multiple addresses.
When do u finally go for writing into the file?
Mighty,with the information that you have provided, i can suggest you to use two working storage variables to store address and level number. Every time after u receive the response compare the current level number value with the previous one.If it is greater then replace both (the address and the level number )else continue.
At the end of the cycle move the address from the variable into the file.