Quantcast
Viewing all 100 articles
Browse latest View live

How to use SAP GUI Scripting with AutoIt Script

Hello community,

 

AutoIt is a powerful freeware scripting language with BASIC syntax. It is primarly designed for automating operations on the WindowsGUI. But it also provides a full set of commands to use it as programming language. It is possible to build GUI applications and to create standalone executables. You find AutoIt here.

 

AutoIt offers, beside the ability to use DLL calls, a COM interface. With these interface it is possible to use SAP GUI Scripting inside AutoIt. You can take the code from the SAP GUI Scripting recorder, itonly hasa $ signbeforethe session variableto be set.

 

Here an AutoIt Script example to login:


;-Begin-----------------------------------------------------------------

 

  ;-Variables-----------------------------------------------------------
    Dim $SAPROT, $SapGuiAuto, $application, $connection, $session

 

  $SAPROT = ObjCreate("SapROTWr.SAPROTWrapper")
  If Not IsObj($SAPROT) Then
    Exit
  EndIf

 

  $SapGuiAuto = $SAPROT.GetROTEntry("SAPGUI")
  If Not IsObj($SapGuiAuto) Then
    Exit
  EndIf

 

  $application = $SapGuiAuto.GetScriptingEngine()
  If Not IsObj($application) Then
    Exit
  EndIf

 

  $connection = $application.Children(0)
  If Not IsObj($connection) Then
    Exit
  EndIf

 

  $session = $connection.Children(0)
  If Not IsObj($session) Then
    Exit
  EndIf

 

$session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "099"
$session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "Hugo"
$session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "Bambi"
$session.findById("wnd[0]/usr/txtRSYST-LANGU").text = "DE"
$session.findById("wnd[0]/tbar[0]/btn[0]").press()

 

;-End-------------------------------------------------------------------

 

Good scripting.

Cheers

Stefan


SendKeys from VBA to a session window

Hello community,

 

in context of the posting from mic jones here I check different ways of SendKey from an Excel VBA application to a session window.

 

At first I identfiy the handle of the session window and set it in foreground with the following code

 

Private Declare Function SetForegroundWindow Lib "user32.dll" _

  (ByVal hWnd As Long) As Long

 

hWnd = Session.ActiveWindow.Handle
SetForegroundWindow hWnd

 

