On ME21N, I have designed two screens, the layout of which is controlled by one variable V[z_me21n_first]. If it is 'blank', screen one is shown and if it is "no", the second screen comes up. When I click the "Personal Settings" (/25) button, the variable becomes blank, and the control is taken to screen one. What could be the reason?

The reason is probably that if you have a Screen S with a popup P, both the script for S and then the script for P will be processed. This is necessary since SAP GUI rebuilds both screens using the protocol. Without the GuiXT script being active for the underlying screen S, you would see the unmodified SAP layout in the background.

For layout changes this is okay, but in some cases variables should only be set if there is no popup active. In order to exclude cases where a popup is active you can use the if-statement:

if not Q[InactiveScreen]