What is the total number of records in COSS and COSP ?
If you have million ranges data and use some other variable/input parameter with it ( like Customer, Material , or GL_ACCOUNT ) , you still might get acceptable performance.
Now 'acceptable' can mean many things .
"Nested IF " is not working, because, at row number 1, you do not have value for row number 2. So, V1 is getting added to null ( for V2) and so on .
Updated blog post with SQL approach and run time .
Regards
Anindya