After that I use different methods of SendKeys:

 

  1. Standard VBA SendKeys, but it doesn't work.

    SendKeys "+{DOWN}", True
  2. SendKeys via SendMessage, but it doesn't work.

    Private Declare Function SendMessageA Lib "user32.dll" _
      (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long

    SendMessageA hWnd, &H100, vbKeyShift, 0
    SendMessageA hWnd, &H100, vbKeyDown, 0
    SendMessageA hWnd, &H101, vbKeyDown, 0
    SendMessageA hWnd, &H101, vbKeyShift, 0
    DoEvents
  3. SendKeys via keybd_event, but it doesn't work.

    Private Declare Sub keybd_event Lib "user32.dll" _
      (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

    keybd_event &H10, 0, 0, 0
    keybd_event &H28, 0, 0, 0
    keybd_event &H28, 0, 2, 0
    keybd_event &H10, 0, 2, 0
  4. SendKeys via Windows Scripting Host and this works very fine.

    Dim wsh As WshShell
    Set wsh = CreateObject("WScript.Shell")
    wsh.SendKeys "+{DOWN}"

Maybe someone can use this information or show different ways.

 

Cheers

Stefan

How to use SAPInfo Control module inside SAP GUI Scripting

Hello community,

 

SAP offers an information control module with the SAP GUI for Windows, called SapInfo OLE Control Module. The filename of the module is sapfewin.ocx and the class name is Sapgui.InfoCtrl.1. This module contains a few functions to get some information, e.g. the Windows system path, the temporary directory, the desktop directory and and and... Often the functions are equivalent to the Windows API functions. In some cases it could be very helpful to know, that this library with this possibilities exists. On the one hand it is possible to use it inside your ABAP code and on the other hand it is possible to use it with SAP GUI Scripting. In the following VBS code I will demonstrate how to use some functions of the SapInfo OLE Conrol Module.


'-Begin-----------------------------------------------------------------

  '-Directives----------------------------------------------------------
    Option Explicit

  '-Sub Main------------------------------------------------------------
    Sub Main()

      '-Variables-------------------------------------------------------
        Dim SAPInfo, strResult, numResult

      Set SAPInfo = CreateObject("Sapgui.InfoCtrl.1")
      If IsObject(SAPInfo) Then

        SAPInfo.AboutBox

        strResult = SAPInfo.GetWindowsDirectory()
        MsgBox strResult, vbOkOnly, "Windows directory"

        strResult = SAPInfo.GetSystemDirectory()
        MsgBox strResult, vbOkOnly, "System directory"

        strResult = SAPInfo.GetComputerName()
        MsgBox strResult, vbOkOnly, "Name of the computer"

        strResult = SAPInfo.GetUserName()
        MsgBox strResult, vbOkOnly, "Name of the user"

        strResult = SAPInfo.GetWindowsVersion()
        MsgBox strResult, vbOkOnly, "Windows version"

        strResult = SAPInfo.GetTempPath()
        MsgBox strResult, vbOkOnly, "Path for temporary files"

        strResult = SAPInfo.GetDesktopDirectory()
        MsgBox strResult, vbOkOnly, "Desktop directory"

        strResult = SAPInfo.GetSapWorkDir()
        MsgBox strResult, vbOkOnly, "SAP Work Directory"

        numResult = SAPInfo.RegisterServer("C:\Dummy\Test.dll")
        MsgBox CStr(numResult), vbOkOnly, "Server registered?"

        numResult = SAPInfo.UnregisterServer("C:\Dummy\Test.dll")
        MsgBox CStr(numResult), vbOkOnly, "Server unregistered?"

        numResult = SAPInfo.MessageBox("MessageBox", "Title", 2, 2)
        MsgBox CStr(numResult), vbOkOnly, "MessageBox result"

        Set SAPInfo = Nothing
      End If

    End Sub

  '-Main----------------------------------------------------------------
    Main

'-End-------------------------------------------------------------------

 

Now the full list of all methods from the SAP Info Control Module

 

Call AboutBox ()

Call BrowseForFolder (Title As WString, InitDir As WString) As WString

Call ClipboardExport () As Integer

Call ClipboardImport () As Long

Call CreateDirectory (Directory As WString) As Integer

Call CreateScreenshot () As WString

Call DeleteFile (File As WString) As Integer

Call DeleteRegKey (Root As Integer, Key As WString) As Integer

Call DeleteRegValue (Root As Integer, Key As WString, _

  Value As WString) As Integer

Call DirectoryExists (DirectoryName As WString) As Long

Call DisableHistoryForField (field_name As WString, _

  disable_b As Integer) As Integer

Call Exec (CmdLine As WString, CmdShow As Long) As Integer

Call FileCopy (Source As WString, Destination As WString, _

  mode As Integer) As Integer

Call FileExists (file_name As WString) As Long

Call FileOpenDialog (Caption As WString, DefExt As WString, _

  File As WString, Filter As WString, InitDir As WString, _

  bMultiSelection As Integer) As Integer

Call FileOpenDialogEx (Caption As WString, DefExt As WString, _

  File As WString, Filter As WString, InitDir As WString, _

  bWithEncoding As Integer, multiselection As Integer) As Integer

Call FileSaveDialog (Caption As WString, DefExt As WString, _

  File As WString, Filter As WString, InitDir As WString) As WString

Call FileSaveDialogEx (Caption As WString, DefExt As WString, _

  File As WString, Filter As WString, InitDir As WString, _

  bWithEncoding As Integer, bOverwriteonprompt As Integer) As WString

Call GetComputerName() As WString

Call GetCurrentDirectory () As WString

Call GetDesktopDirectory () As WString

Call GetDownloadPath () As WString

Call GetDriveType (Drive As WString) As WString

Call GetEnvVariable (Variable As WString) As WString

Call GetFileAttribute (FileName As WString, Attribute As Integer) _

  As Integer

Call GetFileInfo (File As WString, Info As Integer) As WString

Call GetFileSize (File As WString) As Long

Call GetFreeSpaceForDrive (Drive As WString) As Long

Call GetFreeSpaceForDriveEx (lpDirectoryName As WString) As WString

Call GetFullPathName (File As WString) As WString

Call GetGuiFeatures () As WString

Call GetGuiVersion () As Long

Call GetIPAddress () As WString

Call GetPlatformEx () As Long

Call GetProfileString (File As WString, Section As WString, _

  Key As WString) As WString

Call GetProgramName () As WString

Call GetProgramPath () As WString

Call GetRegDWValueEx (Root As Integer, Key As WString, _

  Value As WString) As Long

Call GetRegValue (Root As Integer, Key As WString) As WString

Call GetRegValueEx (Root As Integer, Key As WString, Value As WString) _

  As WString

Call GetSapGUIDirectory () As WString

Call GetSapWorkDir () As WString

Call GetSystemDirectory () As WString

Call GetTempPath () As WString

Call GetUploadPath () As WString

Call GetUserName () As WString

Call GetWindowsBuildNumber () As WString

Call GetWindowsDirectory () As WString

Call GetWindowsPlatform () As WString

Call GetWindowsVersion () As WString

Call GetWindowsVersionEx () As WString

Call IsScriptingActive () As Long

Call IsTerminalServicesRunning () As Integer

Call ListFiles (Directory As WString, Filter As WString) As Integer

Call MessageBox (Text As WString, Caption As WString, Icon As Long, _

  Type As Long) As Long

Call RaiseScriptingEvent (params As WString) As WString

Call RegisterServer (Path As WString) As Long

Call RemoveDirectory (Directory As WString) As Integer

Call SetCurrentDirectory (Directory As WString) As Integer

Call SetEnvVariable (Variable As WString, Value As WString) As Integer

Call SetFileAttribute (FileName As WString, Normal As Integer, _

  ReadOnly As Integer, Hidden As Integer, Archive As Integer) As Integer

Call SetFileDateTime (FileName As WString, wYear As Integer, _

  wMonth As Integer, wDayOfWeek As Integer, wDay As Integer, _

  wHour As Integer, wMinute As Integer, wSecond As Integer) As Integer

Call SetProfileString (File As WString, Section As WString, _

  Key As WString, Value As WString) As Integer

Call SetRegDWValueEx (Root As Integer, Key As WString, _

  Value As WString, Data As Long) As Integer

Call SetRegValue (Root As Integer, Key As WString, Value As WString) _

  As Integer

Call SetRegValueEx (Root As Integer, Key As WString, Value As WString, _

  Data As WString) As Integer

Call SetTimer (Interval As Long) As Long

Call ShellExecute (Operation As WString, File As WString, _

  Parameters As WString, Directory As WString, ShowCmd As Long) As Long

Call ShellExecuteEx (Operation As WString, File As WString, _

  Parameters As WString, Directory As WString, ShowCmd As Long, _

  nSynchroneMode As Integer) As Long

Call ShowDocument (data_provider_URL As WString, data_length As Long, _

  document_name As WString, mime_type As WString, keep_file As Long) _

  As WString

Call UnregisterServer (Path As WString) As Long

Call WinHelp (HelpFile As WString, Command As Long, Data As Long) _

  As Integer

 

There are many interesting methods which can simplify programming.

 

Cheers

Stefan

SAP GUI Scripting in the Context of NetWeaver Business Client, a New Perspective

Hello community,

we see at the DSAG (German SAP User Group) the NetWeaver Business Client (NWBC) as replacement in the near future for the SAP GUI for Windows with the SAP Logon. From this point I considered the SAP GUI Scripting with NWBC for Desktop. At first I installed the NWBC 4.0 PL 4 and configured the application server. It runs well and I directed my attention to the SAP GUI Scripting.

 

First of all, it works. But there are some differences to SAP GUI Scripting inside SAP GUI for Windows.

 

1. If I open a second NWBC Client window and use the method Connections from the Application object with the property Count, I get not more than one connection. SAP GUI Scripting uses only the first NWBC Client window. Look here: http://scn.sap.com/thread/3323820

 

2. The correct entry in the running object table (ROT) for the SAP GUI Scripting inside NWBC is SAPGUISERVER.

 

3. If I record a SAP GUI Script with NWBC, it sets SapGuiAuto = GetObject("SAPGUI"). If I start this script from Windows Explorer, it runs in a normal SAP GUI for Windows session. I think it should be SapGuiAuto = GetObject("SAPGUISERVER"). Look here: http://scn.sap.com/thread/3325237, also for the next points.

 

4. In the NWBC is no Ok-Code-Field visible. It is possible to use it with SAP GUI Scripting because it is in the scripting object hierarchy, but it is not possible to record something with it in NWBC.

 

5. In the NWBC is no Toolbar[1] visible and not useable. Older SAP GUI Scripts will not work and there is no equivalent.

 

My momentary conclusion: SAP GUI Scripting in the context of NWBC offers not the same possibilities as in SAP GUI for Windows context now. We will see what will happen in the future development of NWBC in this sector, I am curious.

 

To be continued...

 

Cheers
Stefan

Use the VBA debugger to analyze SAP GUI Scripting objects at runtime


Hello community,

 

yesterday I discussed with a friend of mine about different methods of analyzing SAP GUI Scripting programs at runtime. One very easy method, to understand and to see where the attributes or methods are in the SAP GUI Scripting hierarchy, is the Visual Basic for Application (VBA) debugger and its watch window.

 

You can use VBA from a lot of applications, e.g. Microsoft Office Word or Excel. Press Alt+F11 to open the VBA IDE. At first you must choose the menu item Tools, References and search for the file C:\Program Files\SAP\FrontEnd\SAPgui\sapfewse.ocx, to bind the SAP GUI Scripting API to your VBA program.

 

Now you can use the following program to check the possibilities:

 

Option Explicit

 

Sub Test()

 

  Dim SapGuiAuto As Object
  Dim Application As SAPFEWSELib.GuiApplication
  Dim Connection As SAPFEWSELib.GuiConnection
  Dim Session As SAPFEWSELib.GuiSession
  Dim Window As SAPFEWSELib.GuiModalWindow
  Dim Coll As SAPFEWSELib.GuiCollection
 
  Set SapGuiAuto = GetObject("SAPGUI")
  If Not IsObject(SapGuiAuto) Then
    Exit Sub
  End If
 
  Set Application = SapGuiAuto.GetScriptingEngine()
  If Not IsObject(Application) Then
    Exit Sub
  End If
 
  Set Connection = Application.Connections(0)
  If Not IsObject(Connection) Then
    Exit Sub
  End If
 
  Set Session = Connection.Sessions(0)
  If Not IsObject(Session) Then
    Exit Sub
  End If
 
  Set Window = Session.FindById("wnd[1]")
  If IsObject(Window) Then
    Set Coll = Window.DumpState("")
    Stop
  End If
 
  Set Coll = Nothing
  Set Window = Nothing
  Set Session = Nothing
  Set Connection = Nothing
  Set Application = Nothing
  Set SapGuiAuto = Nothing

 

End Sub

 

Execute it in debug mode with F5, it stops at line 35. Choose the variable Coll and add it to your watch window. Open the GuiCollection in the watch window and view the complete hierarchy of the object and the values of the attributes, like in the following picture.

 

Image may be NSFW.
Clik here to view.
neu-1.jpg

 

The VBA debugger offers many possibilities to analyze SAP GUI Scripting objects at runtime.

Use it.

 

Cheers
Stefan

SAP GUI Scripting Wizard Tool

here is  a SAP hit tool ( like the SAP wizard) for anyone doing SAP automation  windows 7.

 

http://www.autoitscript.com/forum/topic/149540-sapwizardudf/

 

This lets you click on a control on any SAP GUI and highlights

it just like the wizard did and tells you the control path.

 

The SAP wizard has problems on windows 7 (http://scn.sap.com/thread/2006892) due to its use of Office Assistants Agents which are no longer supported in windows 7.

 

Note, GUI Scripting needs to be turned on see your system admin (or see transaction rz11 to turn on)

 

Note, This tool is written in Auto IT automation tool language..you will need to  compile it.

 

Enjoy

 

 

tags SAP GUI scripting wizard not working

 

also see The this excellent tool Script tracker..

http://scn.sap.com/docs/DOC-32728#comment-349789

CCo (COM Connector) for SAP NetWeaver RFC Library for Scripting Languages

Hello community,

 

SAP offers different connectors to develop ABAP compatible components and applications. JCo for Java environments, NCo for dotNET languages and the NetWeaver RFC SDK for C++. But what's up if you work neither with Java or dotNET environments nor with C++?

 

Here is another alternative, CCo - the COM Connector for SAP. CCo is a COM library and offers wrappers around all functions of the SAP NetWeaver RFC library. So it is possible to use all functionalities of the SAP NetWeaver RFC library inside any language which support COM technic.

 

With CCo it is easily possible to use the SAP NetWeaver RFC functions inside VBScript, Visual Basic for Applications (VBA) or AutoIt script.

 

Here a VBScript example to connect an SAP system:

 

'-Begin-----------------------------------------------------------------

  '-Directives----------------------------------------------------------
    Option Explicit


  '-Variables-----------------------------------------------------------
    Dim SAP, hRFC, rc


  '-Main----------------------------------------------------------------

    Set SAP = CreateObject("COMNWRFC")
    If IsObject(SAP) Then

      SAP.About

      hRFC = SAP.RfcOpenConnection("ABAP", "00", "001", "BCUSER", "", _

        "EN", "0", "0")


      If hRFC Then
        MsgBox "Check connection with TAC SMGW in the SAP system"
        rc = SAP.RfcCloseConnection(hRFC)
      End If
      Set SAP = Nothing
    End If

'-End-------------------------------------------------------------------

 

Here a VBA example to ping an SAP system:

 

'-Begin-----------------------------------------------------------------


  Option Explicit


  '-Constants-----------------------------------------------------------

    Const RFC_OK = 0


  '-Sub Ping------------------------------------------------------------

    Sub Ping()
 
      '-Variables-------------------------------------------------------
        Dim SAP As CCo.COMNWRFC
        Dim hRFC As Long
        Dim rc As Integer
        Dim hFunc, hFuncDesc As Long


      Set SAP = CreateObject("COMNWRFC")

      If IsObject(SAP) Then
 
        hRFC = SAP.RFCOPENCONNECTION("ABAP", "00", "001", "BCUSER", _
          "", "EN", "0", "0")
        If hRFC Then
       
          '-Variant1----------------------------------------------------
            hFuncDesc = SAP.RFCGETFUNCTIONDESC(hRFC, "RFC_PING")
            If hFuncDesc Then
              hFunc = SAP.RFCCREATEFUNCTION(hFuncDesc)
              If hFunc Then
                If SAP.RFCINVOKE(hRFC, hFunc) = RFC_OK Then
                  Debug.Print "Ping successful"
                Else
                  Debug.Print "Ping not successful"
                End If
                SAP.RFCDESTROYFUNCTION hFunc
              End If
            End If
         
          '-Variant2----------------------------------------------------
            If SAP.RFCPING(hRFC) = RFC_OK Then
              Debug.Print "Ping successful"
            Else
              Debug.Print "Ping not successful"
            End If
       
          rc = SAP.RFCCLOSECONNECTION(hRFC)
        End If
        Set SAP = Nothing
   
      End If
     
    End Sub

'-End-------------------------------------------------------------------

 

To the duality of accesses via SAP GUI Scripting and RFC with scripting languages

Image may be NSFW.
Clik here to view.
ScriptStructure.jpg

CCo opens a powerful second channel to communicate with an SAP back end. You can code in your favorite COM-enabled scripting language and use two ways: on the one hand the SAP GUI Scripting to communicate via SAP GUI for Windows with an SAP system, and on the other hand the COM Connector (CCo) to communicate via SAP NetWeaver RFC library with an SAP application server.

CCo is an ideal complementation to SAP GUI Scripting in this application area. You can e.g. use the wide range of thousands of remote-enabled function modules from an SAP system. Use the transaction code BAPI to open the BAPI explorer and find a lot in the alphabetical hierarchy tree.

Enrich your SAP GUI Scripting operation processes. Get information easy and fast via CCo RFC interface in your scripting environment. Combine the best of both worlds.

 

Hint: CCo has at the moment experimental character. Don't use it in production environments.

 

Hint: CCo needs SAP RFC SDK, you find it here.

 

Download

You find CCo here: http://cco.stschnell.de

 

2013/05/05:

  • New Version 0.50 is available. A lot of methods needs no longer pointer, now it is possible to set the arguments direct.
  • ABAP examples are now included.

 

Comments are welcome.

 

Cheers

Stefan

Save Layout Option in ALV

By Gejo john, Lnt Infotech.

 

At times it is required that the user wants the option
of changing the layout of the ALV format and then Can Save it.
It can be also required that after some time they can delete it also , so a manage layout option sholud also be there.

This kind of requirement will mainly comes when there are lots of columns are there in ALV .


All you have to do to achive this is to pass IS_VARIANT  and I_SAVE as the export parameters in method
SET_TABLE_FOR_FIRST_DISPLAY.

Pass the program name to IS_VARIANT.
I_SAVE can have below values .

I_SAVE = blank " sAVE layout option will not be there .
I_SAVE = 'X'  " Global layout only
I_SAVE = 'A'  " BOTH User specific and global
I_SAVE = 'U'  " only user specific only


E.g :

  GV_VARIANT  TYPE DISVARIANT    VALUE SY-REPID,
  CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        IS_VARIANT                    = GV_VARIANT
        I_SAVE                        = 'A'
      CHANGING
        IT_OUTTAB                     = <FS_OUTTAB>
        IT_FIELDCATALOG               = <FS_FIELDCATALOG>
        IT_SORT                       = GT_SORT
      EXCEPTIONS
        INVALID_PARAMETER_COMBINATION = 1
        PROGRAM_ERROR                 = 2
        TOO_MANY_LINES                = 3
        OTHERS                        = 4.
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.


this will give u 4 options in the ALV tool bar
• Save layout: User can Save the layout
• Manage Layout : User can delete the saved layout 
• Choose Layout : User can select among the saved layouts
• Change Layout : User can change the layout and can save if required

 

 

Let me know if you have any doubts in this .

 

Thanks,

Gejo john


SAP GUI Scripting 'How to avoid system messages during recording/playback'

Hello.

 

When we run an recorded SAP Script may upcoming system messages or messages type "I" and "A" can interrupt our script. Messages type "S", "E" and "W" will always shown in statusbar.

 

To avoid this behaviour during record or playback of scripts SAP GUI Scripting provide an session property named 'TestToolMode' which can be set in our script (straight before update statements):

 

session.TestToolMode = 1

 

When we do an recording this has to be done like:

 

session.TestToolMode = 1

session.RecordFile = "Test_Record_Filename"

session.Record = 1

 

Stop Recording:

 

session.Record = 0

session.TestToolMode = 0

 

Setting of property 'session.TestToolMode = 1' on GuiSession object will have below impact:

 

  • While success (S), warning (W) and error (E) messages are always displayed
    in the statusbar, information (I) and abort (A) messages are displayed as pop-up
    windows unless testToolMode is set.
  • The update mode of the application server is changed to immediate mode for
    the connection.
  • System messages are ignored so that they do not interrupt the recording or
    playback of scripts.

 

(Source: SAP GUI Scripting API 7.10 helpfile / Author: christian.cohrs@sap.com)

 

Hope this will help you to make your scripting more stable and reduce interruption.

 

Best regards,

 

Holger

How to Use Different Active Scripting Engines with SAP GUI Scripting

Hello community,

 

since Windows Scripting Host (WSH) 2.0 offers Microsoft with the Windows Script File (WSF) the possibility to combine different scripting languages in one script file. The WSF files containes an Extensible Markup Language (XML) structure with one package tag and different job tags. Below the job tag we can define different script sections with different scripting languages. Here an easy exmaple how to combine VBScript and JScript:

 

<?xml version="1.0" standalone="yes"?>
<package id="test">
  <comment>
    This is a test script
  </comment>
  <job id="001">


    <runtime>
      <description>
        This script shows the using of VBScript and JScript in one
        script file
      </description>
      <example>
        wscript Test.wsf
      </example>
    </runtime>


    <script language="JScript">
      <![CDATA[
//-Begin----------------------------------------------------------------

 

  function JSHelloWorld() {
    return("Hello World from JScript");
  }

 

//-End------------------------------------------------------------------
      ]]>
    </script>


    <script language="VBScript">
      <![CDATA[
'-Begin-----------------------------------------------------------------

 

  MsgBox "Hello World from VBScript"

  MsgBox JSHelloWorld()

 

'-End-------------------------------------------------------------------
      ]]>
    </script>


  </job>
</package>

 

 

Now an example how to use the shift operators from JScript inside VBScript:

 

<?xml version="1.0" standalone="yes"?>
<package id="shift">
  <comment>
    This is a test script
  </comment>
  <job id="001">


    <runtime>
      <description>
        This script shows the using of JScript shift operators with
        VBScript
      </description>
      <example>
        wscript Shift.wsf
      </example>
    </runtime>


    <script language="JScript">
      <![CDATA[
//-Begin----------------------------------------------------------------

 

  function ShiftLeft(Value, Shift) {

    //-Variables--------------------------------------------------------
      var Result;

    Result = Value << Shift
    return(Result);
  }

 

  function ShiftRight(Value, Shift) {

    //-Variables--------------------------------------------------------
      var Result;

    Result = Value >> Shift
    return(Result);
  }

 

//-End------------------------------------------------------------------
      ]]>
    </script>


    <script language="VBScript">
      <![CDATA[
'-Begin-----------------------------------------------------------------

 

  MsgBox CStr(ShiftLeft(14, 2))                 '1110 << 2 = 111000 (56)
  MsgBox CStr(ShiftRight(14, 2))                '1110 >> 2 =     11 ( 3)

 

'-End-------------------------------------------------------------------
      ]]>
    </script>


  </job>
</package>

 

 

It is also possible to implement your SAP GUI script, from the SAP GUI Scripting recorder, inside the VBScript section and to combine it with a JScript section too.

 

<?xml version="1.0" standalone="yes"?>
<package id="test">
  <comment>
    This is a test script
  </comment>
  <job id="001">


    <runtime>
      <description>
        This script shows the using of SAP GUI Scripting as VBScript
        and JScript in one script file
      </description>
      <example>
        wscript SAPGUIScript.wsf
      </example>
    </runtime>


    <script language="JScript">
      <![CDATA[
//-Begin----------------------------------------------------------------

 

  function getJScriptEngine() {
    return ScriptEngine();
  }

 

//-End------------------------------------------------------------------
      ]]>
    </script>


    <script language="VBScript">
      <![CDATA[
'-Begin-----------------------------------------------------------------

 

  MsgBox ScriptEngine()

 

  If Not IsObject(application) Then
    Set SapGuiAuto  = GetObject("SAPGUI")
    Set application = SapGuiAuto.GetScriptingEngine
  End If

 

  If Not IsObject(connection) Then
    Set connection = application.Children(0)
  End If

 

  If Not IsObject(session) Then
    Set session    = connection.Children(0)
  End If

 

  session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "001"
  session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "bcuser"
  session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "minisap"
  session.findById("wnd[0]/usr/txtRSYST-LANGU").text = "EN"
  session.findById("wnd[0]").sendVKey 0

 

  MsgBox getJScriptEngine()

 

'-End-------------------------------------------------------------------
      ]]>
    </script>


  </job>
</package>

 

 

On this way you can use different Active Scripting Engines with SAP GUI Scripting. So you can mix, beside VBScript and JScript, e.g. PerlScript or OOREXX. You can use the best from each scripting language. And you have the possibility to use great archives from a few scripting languages. Use existing and consolidated solutions, it is often not necessary to invent the wheel again.

 

Cheers
Stefan

Scripting Tracker Lite - Development Tool for SAP GUI Scripting

Hello community,

OSS note 1633639 tells us very clear the status about the SAP GUI Development Tools with Windows 7. Also we see the problems with the wizard here.

 

Scripting Tracker Lite is an alternative. It is a small utility to replace the SAP GUI Scripting wizard.

 

The program shows a clearly arranged tree with all SAP sessions and its scripting objects. Also it shows for each scripting object, after the selection in the tree with a single mouse click, a lot of technical details like e.g. ID, position etc.

 

With the Analyzer the program offers the possibility to identify each scripting object with a red frame. It is possible on the one hand to select an object from the hierarchy tree and to press the right mouse button. One the other hand it is possible to select a session from the hierarchy tree and to press the identify button. Now it is necessary to move the mouse pointer to the selected session window. This functionality is equal to the SAP GUI Scripting wizard. After the identifying of the scripting object it is possible to copy its technical name, called ID, to the clipboard and to use them in another context.

 

Image may be NSFW.
Clik here to view.
Unbenannt.JPG

 

Scripting Tracker Lite is free and you can download it from tracker.stschnell.de

 

27.04.2013: New version 2.03 is available with the following changes:

  1. Bug fixing, thanks to Rüdiger Specht for the hint.

 

Product status: stable.

 

Comments are welcome.

Enjoy it.

 

Cheers

Stefan

How to Program and Run an ABAP Report from a Scripting Language via CCo

Hello community,

 

I presented COM Connector CCo for SAP NetWeaver RFC library here.

With CCo it is very easy possible to execute remote-enabled function modules.

 

Here now an example how to execute the FM RFC_ABAP_INSTALL_AND_RUN with the scripting languages VBScript and AutoIt Script. This FM offers the possibility to executes ABAP code from a program which comes from outside of the SAP environment.

 

 

The first example in VBScript:


'-Begin-----------------------------------------------------------------

 

  '-Directives----------------------------------------------------------
    Option Explicit

 

  '-Constants-----------------------------------------------------------
    Const RFC_OK = 0

 

  '-Sub Main------------------------------------------------------------
    Sub Main()

 

      '-Variables-------------------------------------------------------
        Dim SAP, hRFC, rc, hFuncDesc, hFunc, hTable, i, hRow
        Dim RowCount, charBuffer, Result

 

      '-ABAPReport------------------------------------------------------
      '-
      '- Code your ABAP report here. The length of each line must be
      '- equal or less than 72 characters.
      '-
      '-----------------------------------------------------------------
        Dim ABAP(3)
        ABAP(0) = "Report zTest Line-Size 256."
        ABAP(1) = "Write: 'Hello World from'."
        ABAP(2) = "Write: sy-sysid."

 

      Set SAP = CreateObject("COMNWRFC")
      If Not IsObject(SAP) Then
        Exit Sub
      End If

 

      hRFC = SAP.RfcOpenConnection("ABAP", "00", "001", "BCUSER")
      If hRFC = 0 Then
        Set SAP = Nothing
        Exit Sub
      End If

 

      hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, _
        "RFC_ABAP_INSTALL_AND_RUN")
      If hFuncDesc = 0 Then
        rc = SAP.RfcCloseConnection(hRFC)
        Set SAP = Nothing
        Exit Sub
      End If

 

      hFunc = SAP.RfcCreateFunction(hFuncDesc)
      If hFunc = 0 Then
        rc = SAP.RfcCloseConnection(hRFC)
        Set SAP = Nothing
        Exit Sub
      End If

 

      '-Writes the report into the PROGRAM table------------------------
        If SAP.RfcGetTable(hFunc, "PROGRAM", hTable) = RFC_OK Then
          For i = 0 To UBound(ABAP) - 1
            hRow = SAP.RfcAppendNewRow(hTable)
            rc = SAP.RfcSetChars(hRow, "LINE", ABAP(i))
          Next
        End If

 

      If SAP.RfcInvoke(hRFC, hFunc) = RFC_OK Then
        '-Gets the result from the WRITES table-------------------------
          If SAP.RfcGetTable(hFunc, "WRITES", hTable) = RFC_OK Then
            rc = SAP.RfcGetRowCount(hTable, RowCount)
            rc = SAP.RfcMoveToFirstRow(hTable)
            For i = 1 To RowCount
              hRow = SAP.RfcGetCurrentRow(hTable)
              rc = SAP.RfcGetChars(hRow, "ZEILE", charBuffer, 256)
              Result = Result & Trim(charBuffer) & vbCrLf
              If i < RowCount Then
                rc = SAP.RfcMoveToNextRow(hTable)
              End If
            Next
            '-Shows the result in a messagebox--------------------------
              MsgBox Result, vbOkOnly, "Result"
          End If
      End If

 

      rc = SAP.RfcDestroyFunction(hFunc)
      rc = SAP.RfcCloseConnection(hRFC)
      Set SAP = Nothing

 

    End Sub

 

  '-Main----------------------------------------------------------------
    Main

 

'-End-------------------------------------------------------------------

 

 

The second example in AutoIt Script:


;-Begin-----------------------------------------------------------------

 

  ;-Directives----------------------------------------------------------
    AutoItSetOption("MustDeclareVars", 1)

 

  ;-Constants-----------------------------------------------------------
    Const $RFC_OK = 0

 

  ;-Variables-----------------------------------------------------------
    Dim $SAP, $hRFC, $hFuncDesc, $hFunc, $hTable = 0, $RowCount = 0
    Dim $i, $hRow, $charBuffer = "", $Result

 

  ;-ABAPReport----------------------------------------------------------
  ;-
  ;- Code your ABAP report here. The length of each line must be
  ;- equal or less than 72 characters.
  ;-
  ;---------------------------------------------------------------------
    Dim $ABAP[3]
    $ABAP[0] = "Report zTest Line-Size 256."
    $ABAP[1] = "Write: 'Hello World from'."
    $ABAP[2] = "Write: sy-sysid."

 

  ;-Main----------------------------------------------------------------
    $SAP = ObjCreate("COMNWRFC")
    If Not IsObj($SAP) Then
      Exit
    EndIf

 

    $hRFC = $SAP.RfcOpenConnection("ABAP", "00", "001", "BCUSER")
    If Not $hRFC Then
      $SAP = 0
      Exit
    EndIf

 

    $hFuncDesc = $SAP.RfcGetFunctionDesc($hRFC, _
      "RFC_ABAP_INSTALL_AND_RUN")
    If Not $hFuncDesc Then
      $SAP.RfcCloseConnection($hRFC)
      $SAP = 0
      Exit
    EndIf

 

    $hFunc = $SAP.RfcCreateFunction($hFuncDesc)
    If Not $hFunc Then
      $SAP.RfcCloseConnection($hRFC)
      $SAP = 0
      Exit
    EndIf

 

    ;-Writes the report into the PROGRAM table--------------------------
      If $SAP.RfcGetTable($hFunc, "PROGRAM", $hTable) = $RFC_OK Then
        For $i = 0 To UBound($ABAP) - 1
          $hRow = $SAP.RfcAppendNewRow($hTable)
          $SAP.RfcSetChars($hRow, "LINE", $ABAP[$i])
        Next
      EndIf

 

    If $SAP.RfcInvoke($hRFC, $hFunc) = $RFC_OK Then
      ;-Gets the result from the WRITES table---------------------------
        If $SAP.RfcGetTable($hFunc, "WRITES", $hTable) = $RFC_OK Then
          $SAP.RfcGetRowCount($hTable, $RowCount)
          $SAP.RfcMoveToFirstRow($hTable)
          For $i = 1 To $RowCount
            $hRow = $SAP.RfcGetCurrentRow($hTable)
            $SAP.RfcGetChars($hRow, "ZEILE", $charBuffer, 256)
            $Result = $Result & StringStripWS($charBuffer, 3) & @CrLf
            If $i < $RowCount Then
              $SAP.RfcMoveToNextRow($hTable)
            EndIf
          Next
          ;-Shows the result in a messagebox----------------------------
            MsgBox(0, "Result", $Result)
        EndIf
    EndIf

 

    $ABAP = 0
    $SAP.RfcDestroyFunction($hFunc)
    $SAP.RfcCloseConnection($hRFC)
    $SAP = 0

 

;-End-------------------------------------------------------------------

 

 

In both examples we get this result:

Image may be NSFW.
Clik here to view.
0108_ABAPReport_Result.JPG

 

You see how easy it is to contain an ABAP report inside a script.

 

Cheers

Stefan

How to Define a Windows Script Component (WSC) aka Scriptlet and use it inside ABAP

Hello community,

 

Windows offers the possibility to define Windows Script Components (WSC), also known as Scriptlets.  This means you can compile a script file to a type library, register the WSC file and use it inside any other programming language as a COM object, e.g. like ABAP. You find detailed information about WSC on the Microsoft Technet here.

 

At first you must define a WSC file. A WSC file is a XML file. To define a WSC you can use the Microsofts Windows Script Component Wizard from here. In six steps you can create a WSC. You can use different Active Scripting Engines - a similar exampleseehere.

 

Here an example with VBScript and JScript:

 

<?xml version="1.0"?>
<package>
  <comment>
    Compile this Windows Scripting Component (WSC) to a typelibrary with
    the command: rundll32 scrobj.dll,GenerateTypeLib ABAPTest.wsc
      -file:ABAPTest.tlb -doc:"This is an ABAP test" -name:ABAPTest
    and register this WSC with a right mouse click on it and choose the
    menu item Register.
  </comment>

 

  <component id="ABAPTest">
    <?component error="true" debug="true"?>

 

    <registration
      description="ABAPTest"
      progid="ABAPTest.WSC"
      version="1.00"
      classid="{cfda20a9-a891-486d-89b7-9e57d1c91e75}" />

 

    <public>
      <property name="MsgText">
        <get/>
        <put/>
      </property>
      <method name="ShowMsgBox">
        <parameter name="AddMsgText"/>
      </method>
      <property name="AlertText">
        <get/>
        <put/>
      </property>
      <method name="ShowAlertBox">
        <parameter name="AddAlertText"/>
      </method>
    </public>

 

    <script language="VBScript">
      <![CDATA[
'-Begin-----------------------------------------------------------------

 

  '-Variables-----------------------------------------------------------
    Dim MsgText

 

  '-Properties----------------------------------------------------------
    Function get_MsgText()
      get_MsgText = MsgText
    End Function

    Function put_MsgText(newValue)
      MsgText = newValue
    End Function

 

  '-Methods-------------------------------------------------------------
    Sub ShowMsgBox(AddMsgText)
      MsgBox MsgText & vbCrLf & AddMsgText
    End Sub

 

  '-Main----------------------------------------------------------------
    MsgText = "Hello World from WSC VBScript"

'-End-------------------------------------------------------------------
      ]]>
    </script>

 

    <script language="JScript">
      <![CDATA[
//-Begin----------------------------------------------------------------

 

  //-Variables----------------------------------------------------------
    var AlertText;

 

  //-Properties---------------------------------------------------------
    function get_AlertText() {
      return AlertText;
    }

    function put_AlertText(newValue) {
      AlertText = newValue;
    }

 

  //-Methods------------------------------------------------------------
    function ShowAlertBox(AddAlertText) {
      ShowMsgBox(AlertText + '\r' + AddAlertText)
    }

 

  //-Main---------------------------------------------------------------
    AlertText = 'Hello World from WSC JScript';

 

//-End------------------------------------------------------------------
      ]]>
    </script>

 

  </component>
</package>

 

Compile this WSC file with the command rundll32 scrobj.dll,GenerateTypeLib ABAPTest.wsc -file:ABAPTest.tlb -doc:"This is an ABAP test" -name:ABAPTest to a type libaray and register the WSC file with the context menu item "Register". Be sure that you have admin rights to register the WSC.

 

That is all, now we can use this componenten inside any other language. Here the VBScript example:

 

'-Begin-----------------------------------------------------------------

 

  '-Variables-----------------------------------------------------------
    Dim ABAPTest

 

  '-Main----------------------------------------------------------------
    Set ABAPTest = CreateObject("ABAPTest.WSC")
    If IsObject(ABAPTest) Then

 

      '-VBScript--------------------------------------------------------
        ABAPTest.ShowMsgBox("This is a Test")

 

        ABAPTest.MsgText = "Hello World from ABAP via VBScript"
        ABAPTest.ShowMsgBox("This is another Test")

 

        MsgBox ABAPTest.MsgText

 

      '-JScript---------------------------------------------------------
        ABAPTest.MsgText = vbNullString
        ABAPTest.ShowAlertBox("This is a Test")

 

        ABAPTest.AlertText = "Hello World from ABAP via JScript"
        ABAPTest.ShowAlertBox("This is another Test")

 

        MsgBox ABAPTest.AlertText

 

      Set ABAPTest = Nothing
    End If

 

'-End-------------------------------------------------------------------

 

And here the same example in ABAP:

 

"-Begin-----------------------------------------------------------------
  Report zWSCTest.

 

    "-Type pools--------------------------------------------------------
      Type-Pools OLE2.

 

    "-Variables---------------------------------------------------------
      Data ABAPTest Type OLE2_OBJECT.
      Data MsgText Type String.
      Data AlertText Type String.

 

    "-Main--------------------------------------------------------------
      Create Object ABAPTest 'ABAPTest.WSC'.
      If sy-subrc <> 0 Or ABAPTest-HANDLE = 0 Or
        ABAPTest-TYPE <> 'OLE2'.
        Exit.
      EndIf.

 

      "-VBScript--------------------------------------------------------
        Call Method Of ABAPTest 'ShowMsgBox'
          Exporting #1 = 'This is a test'.

 

        Set Property Of ABAPTest 'MsgText' =
          'Hello World from ABAP via VBScript'.
        Call Method Of ABAPTest 'ShowMsgBox'
          Exporting #1 = 'This is another test'.

 

        Get Property Of ABAPTest 'MsgText' = MsgText.
        Write: / MsgText.

 

      "-JScript---------------------------------------------------------
        Set Property Of ABAPTest 'MsgText' = ''.
        Call Method Of ABAPTest 'ShowAlertBox'
          Exporting #1 = 'This is a test'.

 

        Set Property Of ABAPTest 'AlertText' =
          'Hello World from ABAP via JScript'.
        Call Method Of ABAPTest 'ShowAlertBox'
          Exporting #1 = 'This is another test'.

 

        Get Property Of ABAPTest 'AlertText' = AlertText.
        Write: / AlertText.

 

      Free Object ABAPTest.

 

"-End-------------------------------------------------------------------

 

If you want to use a WSC on a Windows 64bit system, you must add the CLSID registration from HKCR\CLSID also to HKCR\Wow6432Node\CLSID.

 

Windows Registry Editor Version 5.00

 

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{CFDA20A9-A891-486D-89B7-9E57D1C91E75}]
@="ABAPTest"

 

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{CFDA20A9-A891-486D-89B7-9E57D1C91E75}\InprocServer32]
@="C:\\Windows\\system32\\scrobj.dll"
"ThreadingModel"="Apartment"

 

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{CFDA20A9-A891-486D-89B7-9E57D1C91E75}\ProgID]
@="ABAPTest.WSC.1.00"

 

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{CFDA20A9-A891-486D-89B7-9E57D1C91E75}\ScriptletURL]
@="file:///C:/Dummy/ABAPTest.wsc"

 

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{CFDA20A9-A891-486D-89B7-9E57D1C91E75}\VersionIndependentProgID]
@="ABAPTest.WSC"

 

