It's not surprising that this UDF is slow, since you force a row by row processing.
HANA cannot know what you do inside of your function or how to rewrite it to set operations.
To have this update run faster you may put the update logic into a single statement instead of a function.
If absolute speed is key here, you may even use two separate update statements, one for each branch of your update logic.