Nathan Hands' Blog

UI5 applications consultant, entrepreneur, fantasy book lover and gamer

How to login to SAP using a single command in SAP IRPA

1 month ago · 2 MIN READ
#IRPA  #tutorial 

Introduction

I'm currently working on some SAP automations that are being adjusted to working in 'unattended' mode, which wasn't a very large shift for my work except for one common problem.

The problem is that unattended mode seems unable to process the 'click' command for a UI Automation, this seems to also effect keyboard usage as well as double clicks and possibly more.

Note This is especially frustrating as it will work in debug mode or unattended mode if your screen is unlocked and viewable, however in my instance this will be on a citrix server and so a user will not often be connected to the other end. This seems to be why the automation is unable to click/ send keyboard commands as it simulates user interaction with UI Automations which seems to fall over in this scenario.

How does the UI automation look?

The automated logging into SAP is rather straight forward via a UI automation, I won't document this here because this has been documented at length in multiple blogs such as over here.

Without following that link though our end result for logging into SAP looks something like this:

sap irpa login.PNG

Simple, effective and it works like a charm unless you want to run on an unattended citrix session as in that case it entirely falls apart.

introducing sapshcut

sapshcut.exe is a small little exe that comes with the installation of the SAP GUI. Sapshcut can log us into SAP via a single string command, as well as take us to a desired transaction if we'd like. This makes our job infinitely easier and honestly more robust as I've found the UI automation can be difficult to work with at times where as program access will always work.

How does this look?

sap login custom 2.PNG

We simply add a 'custom' activity and carry on as normal, this custom activity can then contain the code to execute sapshcut.exe and login to SAP.

How does the code look?

// ----------------------------------------------------------------
//   Step: Login_to_SAP
// ----------------------------------------------------------------
GLOBAL.step({ Login_to_SAP: function(ev, sc, st) {
    var rootData = sc.data;
    ctx.workflow('sapshcut logon', 'be1c77ff-e2dd-4939-a95e-1cdf6b433582') ;
    // Login to SAP
    var sSAPId = 'DEV' //SID of the SAP system to connect to
    var sClient = '100' //Client of the SAP system to logon to
    var sUsername = '' //Username for the SAP system
    var sPassword = '' //Password for the SAP system
    var sExecute = 'sapshcut.exe -sid=' + sSAPId + ' -client=' + sClient + ' -u=' + sUsername + ' -pw=' + sPassword + ' -l=EN -max';
    ctx.execRun(sExecute, 1, true);
    sc.endStep(); // pSAPEasyAccessU_manag_1
    return;
}});

Conclusion

Success! we've now replaced our UI automation with the sapshcut command and we can login to SAP without using any UI automation which has got us around the lack of ability to click.

If you have other applications that require clicking in a UI automation I don't currently know how you can get around those, these might simply need to be 'attended' bots or ran on systems that don't lock and are 'always on' or at least unlock for the scheduled times.

If you know any other approaches to this problem feel free to mention them in the comments! I got this problem and solved it within the day and then wrote up this post to hopefully save someone else the trouble.

···

Nathan Hand

SAP Applications consultant working as a UI5 developer, Lover of automation, technology, fantasy books & games.
comments powered by Disqus


Proudly powered by Canvas · Sign In