Withthisoptionit is very easyto make functions of different scripting enginesavailablein ABAP.

 

Cheers

Stefan

How to Communicate Between ABAP and a Scripting Language via IPC

Hello community,

 

sometimes it could be necessary to synchronize different activities between ABAP and a scripting language. I show here the possibility to define Windows Script Components (WSC) and how to use it inside ABAP. Also I show here how to use SAP NetWeaver RFC Library via COM Connector (CCo) inside a scripting language and the possibility to use BAPI or other RFC function modules. These are two perspectives that could make a possible synchronization required. It is very easy to synchronize this kind of activities.

 

COMIPC is a small COM library, to use Windows interprocess communications (IPC) with ABAP and other languages which are COM enabled. With this library it is very simple to use IPC between a script on the presentation server and ABAP on the application server. So you can very easy synchronize different programs, e.g. VBScript or AutoIt with an ABAP program, or what ever you need...

 

The library supports

  • Events
    An event is a synchronization object whose state can be explicitly set to signaled.
  • Semaphores
    A semaphore is also a synchronization object that maintains a count between zero and a specified maximum value.
  • FileMaps
    File mapping is the association of a file's contents with a portion of the virtual address space of a process.

 

Here an event example, at first the ABAP code:

 

"-Begin-----------------------------------------------------------------
  Report  zCOMIPC.

 

  "-Includes------------------------------------------------------------
    Include OLE2INCL.

 

  "-Constants-----------------------------------------------------------
    Constants Infinite Type i Value -1.

 

  "-Variables-----------------------------------------------------------
    Data oIPC Type Ole2_Object.
    Data rc Type i.
    Data hEvent Type i.

 

  "-Main----------------------------------------------------------------
    Create Object oIPC 'COMIPC'.

    Break-Point.

    If sy-subrc = 0 And oIPC-HANDLE <> 0 And oIPC-TYPE = 'OLE2'.

 

      "=Event===========================================================
        Call Method Of oIPC 'EventCreate' = hEvent
          Exporting #1 = 'TestEvent' #2 = 1 #3 = 0.
        Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
       
        If hEvent <> 0.

          Call Method Of oIPC 'EventWait' = rc
            Exporting #1 = 'TestEvent' #2 = Infinite.
          Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.

          "-------------------------------------------------------------
          "-
          "- Now start the external script to set the event
          "-
          "-------------------------------------------------------------

          Call Method Of oIPC 'EventReset' = rc
            Exporting #1 = 'TestEvent'.
          Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
         
        EndIf.

      Free Object oIPC.

    EndIf.

 

