SAP GUI Connection Problem

Hi all!

I am just facing a problem with a SAP GUI script. I can see all server online and I can log in manually without any problem at any time. But the script sometimes fails in the BPM to reply and generate an error (95% OK, 5% NOK). The errors occurs always at the beginning when calling the function sapgui_open_connection_ex

This is an example of the output log:

Action.c(16): Error: Failed to open new connection to server "pw0.appld0"
Action.c(16): Error: Failed to get active window
Action.c(16): Error: Failed to find SapGui component by ID "sbar"
Action.c(16): Error: Failed to get the status bar text
Action.c(16): Error: Failed to get active window
Abort was called from an action.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.

I am trying to catch this error to do a connection retry directly in the script. But in these cases the SAP-GUI client generate an abort that triggers vugen_end anyway.  Code Snippet:

		i  ;
		lr_output_message ("Counter %d", i);	
	while ((RC!=LR_PASS)&&(i<=3));

Screenshot from Vugen attached (please notice, I put extra a wrong server for testing purposes). 

Thanks for any suggestion or help you can give!