Recent

Author Topic: SAPGUI Scripting - Connection in Lazarus/FPC  (Read 7177 times)

kusana

  • New member
  • *
  • Posts: 8
SAPGUI Scripting - Connection in Lazarus/FPC
« on: May 12, 2016, 10:02:19 pm »
Hello,
I need to pilot SAPGUI from my own Lazarus app using the SAPGUI Scripting interface.

I've found a similar help request on the SAP forum, but unfortunatly there is no answer: https://scn.sap.com/thread/2137793

Using VB.net I can connect to SAPGUI with a few lines of VB code:

Imports SAPFEWSELib 'import SAPGUI Scripting library
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim sapguiauto As Object = GetObject("SAPGUI") 'create activex object
        Dim application As GuiApplication = sapguiauto.getscriptingengine 'get scripting engine
        Dim connection As GuiConnection = application.Children(0) 'get first connection
        Dim session As GuiSession = connection.Children(0) ' get first session
        session.FindById("wnd[0]/tbar[0]/okcd").text = "IW23" 'select transaction IW23
        session.FindById("wnd[0]").sendvkey(0) 'send return key
        session.FindById("wnd[0]/usr/ctxtRIWO00-QMNUM").text = "91013157" 'feed additional data
        session.FindById("wnd[0]").sendvkey(0) 'send return key
    End Sub
End Class

It would be nice if someone could convert these few lines of VB code to FPC/Lazarus code.

I've already imported SAPFEWSELib from "c:\program files\sap\frontend\sapgui\sapfewse.ocx", but I'm not able to create the ActiveX object properly.

Within "sapfewselib_1_0_tlb.pas" converted file I find:
  TEvsGuiSession = Class(TEventSink)   and    TEvsGuiApplication = Class(TEventSink)

Thank you in advance for your help.

kusana

  • New member
  • *
  • Posts: 8
Re: SAPGUI Scripting - Connection in Lazarus/FPC
« Reply #1 on: May 27, 2016, 10:58:45 am »
Finally I managed to write the following piece of Lazarus/FPC code to control an active session:
 
uses
  ..., saprotwr_1_0_tlb, sapfewselib_1_0_tlb;
 
var
  MySapROTWrapper: ISapROTWrapper;
  MySapROTEntry: _Dsapfewse;
  MyGuiApplication: GuiApplication;
  MyGuiConnection: GuiConnection;
  MyGuiSession: GuiSession;
  MyGuiFrameWindow: GuiFrameWindow;
begin
  MySapROTWrapper := CoCSapROTWrapper.Create;
  MySapROTEntry := _Dsapfewse(MySapROTWrapper.GetROTEntry('SAPGUI'));
  MyGuiApplication := GuiApplication(MySapROTEntry.GetScriptingEngine);
  MyGuiConnection := GuiConnection(MyGuiApplication.Children.Item(0));
  MyGuiSession := GuiSession(MyGuiConnection.Children.Item(0));
  MyGuiFrameWindow := GuiFrameWindow(MyGuiSession.Children.Item(0));
 
  GuiTextField(MyGuiFrameWindow.findById('wnd[0]/tbar[0]/okcd', GuiTextField_)).Text_ := 'my transaction here';
  MyGuiFrameWindow.SendVKey(0);
  GuiTextField(MyGuiFrameWindow.findById('wnd[0]/usr/text field id here', GuiTextField_)).Text_ := 'text data';
  MyGuiFrameWindow.SendVKey(0);
...
 
and so on.

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: SAPGUI Scripting - Connection in Lazarus/FPC
« Reply #2 on: December 29, 2016, 10:57:32 am »
Thank Kusana, i don´t know how to use it but it is very interesting thing interact with SAP.
Works with an active session directly? Can it be used to extract obtained data of SAP?

Can you write a little practical tutorial with simple steps?
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

 

TinyPortal © 2005-2018