"-End-------------------------------------------------------------------

 

Now the AutoIt code:

 

;-Begin-----------------------------------------------------------------

 

  ;-Variables-----------------------------------------------------------
    Dim $oIPC

 

  ;-Main----------------------------------------------------------------
    $oIPC = ObjCreate("COMIPC")

 

    ;-Event-------------------------------------------------------------
      $oIPC.EventSet("TestEvent")

 

;-End-------------------------------------------------------------------

 

If the ABAP code is executed, it stops at the call of EventWait. Now it is necessary to execute the AutoIt script, to set the event. After the execution of the AutoIt script, the ABAP code will continue to run.

 

Here another example with a filemap, at first the ABAP code:


"-Begin-----------------------------------------------------------------
  Report  zCOMIPC.

 

  "-Includes------------------------------------------------------------
    Include OLE2INCL.

 

  "-Constants-----------------------------------------------------------
    Constants Infinite Type i Value -1.

 

  "-Variables-----------------------------------------------------------
    Data oIPC Type Ole2_Object.
    Data rc Type i.
    Data hFileMap Type i.
    Data FileMapData Type String.

 

  "-Main----------------------------------------------------------------
    Create Object oIPC 'COMIPC'.

    Break-Point.

    If sy-subrc = 0 And oIPC-HANDLE <> 0 And oIPC-TYPE = 'OLE2'.

 

      "=FileMap=========================================================
        Call Method Of oIPC 'FileMapCreate' = hFileMap
          Exporting #1 = 'TestFileMap'.
        Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.

 

        If hFileMap <> 0.

          Call Method Of oIPC 'FileMapWrite' = rc
            Exporting #1 = 'TestFileMap' #2 = 'This is a test from ABAP'.
          Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.

          "-------------------------------------------------------------
          "-
          "- Now start the script to get the text from the filemap
          "-
          "-------------------------------------------------------------

          Call Method Of oIPC 'FileMapClose' = rc
            Exporting #1 = hFileMap.
          Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.

        EndIf.

 

        Call Method Of oIPC 'FileMapRead' = FileMapData
          Exporting #1 = 'TestFileMap2'.
        Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.

      Free Object oIPC.

    EndIf.

 

