Hello,
This is my first raised question to the community.
I've just very recently found out that it is possible to record steps in SAP and save them to a vb file.
At the same time I also found out that, you can use an adapted code e.g. inside a VBA excel file and run it to create the same behavior as if you were pressing the run command in SAP for such a stored script.
This was a big thing to me because working in SAP and to have any possible interaction to it from the "outside" would be a mind changer.
I've since searched and searched for a way to create my interaction outside the VBA IDE and to use Visual Studio to run my code. So far, it was impossible to me to have it working. Errors after errors.
My question at this point, without having to keep spending time is simple: Can I assume this is even possible? Use a VS application to run C# or VB.NET to do the simplest thing like run a transaction in SAP from the outside?
I use Windows 10 - 64 bit and the SAP GUI for Windows release 7600.1.9.1160.
If anyone could provide me the feedback, I could then build up my knowledge and start asking step by step questions.
I have absolutely no knowledge about this topic. I'm familiar with C# and just a small bit on VB.NET, so, any gain from this point is a benefit. To be honest, there should be a lot of other people in the same conditions.
Please let me have your precious feedback.
Many thanks in advance.
Regards
Request clarification before answering.
ptuga
Hello Pedro,
you can find answers to suppress the security message here and here.
To automize more you can use this approach:
'-Begin-----------------------------------------------------------------
Imports System
Imports Microsoft.VisualBasic
Public Module SAPGUIScripting
Sub Main()
Dim SapGuiAuto As Object
Dim app As Object
Dim connection As Object
Dim session As Object
Try
SapGuiAuto = CreateObject("Sapgui.ScriptingCtrl.1")
app = SapGuiAuto.GetScriptingEngine
app.HistoryEnabled = False
connection = app.OpenConnection("C11", True)
If connection.DisabledByServer = True Then
Exit Sub
End If
session = connection.Children(0)
If session.Info.IsLowSpeedConnection = True Then
Exit Sub
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
Exit Sub
End Try
'>Insert your SAP GUI Scripting code here<
app.HistoryEnabled = True
End Sub
End Module
'-End-------------------------------------------------------------------
But this approach is only available at x86 platform. With Sapgui.ScriptingCtrl.1 object and method OpenConnection it is possible to start direct the SAP session.
Do you have an example transaction which opens Excel instead of downloading?
Best regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan,
Thank you for the feedback.
When you refer to "only available at x86 platform." I presume you mean Windows and that 64 bit Windows will not work with this code. Is this correct?
I've tried to run the code but when you reach to 'Connection = app.OpenConnection("C11", True)' it fails and the console shows a "SAP Logon connection entry not found" message even if SAP Logon 760 window is available. This might be cause by what you described on your comment?
We use several that allow an export to Excel, e.g. CS11, VA05 but I thought these could be very specific for the company rather than generic. In these cases, the Excel file is created and Excel is lunched to show the file. Just saving the file would be preferable.
Another point that I've been experiencing with the exports is the fact that the transaction code runs and finishes and the file has not yet been created/finalised. Because I'm running the SAP transaction/interfacing code on an external console app (VBdotNet), there is no way for my main application (Windows form in C#) to know exactly that the Excel file is ready. It seems that the SAP export does not wait until the Excel process is finished. It might run on a different thread, I suppose. The only way round this was for me to wait using a Thread.Sleep(ms) but if the export takes longer I'll run into trouble. My perception can also be wrong and something else is happening.
To finalise for today, I would like to ask, if it is possible to bring the SAP Easy Access window to the main screen with no other internal windows opened. Sometimes if a script fails, you are not starting from the initial main window screen and the scrip fails. Is there any workaround for this. You can press back (sendkey) several times and even if it works on most cases (not in all), seems very rudimentary.
I'll go through the security settings over the weekend and will let you know.
In the meanwhile, please feedback on the remaining topics.
Many thanks.
Kind regards,
Pedro
ptuga
Hello Pedro,
x86 platform means that you must compile your code with the x86 switch. It runs on 64-bit Windows, but it is an x86 application.
Instead of string C11 you must use your system description from the logon to start the correct connection. Please take a look at the SAP GUI Scripting help.
The FM XML_EXPORT_DIALOG contains an input parameter I_APPLICATION, if a related application can be detected it will be opened. Method GET_PC_APPLICATION from class CL_SALV_GUI_DATA_PUBLISHER do that, but I don't see a switch. I don't know a way around displaying the Excel file.
In my opinion you can check if the file exists and if you can add an additional file to it, Excel xlsx is a ZIP file. If this is possible it is probable that the download is complete.
Kill your SAP Logon and restart it, I know, this is radical but this step creates the desired conditions for you
Best regards
Stefan
Hi Stefan,
Sorry for the long delay in my answer.
I'm an autodidact and sometimes can take a while until I find free time to look at none professional topics.
I'll try to compile an application in 32 bit to check what you mean. But for that I need the "system description" you mentioned.
The access to any help scripting seems to be only here:
file:///C:/Program%20Files%20(x86)/SAP/FrontEnd/sapgui/sapguihelp/EndUserHelp/EN/7ddb7c9c4a4c43219a65eee4ca8db001.html
But there is not a lot of info. Is there a link to show me the tips you mentioned?
The "system description" is likely to be a company/user specific thing, right?
Can I check this details after I login manually and look at a dialog?
Regarding the other topic, I need some extra investigation to reach a more accurate conclusion. In any case I appreciate your tips.
Now that I'm closer to a summer break I might have a bit more time for some reading.
You mentioned at the beginning of this ticket a dotNET Connector (NCo). For a starter, and for who would like to know a bit more, what do you recommend?
There are so many questions ... do we have the software in my machine? Where can I read about the topic and look for some examples?
You also mentioned "to automize via API, remote enabled function calls". What does this mean? Can I use VS and create VBdotNet apps to interact with SAP without the SAP GUI in between?
Can you provide me any details?
I believe I'm still at 0.1 level 😄 (I would like to step up a bit)
Thank you.
Kind regards,
Pedro
ptuga
Hello Pedro,
you can find more information about the system description in the SAP GUI Scripting help in the GuiApplication object, method OpenConnection. If you use method OpenConnectionByConnectionString, you can find all the parameters you need in your SAP Logon.
You can find all information you need about SAP dotNET Connector (NCo) in the support portal. The x86 version of NCo is part of the current SAP GUI for Windows installation. The NCo offers the possibility to communicate with the SAP backend system via remote enabled function calls (RFC). Yes, with NCo you can create VBdotNET apps to interact with SAP without the SAP GUI for Windows. You can find a few information in the Overview document.
Hope this answers your questions.
Best regards
Stefan
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.