After this follow step 4.
And it should execute for each Server Round Trip.
So write this code in DO_PREPARE_OUTPUT() but this this execute for every Server Round Trip, that is not good programming.
Am not sure about this, but one more way is there,
Create an event and place this code in that event.
Create one button on screen and assign this event to that button.
Now on clicking of that button it will fill context node attribute ie. ext_locno.