"-End-------------------------------------------------------------------

 

Now the AutoIt code:

 

;-Begin-----------------------------------------------------------------

 

  ;-Variables-----------------------------------------------------------
    Dim $oIPC
    Dim $Result

 

  ;-Main----------------------------------------------------------------
    $oIPC = ObjCreate("COMIPC")

 

    ;-Event-------------------------------------------------------------
      $Result = $oIPC.FileMapRead("TestFileMap")
     
      MsgBox(0, "Read the file map", $Result)

 

;-End-------------------------------------------------------------------

 

If you step with the debugger over the point FileMapWrite, execute the AutoIt script and you will see text from ABAP inside the messagebox of AutoIt.

With COMIPC is a basic communication and synchronization between ABAP and each COM enabled scripting language very handy.

 

You find COMIPC on my site: http://www.stschnell.de/

COMIPC is freeware.

 

Enjoy it.

Cheers
Stefan

SAP GUI Scripting in the Context of NetWeaver Business Client, a New Perspective

Hello community,

we see at the DSAG (German SAP User Group) the NetWeaver Business Client (NWBC) as replacement in the near future for the SAP GUI for Windows with the SAP Logon. From this point I considered the SAP GUI Scripting with NWBC for Desktop. At first I installed the NWBC 4.0 PL 4 and configured the application server. It runs well and I directed my attention to the SAP GUI Scripting.

 

First of all, it works. But there are some differences to SAP GUI Scripting inside SAP GUI for Windows.

 

1. If I open a second NWBC Client window and use the method Connections from the Application object with the property Count, I get not more than one connection. SAP GUI Scripting uses only the first NWBC Client window. Look here: http://scn.sap.com/thread/3323820

 

2. The correct entry in the running object table (ROT) for the SAP GUI Scripting inside NWBC is SAPGUISERVER.

 

3. If I record a SAP GUI Script with NWBC, it sets SapGuiAuto = GetObject("SAPGUI"). If I start this script from Windows Explorer, it runs in a normal SAP GUI for Windows session. I think it should be SapGuiAuto = GetObject("SAPGUISERVER"). Look here: http://scn.sap.com/thread/3325237, also for the next points.

 

4. In the NWBC is no Ok-Code-Field visible. It is possible to use it with SAP GUI Scripting because it is in the scripting object hierarchy, but it is not possible to record something with it in NWBC.

 

5. In the NWBC is no Toolbar[1] visible and not useable. Older SAP GUI Scripts will not work and there is no equivalent.

 

My momentary conclusion: SAP GUI Scripting in the context of NWBC offers not the same possibilities as in SAP GUI for Windows context now. We will see what will happen in the future development of NWBC in this sector, I am curious.

 

To be continued...

 

Cheers
Stefan


Scripting Tracker Lite - Development Tool for SAP GUI Scripting

Hello community,

OSS note 1633639 tells us very clear the status about the SAP GUI Development Tools with Windows 7. Also we see the problems with the wizard here.

 

Scripting Tracker Lite is an alternative. It is a small utility to replace the SAP GUI Scripting wizard.

 

The program shows a clearly arranged tree with all SAP sessions and its scripting objects. Also it shows for each scripting object, after the selection in the tree with a single mouse click, a lot of technical details like e.g. ID, position etc.

 

With the Analyzer the program offers the possibility to identify each scripting object with a red frame. It is possible on the one hand to select an object from the hierarchy tree and to press the right mouse button. One the other hand it is possible to select a session from the hierarchy tree and to press the identify button. Now it is necessary to move the mouse pointer to the selected session window. This functionality is equal to the SAP GUI Scripting wizard. After the identifying of the scripting object it is possible to copy its technical name, called ID, to the clipboard and to use them in another context.

 

Image may be NSFW.
Clik here to view.
Unbenannt.JPG

 

Scripting Tracker Lite is free and you can download it from tracker.stschnell.de

 

27.04.2013: New version 2.03 is available with the following changes:

  1. Bug fixing, thanks to Rüdiger Specht for the hint.

 

Product status: stable.

 

Comments are welcome.

Enjoy it.

 

Cheers

Stefan

SAP GUI Scripting in the Context of NetWeaver Business Client, a New Perspective

Hello community,

we see at the DSAG (German SAP User Group) the NetWeaver Business Client (NWBC) as replacement in the near future for the SAP GUI for Windows with the SAP Logon. From this point I considered the SAP GUI Scripting with NWBC for Desktop. At first I installed the NWBC 4.0 PL 4 and configured the application server. It runs well and I directed my attention to the SAP GUI Scripting.

 

First of all, it works. But there are some differences to SAP GUI Scripting inside SAP GUI for Windows.

 

1. If I open a second NWBC Client window and use the method Connections from the Application object with the property Count, I get not more than one connection. SAP GUI Scripting uses only the first NWBC Client window. Look here: http://scn.sap.com/thread/3323820

 

2. The correct entry in the running object table (ROT) for the SAP GUI Scripting inside NWBC is SAPGUISERVER.

 

3. If I record a SAP GUI Script with NWBC, it sets SapGuiAuto = GetObject("SAPGUI"). If I start this script from Windows Explorer, it runs in a normal SAP GUI for Windows session. I think it should be SapGuiAuto = GetObject("SAPGUISERVER"). Look here: http://scn.sap.com/thread/3325237, also for the next points.

 

4. In the NWBC is no Ok-Code-Field visible. It is possible to use it with SAP GUI Scripting because it is in the scripting object hierarchy, but it is not possible to record something with it in NWBC.

 

5. In the NWBC is no Toolbar[1] visible and not useable. Older SAP GUI Scripts will not work and there is no equivalent.

 

My momentary conclusion: SAP GUI Scripting in the context of NWBC offers not the same possibilities as in SAP GUI for Windows context now. We will see what will happen in the future development of NWBC in this sector, I am curious.

 

To be continued...

 

Cheers
Stefan

Scripting Tracker Lite - Development Tool for SAP GUI Scripting

Hello community,

OSS note 1633639 tells us very clear the status about the SAP GUI Development Tools with Windows 7. Also we see the problems with the wizard here.

 

Scripting Tracker Lite is an alternative. It is a small utility to replace the SAP GUI Scripting wizard.

 

The program shows a clearly arranged tree with all SAP sessions and its scripting objects. Also it shows for each scripting object, after the selection in the tree with a single mouse click, a lot of technical details like e.g. ID, position etc.

 

With the Analyzer the program offers the possibility to identify each scripting object with a red frame. It is possible on the one hand to select an object from the hierarchy tree and to press the right mouse button. One the other hand it is possible to select a session from the hierarchy tree and to press the identify button. Now it is necessary to move the mouse pointer to the selected session window. This functionality is equal to the SAP GUI Scripting wizard. After the identifying of the scripting object it is possible to copy its technical name, called ID, to the clipboard and to use them in another context.

 

Image may be NSFW.
Clik here to view.
Unbenannt.JPG

 

Scripting Tracker Lite is free and you can download it from tracker.stschnell.de

 

27.04.2013: New version 2.03 is available with the following changes:

  1. Bug fixing, thanks to Rüdiger Specht for the hint.

 

Product status: stable.

 

Comments are welcome.

Enjoy it.

 

Cheers

Stefan

How to use Freestyle BASIC Script Language (FBSL) inside ABAP

Hello community,


in this forum we only discus how to connect SAP from different scripting languages. We never talk about the possibility how to use a scripting language from the SAP side. I published a little bit in 2009 about this theme in my blog with AutoItX. But AutoItX, the ActiveX component of Autoit, is, compared with AutoIt, restricted in its functionality. Now from this point I want to introduce another brilliant script language: Freestyle BASIC Script Language.

 

Freestyle BASIC Script Language (FBSL) is a multi-syntax all-in-one high-level language (HLL) development environment. Its interpretative layer is a vastly extended superset of traditional BASIC that targets seamless integration of FBSL applications with Windows API and third-party dynamic link libraries. Its integrated Dynamic Assembler and Dynamic C JIT compiler layers enable the user to interleave BASIC code with verbatim Intel-style assembly and ANSI C, respectively. You can find FBSL here.

 

To use FBSL inside ABAP I build an ActiveX library, called FBSLX. FBSLX contains wrapper functions around the library FBSL.dll. With FBSLX you have the possibility to use FBSL inside any language which is COM-enabled, also ABAP. The integration of FBSL insisde ABAP offers inter alia the possibilities to use on the presentation server easily

  • API/DLL functions,
  • a console window for input and/or output,
  • a GUI window,
  • memory functions,
  • memory map files for interprocess communication (IPC),
  • etc. etc. etc.

You can find FBSLX here.

 

Here an example how easy it is to use FBSL inside ABAP:

 

"-Begin-----------------------------------------------------------------
  Program ZFBSL.

 

    "-Constants---------------------------------------------------------
      Constants CrLf(2) Type c Value %_CR_LF.

 

    "-Variables---------------------------------------------------------
      Data oFBSL Type OLE2_OBJECT.
      Data Buffer Type String Value ''.
      Data rc Type i.
      Data RetVal Type i.

 

    "-Macros------------------------------------------------------------
      Define _.
        Concatenate Buffer &1 CrLf Into Buffer.
      End-Of-Definition.

 

      Define Flush.
        Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
      End-Of-Definition.

 

    "-Main--------------------------------------------------------------
      Create Object oFBSL 'FbslX'.

      If sy-subrc <> 0 Or  oFBSL-Handle = 0 Or oFBSL-Type <> 'OLE2'.
        Call Function 'ZFBSL'.
        Call Function 'ZFBSLX'.
        Create Object oFBSL 'FbslX'.
      EndIf.

 

      If sy-subrc = 0 And oFBSL-Handle > 0 And oFBSL-Type = 'OLE2'.

 

"-FBSL script begin-----------------------------------------------------

 

_ '#Uses "@|WIN32"'.
_ '#Option Strict'.
_ '#AppType GUI'.

 

_ 'Dim %rc'.
_ 'rc = Msgbox(Null, "Message", "Title", MB_ABORTRETRYIGNORE)'.
_ 'Return rc'.

 

"-FBSL script end-------------------------------------------------------

 

        "-Here we execute the script------------------------------------
          Call Method Of oFBSL 'ExecuteScriptBuffer' = rc
            Exporting #1 = Buffer.
          Flush.

 

        "-Here we get the return value of the script--------------------
          Call Method Of oFBSL 'GetReturnValueInteger' = RetVal.
          Flush.

 

        Write: RetVal.

 

        Free Object oFBSL.

      EndIf.

 

"-End-------------------------------------------------------------------

 

You find more examples here:

Different Return Values

Simple console window

Simple GUI window

UDT return value

Array return value

GL3DRose in SAP context (This is an impressive OGL example)

FBSL script controls ABAP report

 

FBSL offers a lot of new possibilities to integrate the presentation server in the context of ABAP on the application server. To implement FBSL complete in the ABAP context I use BinFile2ABAP, it works excellent.

 

Update 2013/09/14 and 2013/09/15

  • New FBSL program added to create ABAP FM from FBSL scripts.
  • New OGL example added of the teapot, look below.
  • New example how to control an ABAP report with an FBSL script.

 

A know-how document which describes the implementation and using of FBSL inside ABAP via FBSLX is here available.

 

Comments are welcome.

 

Enjoy it.

 

Cheers
Stefan

 

Image may be NSFW.
Clik here to view.
Teapot.JPG

How to Use a Drop Zone Inside ABAP with Freestyle BASIC Script Language

Hello community,

here is a small example how to use a drop zone via FBSL and to use it inside an ABAP report or function module.

 

At first we create two file maps. The first is for the communication between the drop zone events and the ABAP report and the second is for the communication of the drop event, here we store the file name of the dropped file.

Now it follows the definition of the Freestyle BASIC script. With the sub procedure RC we communicate via the file maps with the ABAP report. In the Main sub procedure we define the window and the event handling. With the event WM_DROPFILES we deliver the filename to the file map.

We write the file to the users work directory and runs an ansynchronous process. In the following while loop the ABAP report communicate with the FBSL script via the file maps. If a drop event is triggered, we read the file name from the file map.

 

You see how easy it is to realize a drop zone with FBSL and to implement it in an ABAP program.


"-Begin-----------------------------------------------------------------
  Program ZFBSL.

 

    "-Constants---------------------------------------------------------
      Constants CrLf(2) Type c Value %_CR_LF.
      Constants SW_SHOWNORMAL Type i Value 1.
      Constants MAX_PATH Type i Value 260.
      Constants idBQuit Type String Value '1001'.

 

    "-Variables---------------------------------------------------------
      Data oFBSL Type OLE2_OBJECT.
      Data Buffer Type String Value ''.
      Data hFileMap1 Type i Value 0.
      Data hFileMap2 Type i Value 0.
      Data rc Type i Value 0.
      Data FileName Type String Value ''.
      Data WorkDir Type String Value ''.
      Data ProcID Type i Value 0.
      Data RetCode Type String Value ''.

 

    "-Macros------------------------------------------------------------
      Define _.
        Concatenate Buffer &1 CrLf Into Buffer.
      End-Of-Definition.

 

      Define Flush.
        Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
      End-Of-Definition.

 

    "-Main--------------------------------------------------------------
      Create Object oFBSL 'FbslX'.

      If sy-subrc <> 0 Or  oFBSL-Handle = 0 Or oFBSL-Type <> 'OLE2'.
        Call Function 'ZFBSL_EXE'.
        Call Function 'ZFBSL_DLL'.
        Call Function 'ZFBSLX'.
        Create Object oFBSL 'FbslX'.
      EndIf.

 

      If sy-subrc = 0 And oFBSL-Handle > 0 And oFBSL-Type = 'OLE2'.

 

        Call Method Of oFBSL 'FileMapCreate' = hFileMap1
          Exporting #1 = 'SAP001' #2 = 4.

        Call Method Of oFBSL 'FileMapCreate' = hFileMap2
          Exporting #1 = 'SAP002' #2 = MAX_PATH.

        Flush.

 

        If hFileMap1 <> 0 And hFileMap2 <> 0.

 

_ '#Uses "@|WIN32"'.
_ '#Option Strict'.
_ '#AppType GUI'.

 

_ 'Begin NameSpace Win32'.
_ '  #DllImports Kernel32, User32, Shell32'.
_ 'End NameSpace'.

 

_ 'Begin Const'.
_ '  HWND_TOPMOST = -1'.
_ '  SWP_NOSIZE = 1'.
_ '  SWP_NOMOVE = 2'.
_ '  FILE_MAP_ALL_ACCESS = 30'.
_ '  idBQuit = 1001'.
_ 'End Const'.

 

_ 'Sub RC(ByVal $MMFName, ByVal $RetCode)'.
_ '  Dim %hMMF, %Buffer'.
_ '  hMMF = Win32.OpenFileMapping(FILE_MAP_ALL_ACCESS, 0, MMFName)'.
_ '  If hMMF Then'.
_ '    Buffer = Win32.MapViewOfFile(hMMF, FILE_MAP_ALL_ACCESS, _'.
_ '      0, 0, 0)'.
_ '    If Buffer Then'.
_ '      Poke(Buffer, RetCode)'.
_ '      Win32.UnmapViewOffile(Buffer)'.
_ '    End If'.
_ '    Win32.CloseHandle(hMMF)'.
_ '  End If'.
_ 'End Sub'.

 

_ 'Sub Main()'.
_ '  Dim $FileName'.

 

_ '  Fbsl_SetText(Me, "MyDropZone")'.
_ '  Style_Remove(Me, WS_MINIMIZEBOX + WS_MAXIMIZEBOX)'.
_ '  Resize(Me, 0, 0, 330, 255)'.
_ '  Center(Me)'.
_ '  Win32.SetWindowPos(Me, HWND_TOPMOST, 0, 0, 0, 0, _'.
_ '    SWP_NOSIZE + SWP_NOMOVE)'.
_ '  Show(Me)'.
_ '  Win32.DragAcceptFiles(Me, True)'.

_ '  Fbsl_Control("Button", Me, "Quit", idBQuit, 10, 10, _'.
_ '    100, 24, 0, 0)'.

 

_ '  Begin Events'.
_ '    Select Case CBMSG'.
_ '      Case WM_COMMAND'.
_ '        Select Case CBCTL'.
_ '          Case idBQuit'.
_ '            RC("SAP001", "1001")'.
_ '            Destroy(Me)'.
_ '        End Select'.
_ '      Case WM_DROPFILES'.
_ '        FileName = Space(MAX_PATH)'.
_ '        Win32.DragQueryFile(CBWPARAM, 0, FileName, MAX_PATH)'.
_ '        Win32.DragFinish(CBWPARAM)'.
_ '        RC("SAP002", FileName)'.
_ '        RC("SAP001", "1002")'.
_ '      Case WM_CLOSE'.
_ '        RC("SAP001", "1001")'.
_ '        Destroy(Me)'.
_ '    End Select'.
_ '  End Events'.

 

_ 'End Sub'.

 

          Call Method cl_gui_frontend_services=>get_sapgui_workdir
            Changing SAPWORKDIR = WorkDir Exceptions Others = 1.
          Concatenate WorkDir '\Drop.fbs' Into FileName.

 

          Call Method Of oFBSL 'WriteFile' Exporting #1 = FileName
            #2 = Buffer.
          Flush.

 

          Call Method Of oFBSL 'Shell' = ProcID Exporting
            #1 = 'Fbsl.exe' #2 = 'Drop.fbs'
            #3 = SW_SHOWNORMAL #4 = 0.
          Flush.

 

          Call Method Of oFBSL 'FileMapClear' = rc
            Exporting #1 = 'SAP001' #2 = 4.
          Call Method Of oFBSL 'FileMapClear' = rc
            Exporting #1 = 'SAP002' #2 = MAX_PATH.
          Flush.

 

          While RetCode <> idBQuit.

 

            Call Method Of oFBSL 'Sleep' Exporting #1 = 125.
            Flush.

 

            Call Method Of oFBSL 'FileMapRead' = RetCode
              Exporting #1 = 'SAP001' #2 = 4.
            Flush.

 

            Call Method Of oFBSL 'FileMapClear' = rc
              Exporting #1 = 'SAP001' #2 = 4.
            Flush.

 

            Case RetCode.

              When '1002'.

 

                Call Method Of oFBSL 'FileMapRead' = FileName
                  Exporting #1 = 'SAP002' #2 = MAX_PATH.
                Flush.

 

                ">Code executed when a file is droped<------------------
                  Call Method Of oFBSL 'DebugPrint'

                    Exporting #1 = FileName.

 

                  Write: / FileName.

 

                Call Method Of oFBSL 'FileMapClear' = rc
                  Exporting #1 = 'SAP002' #2 = MAX_PATH.
                Flush.

 

            EndCase.

 

          EndWhile.

 

          Call Method Of oFBSL 'FileMapClose' = rc
            Exporting #1 = hFileMap1.
          Call Method Of oFBSL 'FileMapClose' = rc
            Exporting #1 = hFileMap2.
          Flush.

 

          Free Object oFBSL.
        EndIf.

 

      EndIf.

 

"-End-------------------------------------------------------------------

 

You can find FBSL here: http://www.fbsl.net

You can find COM wrapper for FBSL here: http://fbslx.stschnell.de

 

Below an image. I drag the files from Windows Explorer to the drop zone and DebugView shows the name of the dropped file

 

Cheers

Stefan

 

Image may be NSFW.
Clik here to view.
Unbenannt.JPG

Viewing all 100 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>