Quantcast
Channel: SCN : All Content - Scripting Languages
Viewing all 522 articles
Browse latest View live

Error 0x80010105 (RPC_E_SERVERFAULT) using SAP Scripting API

$
0
0

All,

 

I'm working on an application for my company to run SAP Script, using SAP Scripting API. The application is being programmed in VB.NET from Visual Studio 2015.

 

When I try to open a Gui Application, I can get all the things I need (GuiApplication, ScriptingEngine, Session 0 etc.), but when I try to set the first field (actually, the user name on the logon screen..) I get an error 0x80010105 (RPC_E_SERVERFAULT). This is the VB.NET code I'm using....

 

PublicSub RunScript()

 

   Dim ConnectionString AsString = BuildConnectionString()

 

   Dim app AsGuiApplication

 

   Dim mySession AsGuiSession

 

   Try

 

   'Create object wrapper

 

   Dim objWrapper = CreateObject("SapROTWr.SapROTWrapper")

 

   'Get sap GUI using wrapper

 

   Dim objRotSAPGUI = objWrapper.GetROTEntry("SAPGUI")

 

   If IsNothing(objRotSAPGUI) Then

 

   'New instance

 

       app = CType(CreateObject("Sapgui.ScriptingCtrl.1"), GuiApplication)

 

   Else

 

   'running instance

 

       app = CType(objRotSAPGUI.GetScriptingEngine(), GuiApplication)

 

   EndIf

 

   Dim Connection AsGuiConnection = app.OpenConnection("ECC6 EHP7 SR2 on HANA", True)

  

  mySession.FindById("/app/con[0]/ses[0]/wnd[0]/usr/txtRSYST-BNAME").text = "USER"

 

  mySession.FindById("/app/con[0]/ses[0]/wnd[0]/usr/pwdRSYST-BCODE").text = "PASSWORD"

 

  mySession.SendCommand("/0")

  

  app = Nothing

 

   Catch ex AsException

 

   EndTry

 

EndSub


 

The procedure creates the error when trying to set the user (field txtRSYST-BNAME). Has anybody ever seen that before and solved the issue?

 

Some parameters from my machine: OS is Windows 10 Enterprise 64bit, dev environment is Visual Studio Enterprise 2015, :Net frame work used is 4.6, the application is compiled for 32 bit. SAP Logon is 7.40, no NWBC installed.

 

Thanks a lot and best regards,

 

Werner Buchner



SAP HANA Script Recordings and Playback Changes

$
0
0

I currently have many test and mass automation scripts that were recorded using the SAP built in "Script Recordings and Playback" tool.

 

A majority of the scripts that are recorded using the tool are exported and embedded into VBA Excel automation programs to allow our end users to load mass amounts of data. The VBA code made from the SAP tool scripting tool references tables and fields in SAP.  Example shown below:

 

 

vba code.PNG


My company plans to implement SAP HANA and place our ERP systems on top of it.  I fear that the new HANA database structure will break all my scripts because they reference tables and fields that point at the old SAP table structure.


Will the change break my code and force me to re - record the scripts ? Also, if it does break the scripts, is there a way to work around it or adjust a setting in new SAP HANA ERP system to allow the scripts to work?

"Run-Time error ´429´: ActiveX component can´t create object

$
0
0

Hi!

 

Need some help!

The following code still works on my old Laptop (SAP version 720 and excel version 2007) but it does not work on my new laptop (SAP version 720 and excel version 2013).

I face the debug error in the first command.

If Not IsObject(SapGuiApp) Then
    Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")

 

Do someone know why this excel macro doesn´t work on my new laptop?

 

Please let me knkow if you need further information.

 

Thanks in advance,

Jose

Using VBScript for Automated Login to SAP

$
0
0

All,

 

I'm attempting to create a VBScript that will login to my companies SAP and basically run a report that outputs an HTM file for use with some other reports.  Generating the actual report goes off without a hitch, but I would like to set up a chron job (recurring windows task) that would completely automate this process.

 

I am primarily running into a problem with the automated login to SAP.  I have code that can open the SAP executable and I have code that can input the username and password into the login screen but I am at a loss on how to select and execute the target server (it is auto selected at the beginning but sending WshShell.SendKeys "{ENTER}" does not seem to work).  Any help would be greatly appreciated!

 

My code can reviewed on github with comments:

warroom/SAPLogin.vbs at master · PaulStreet/warroom · GitHub

 

For convenience I have also pasted the code (VBScript below).

 

'The below section will create an SAP session.

set WshShell = CreateObject("WScript.Shell")

Set proc = WshShell.Exec("C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe")

            Do While proc.Status = 0

            WScript.Sleep 100

      Loop

   Set SapGui = GetObject("SAPGUI")

Set Appl = SapGui.GetScriptingEngine

 

 

 

''Deprecated alternate code, wait for 6 seconds

'Dim dteWait

'dteWait = DateAdd("s", 6, Now())

'Do Until (Now() > dteWait)

'Loop

 

 

 

'Wait for 5 seconds then press enter.

WScript.Sleep 5000

WshShell.SendKeys "{ENTER}"

 

 

 

''This commented section of code doesn't seem to work for me.

'Set Connection = Appl.Openconnection("Test SAP", True)

'Set session = Connection.Children(0)

'session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "USERNAME"

'session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "PASSWORD"

'session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "E"

'session.findById("wnd[0]").sendVKey 0

 

 

 

'The below code is what I can record once I have gotten to the SAP login for the target server.

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

If IsObject(WScript) Then

   WScript.ConnectObject session,     "on"

   WScript.ConnectObject application, "on"

End If

session.findById("wnd[0]").maximize

session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "USERNAME"

session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "PASSWORD"

session.findById("wnd[0]/usr/pwdRSYST-BCODE").setFocus

session.findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 10

session.findById("wnd[0]").sendVKey 0

 

Attached is a screenshot of the screen I cannot get past (SAP executable with server select); ie the screen I cannot get past (there are other servers that I have censored out).

SAPServerSelectScreen.png

Download Documents from DMS using VBA

$
0
0

Hi All,

 

  I am looking for the solution to download the documents listed in the Excel from DMS in to the specific folder. The use case is, user will enter the list of required DMS numbers in the excel. Upon pressing the button, the mentioned in the list of Documents needs to be downloaded from DMS in to the specific folder.

 

Let me know, if you need any more information.

 

Regards,

Vijay.

How to use SAP GUI Scripting Inside Windows PowerShell (Part 2)

$
0
0

Hello community,

 

two and a half year ago I wrote here about the possiblity how to use SAP GUI Scripting with Windows PowerShell. But this solution uses Microsoft Script Control engine and it is not clear how the future will look like. So I develop a solution which works with PowerShell without the Microsoft Script Control engine:

 

#-Begin-----------------------------------------------------------------

 

  #-Get-Property--------------------------------------------------------

    function Get-Property {

      param([__ComObject] $object, [String] $propertyName)

      $objectType = [System.Type]::GetType($object)

      $objectType.InvokeMember($propertyName,

        "GetProperty", $NULL, $object, $NULL)

    }

 

  #-Set-Property--------------------------------------------------------

    function Set-Property {

      param([__ComObject] $object, [String] $propertyName,

        $propertyValue)

      $objectType = [System.Type]::GetType($object)

      [Void] $objectType.InvokeMember($propertyName,

        "SetProperty", $NULL, $object, $propertyValue)

    }

 

  #-Invoke-Method-------------------------------------------------------

    function Invoke-Method {

      param([__ComObject] $object, [String] $methodName,

        $methodParameters)

      $objectType = [System.Type]::GetType($object)

      $output = $objectType.InvokeMember($methodName,

        "InvokeMethod", $NULL, $object, $methodParameters)

      if ( $output ) { $output }

    }

 

  #-Main----------------------------------------------------------------

    $SapGuiAuto = [microsoft.visualbasic.Interaction]::GetObject("SAPGUI")

    $application = Invoke-Method $SapGuiAuto "GetScriptingEngine"

    $connection = Get-Property $application "Children" @(0)

    $session = Get-Property $connection "Children" @(0)

 

    $ID = Invoke-Method $session "findById" @("wnd[0]/usr/txtRSYST-MANDT")

    Set-Property $ID "Text" @("001")

    $ID = Invoke-Method $session "findById" @("wnd[0]/usr/txtRSYST-BNAME")

    Set-Property $ID "Text" @("BCUSER")

    $ID = Invoke-Method $session "findById" @("wnd[0]/usr/pwdRSYST-BCODE")

    Set-Property $ID "Text" @("minisap")

    $ID = Invoke-Method $session "findById" @("wnd[0]/usr/txtRSYST-LANGU")

    Set-Property $ID "Text" @("EN")

 

    $ID = Invoke-Method $session "findById" @("wnd[0]")

    Invoke-Method $ID "sendVKey" @(0)

 

#-End-------------------------------------------------------------------

 

Hint: The wrapper functions are from Bill Stewart - thanks for that.

 

Here the equivalent code but with Microsoft Script Control engine:

 

#-Begin-----------------------------------------------------------------


  $VB = New-Object -COMObject MSScriptControl.ScriptControl

 

$Cmd = @"

Set SapGuiAuto = GetObject(`"SAPGUI`")`n

Set application = SapGuiAuto.GetScriptingEngine`n

Set connection = application.Children(0)`n

Set session = connection.Children(0)`n

session.findById(`"wnd[0]/usr/txtRSYST-MANDT`").text = `"001`"`n

session.findById(`"wnd[0]/usr/txtRSYST-BNAME`").text = `"BCUSER`"`n

session.findById(`"wnd[0]/usr/pwdRSYST-BCODE`").text = `"minisap`"`n

session.findById(`"wnd[0]/usr/txtRSYST-LANGU`").text = `"EN`"`n

session.findById(`"wnd[0]`").sendVKey 0`n

"@

 

  $VB.Language = "VBScript"

  $VB.AllowUI = $TRUE

  $VB.ExecuteStatement($Cmd)

 

#-End-------------------------------------------------------------------

 

As you can see looks the code a little bit unusual, but on this way you use only a VB.net function and PowerShell natively.

 


2016/03/08

Minor changes, explicit type detection for PowerShell 5 compatibility.

 

 

Enjoy it.

 

Cheers

Stefan

How To Use COM Functions in PowerShell Easily, in Comparison with VBScript, Using the Example of CCo

$
0
0

Hello community,

 

over two years ago I presented COM Connector (CCo) here - CCo makes the using of the NetWeaver RFC library very easy.

Slowly but surely the landscape of the script language environments changed in Windows OS - from Windows Script Host (WSH) to PowerShell. From this point of view it seems good to take also a movement.

 

Here a PowerShell example how to get all installed SAP components and its version numbers in comparison with a VBScript which offers the same information.

 

#-Begin-----------------------------------------------------------------


  #-Constants-----------------------------------------------------------

    $RFC_OK = 0

    $VarByRef = -1


  #-Includes------------------------------------------------------------

    ."Includes\COM.ps1"

 

  #-Function Get-SAPComponents------------------------------------------

    Function Get-SAPComponents {

 

      $SAP = $null

      $SAP = Create-Object "COMNWRFC"

      if ($SAP -eq $null) {

        Break

      }

 

      $hRFC = Invoke-Method $SAP "RfcOpenConnection" @(

        "ASHOST=NSP, SYSNR=00, CLIENT=001, USER=BCUSER")

      if ($hRFC -eq 0) {

        Free-Object $SAP

        Break

      }

 

      $hFuncDesc = Invoke-Method $SAP "RfcGetFunctionDesc" @(

        $hRFC, "DELIVERY_GET_INSTALLED_COMPS")

      if ($hFuncDesc -eq 0) {

        $rc = Invoke-Method $SAP "RfcCloseConnection" $hRFC

        Free-Object $SAP

        Break

      }

 

      $hFunc = Invoke-Method $SAP "RfcCreateFunction" $hFuncDesc

      if ($hFunc -eq 0) {

        $rc = Invoke-Method $SAP "RfcCloseConnection" $hRFC

        Free-Object $SAP

        Break

      }

 

      $rc = Invoke-Method $SAP "RfcInvoke" @($hRFC, $hFunc)

      if ($rc -eq $RFC_OK) {

 

        $rc = Invoke-Method $SAP "RfcGetTable" @(

          $hFunc, "TT_COMPTAB", $VarByRef)

        if ($rc -eq $RFC_OK) {

 

          $hTable = Get-Property $SAP "lngByRef"

          $rc = Invoke-Method $SAP "RfcGetRowCount" @(

            $hTable, $VarByRef)

          $RowCount = Get-Property $SAP "lngByRef"

 

          $rc = Invoke-Method $SAP "RfcMoveToFirstRow" $hTable

 

          for ($i = 1; $i -le $RowCount ; $i++) {

 

            $Row = Invoke-Method $SAP "RfcGetCurrentRow" $hTable

 

            $rc = Invoke-Method $SAP "RfcGetChars" @(

              $Row, "COMPONENT", $VarByRef, 30)

            $charBuffer = Get-Property $SAP "strByRef"

            $txt = $txt + $charBuffer

 

            $rc = Invoke-Method $SAP "RfcGetChars" @(

              $Row, "RELEASE", $VarByRef, 10)

            $charBuffer = Get-Property $SAP "strByRef"

            $txt = $txt + $charBuffer

 

            $rc = Invoke-Method $SAP "RfcGetChars" @(

              $Row, "EXTRELEASE", $VarByRef, 10)

            $charBuffer = Get-Property $SAP "strByRef"

            $txt = $txt + $charBuffer

 

            $rc = Invoke-Method $SAP "RfcGetChars" @(

              $Row, "COMP_TYPE", $VarByRef, 1)

            $charBuffer = Get-Property $SAP "strByRef"

            $txt = $txt + $charBuffer + "`r`n"

 

            if ($i -lt $RowCount) {

              $rc = Invoke-Method $SAP "RfcMoveToNextRow" $hTable

            }

 

          }

        }

      }

 

      $rc = Invoke-Method $SAP "RfcDestroyFunction" $hFunc

      $rc = Invoke-Method $SAP "RfcCloseConnection" $hRFC

      Free-Object $SAP

      Remove-Variable SAP

      $txt

    }

 

  #-Function Main-------------------------------------------------------

    Function Main {

      $Components = Get-SAPComponents

      Write-Host $Components

    }

 

  #-Main----------------------------------------------------------------

    Main

 

#-End-------------------------------------------------------------------

 

 

Here now the VBScript:

 

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

 

  '-Directives----------------------------------------------------------

    Option Explicit

 

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

    Const RFC_OK = 0

 

  '-Function GetSAPComponents-------------------------------------------

    Function GetSAPComponents()

 

      '-Variables-------------------------------------------------------

        Dim SAP, hRFC, rc, hFuncDesc, hFunc, hTable, RowCount, i, Row

        Dim charBuffer, strText

 

      Set SAP = CreateObject("COMNWRFC")

      If Not IsObject(SAP) Then

        Exit Function

      End If

 

      hRFC = SAP.RfcOpenConnection("ASHOST=NSP, SYSNR=00, " & _

        "CLIENT=001, USER=BCUSER")

      If hRFC = 0 Then

        Set SAP = Nothing

        Exit Function

      End If

 

      hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, _

        "DELIVERY_GET_INSTALLED_COMPS")

      If hFuncDesc = 0 Then

        rc = SAP.RfcCloseConnection(hRFC)

        Set SAP = Nothing

        Exit Function

      End If

 

      hFunc = SAP.RfcCreateFunction(hFuncDesc)

      If hFunc = 0 Then

        rc = SAP.RfcCloseConnection(hRFC)

        Set SAP = Nothing

        Exit Function

      End If

 

      If SAP.RfcInvoke(hRFC, hFunc) = RFC_OK Then

        If SAP.RfcGetTable(hFunc, "TT_COMPTAB", hTable) = RFC_OK Then

          rc = SAP.RfcGetRowCount(hTable, RowCount)

          rc = SAP.RfcMoveToFirstRow(hTable)

          For i = 1 To RowCount

            Row = SAP.RfcGetCurrentRow(hTable)

            rc = SAP.RfcGetChars(Row, "COMPONENT", charBuffer, 30)

            strText = strText & Trim(charBuffer) & " "

            rc = SAP.RfcGetChars(Row, "RELEASE", charBuffer, 10)

            strText = strText & Trim(charBuffer) & " "

            rc = SAP.RfcGetChars(Row, "EXTRELEASE", charBuffer, 10)

            strText = strText & Trim(charBuffer) & " "

            rc = SAP.RfcGetChars(Row, "COMP_TYPE", charBuffer, 1)

            strText = strText & Trim(charBuffer) & vbCrLf

            If i < RowCount Then

              rc = SAP.RfcMoveToNextRow(hTable)

            End If

          Next

        End If

      End If

 

      rc = SAP.RfcDestroyFunction(hFunc)

      rc = SAP.RfcCloseConnection(hRFC)

      Set SAP = Nothing

 

      GetSAPComponents = strText

    End Function

 

  '-Sub Main------------------------------------------------------------

    Sub Main()

      MsgBox GetSAPComponents()

    End Sub

 

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

    Main

 

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

 

 

As you can see it is very comparable.

 

To establish the comparibility I use an include file, which stores the COM access routines like Create-Object, Invoke-Method etc.

 

#-Begin-----------------------------------------------------------------

 

  #-Function Create-Object----------------------------------------------

    Function Create-Object {

      param([String] $objectName)

      try {

        New-Object -ComObject $objectName

      }

      catch {

        [Void] [System.Windows.Forms.MessageBox]::Show(

          "Can't create object", "Important hint", 0)

      } 

    }

 

  #-Sub Free-Object-----------------------------------------------------

    Function Free-Object {

      param([__ComObject] $object)

      [Void] [System.Runtime.Interopservices.Marshal]::ReleaseComObject($object)

    }

 

  #-Function Get-Property-----------------------------------------------

    Function Get-Property {

      param([__ComObject] $object, [String] $propertyName)

      $objectType = [System.Type]::GetType($object)

      $objectType.InvokeMember($propertyName,

        [System.Reflection.Bindingflags]::GetProperty,

        $null, $object, $null)

    }

 

  #-Sub Set-Property----------------------------------------------------

    Function Set-Property {

      param([__ComObject] $object, [String] $propertyName,

        $propertyValue)

      $objectType = [System.Type]::GetType($object)

      [Void] $objectType.InvokeMember($propertyName,

        [System.Reflection.Bindingflags]::SetProperty,

        $null, $object, $propertyValue)

    }

 

  #-Function Invoke-Method----------------------------------------------

    Function Invoke-Method {

      param([__ComObject] $object, [String] $methodName,

        $methodParameters)

      $objectType = [System.Type]::GetType($object)

      $objectType.InvokeMember($methodName,

        [System.Reflection.Bindingflags]::InvokeMethod,

        $null, $object, $methodParameters, $null, $null, $null)

    }

 

#-End-------------------------------------------------------------------

 

001.jpg

 

With this tiny include you can use COM functions in PowerShell almost like in VBScript.

 

Let the games begin.

 

 

2016/03/08:

Minor changes for PowerShell 5 compatibility.

 

 

Cheers

Stefan

Error while trying to attach an Excel spreadsheet by _Excel_BookAttach () function AutoIt

$
0
0

Hellocommunity!

Errorwhile trying to attachan Excel spreadsheetby_Excel_BookAttach() functionAutoItthe sheetwas opened byan SAPtransaction,so I'm usingonlythe_Excel_Open() functionbut thisreturningan intermittent errorin myscript, does anyone canmehelp out?

Global$aWins=WinList($sSAP_Excel_Temp)
_ArrayDisplay($aWins)
$oWorkBook=_Excel_BookAttach($aWins[1] [0], "Title")
Error ="1 - Anerror occurredor$sStringcannot be foundinanyof theopenworkbooks@extendedisSet totheCOMerror code."
@Error=1@extended=-2147352570

I believeI'musingthe same resourcementionedin thislink:
http://help.sap.com/saphelp_afs64/helpdata/ja/e3/41a138c4397a42e10000009b38f842/content.htm

Thank you so much!

Márcio.


Scripting Tracker - Development Tool for SAP GUI Scripting

$
0
0

Hello community,

 

over two years ago I presented here the lite version of Scripting Tracker. Scripting Tracker is a utility and a replacement to the SAP GUI Scripting Development Tools. It is a SAP GUI analyzer and recorder on SAP GUI Scripting base. Now I decided to make all features of Scripting Tracker free available. In this case it means that the recording module is also free available from now.

 

tracker001.jpg

The analyzer 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.

tracker002.jpg

With the recorder the program offers the possibility to record, edit and execute your SAP GUI activities in Visual Basic, AutoIt, MiniRobot or PowerShell script language. E.g. with the + button you enriches the source with information comment lines about the transaction, title, dynpro - program name and screen number - and the session number. With Scripting Tracker you have full visual control about the creating code, now it couldn't be easier to use SAP GUI Scripting.

 

You can find Scripting Tracker here.

 

2016/03/12 Update 2.30 of Scripting Tracker is available

  • Complete redesign of the recorder module
  • Native PowerShell code generation

 

2016/02/25 Update 2.23 of Scripting Tracker is available

  • Help file return to CHM format
  • Minor changes

 

2015/10/24 Update 2.22 of Scripting Tracker is available

  • Actualization of the recorder module to GUI 7.40
  • Minor bug fixing

 

2015/09/05 Update 2.20 of Scripting Tracker is available

  • Add the Comparator tab, to compare screens with its elements and find differences between them easily.
  • Disable the possibility to export list of screen elements as CSV file.

 

2015/03/29 Update 2.12 of Scripting Tracker is available

  • Integration of AutoIt recorder now possible
  • Add the possibility to save a complete source file via shift and save button
  • Disable support of MiniRobot, because it has no relevance
  • Minor bug fixing

 

Comments are welcome.

 

Cheers

Stefan

PHP: RFC Logon problems

$
0
0

Hey guys,

 

I've done many implementations regarding SAP via RFC in PHP.

 

One stranger problem that I have is that we've created a new CLIENT and I want to connect to it.

 

  1. I've created a brand new user with all the required parameters and authorizations, direct copy from the main client server
  2. I've changed the client number from 200 to 300
  3. PHP extension is installed and it's working with the client 200
  4. My credentials are 100% correct
  5. Everything seems to be okay until the next message

 

Warning: RFC Error Info :
Group : 103
Key : RFC_ERROR_LOGON_FAILURE
Message : Name or password is incorrect (repeat logon)

 

My configuration look like this

 

require_once("sap/saprfc.php");
$login = array (            "ASHOST"    =>  "myIp",            "SYSNR"     =>  "00",            "CLIENT"    =>  "300",            "USER"      =>  "myUser",            "PASSWD"    =>  "myPass",            "LANG"      =>  "EN",            "CODEPAGE"  =>  "1100"
);

 

Any suggestions regarding this weird problem ?

Thank you

SAP GUI Scripting on SAP HANA

$
0
0

My company is moving from SAP ECC 6.0 to SAP HANA.

 

Is SAP GUI SCRIPTING available on SAP HANA ?

 

Any modification is required ?

 

Thanks

Use SAP GUI Scripting with Native PowerShell

$
0
0

Hello community,

 

a few days ago I presented here the new version of Scripting Tracker. The new version supports now native PowerShell code generating.

 

Here an example of a PowerShell script from a logon process.

001.jpg

You see the SAP GUI for Windows screen and the recorded script inside Scripting Tracker. With Scripting Tracker it is seamless possible to switch in the PowerShell ISE and here you find the complete code. Now you can use all the possibilities of the ISE like single step debugging or examination of variables.

 

Scripting Tracker uses a COM bridge for the communication with SAP GUI Scripting, which I presented here. On this way it is possible to generate code which is nearly similar to well known VBScript.

 

Here an example of an activity in an tree control in VBScript:

session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").expandNode "0000000003"

session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").selectedNode = "0000000004"

 

Here the same example in PowerShell:

$ID = Invoke-Method $session "findById" @("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell")

Invoke-Method $ID "expandNode" @("0000000003")

$ID = Invoke-Method $session "findById" @("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell")

Set-Property $ID "selectedNode" @("0000000004")

 

The comparisation shows that code in VBScript contains one line for one activity and PowerShell two lines. The code generation creates for findById one call of Invoke-Method and with the returned ID it calls the next activity e.g. like expandNode.

002.jpg

In some cases the code generation creates well known code like

$ID.elementAt(3).width = 19

which should sets the width of the third column of the table control.

But the method elementAt doesn't work in this context, it is necessary to replace it with Item like

$ID.Item(3).width = 19

which works perfectly.

003.jpg

Since version 5, which I presented here, offers PowerShell new language features like classes.

 

It has many advantages more to use PowerShell instead VBScript with SAP GUI Scripting:

  1. PowerShell is the actual Scripting language in Windows environments.
  2. It is available on all Windows systems without further installations.
  3. It is in further development.
  4. Its security mechanisms are technically mature.
  5. PowerShell offers an Integrated Scripting Environment (ISE) e.g. for single step debugging.
  6. etc.

 

Enjoy it.

 

Cheers

Stefan

Cannot get WScript.Quit to work to give user choice terminate script

$
0
0

Hi,

 

I've been attempting insert this code into an if statement and keep getting the same error:

 

'Object Required: 'WScript' -

 

Reading through the various forums, I've placed this code:

set WScript = CreateObject("WScript.Shell") in anumber of areas and it does not work

 

Does anyone know how to fix this and/or any other alternative for a user

to have the choice to Exit/Stop/Terminate a script,

 

Thanks

Export from specific fields in sessions to excel or Lotus notes.?

$
0
0

HI I would like to solve a task i do every day many many times. When i allocate payments i nearly all time have to send a mail in lotus notes. I would like to be able to transfer the input in specific fields to lotus mail. If not possible to a excel sheet.

 

 

If directly to lotus mail the FULL Name in the second picture have to go to the mail address in top

And the rest from the first picture have to go in the subject line with space between. So the Custemer is first and then name and then the amount which are highlighted in the payment which are open.

 

 

If in excel sheet.

I would like it open a new workbook,

Paste the Full name in the second picture/session to A1.

Paste Customer name to A2 from the first picture

Paste name to A3 from the first picture

and Highlighted amount to cell A4 from the first picture-

 

 

Please let me know if i have to find some controls and where to find and record them.

 

 

Thanks in advance

 

 

Sincerely

 

 

Abjac

Continuous processing until blank

$
0
0

Hi again guys/ ScriptMan,

 

I have a SAP recording which is repetitive as follows:

 

session.findById("wnd[0]/tbar[0]/okcd").text = "mmrv"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtMARV-BUKRS").text = "A111"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/chkMARV-XRUEM").selected = false

session.findById("wnd[0]/usr/chkMARV-XRUEM").setFocus

session.findById("wnd[0]/tbar[0]/btn[11]").press

session.findById("wnd[0]/usr/ctxtMARV-BUKRS").text = "B111"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/chkMARV-XRUEM").selected = false

session.findById("wnd[0]/usr/chkMARV-XRUEM").setFocus

session.findById("wnd[0]/tbar[0]/btn[11]").press

session.findById("wnd[0]/usr/ctxtMARV-BUKRS").text = "C111"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/chkMARV-XRUEM").selected = false

session.findById("wnd[0]/usr/chkMARV-XRUEM").setFocus

session.findById("wnd[0]/tbar[0]/btn[11]").press

 

As you have notice, only A111, B111, C111 keeps changing. In excel they are arranged in a single column row by row. Can u help me make a condition to loop the process until it reaches blank? It would be so much helpful.

 

Thanks in advance.


Export pdf using Windows window

$
0
0

Hi everybody,

 

I have following issue:

 

I have to Export invoices as pdfs using Transaction VF31 and scripting.

Because Spooling is not working I have to print the invoice via Cute Pdf Writer.

Everything works fine but the saving works via normal Windows window (see Picture).

 

Now my question:

How to enter another Name and press enter? I know there is some VBS code and I'm sure there is some VB compontent but I don't know which one.

 

thank you very much

bw

Michael
Unbenannt.PNG

How to get data from a table using vb.net

$
0
0

Hi,

    I am new to SAPGUI scripting. Am tring to access a table get some data of it. Am using SAPFEWSE.ocx

 

i used  SAPFEWSELib and so far i was able to Login and navigate to the table. But I cant extracte specific data from them. Here is my code so far.

Can anyone help me on how to get a value from a table. Am getting error at the redline. PLease help me.

 

    Private Sub loginInfo()        sapSession = sapCon.Children(0)        With sapSession            ' MsgBox(.FindById("wnd[0]/usr/txtRSYST-MANDT").Text)            ' .FindById("wnd[0]/usr/txtRSYST-MANDT").Text = "200"            ' MsgBox(.FindById("wnd[0]/usr/txtRSYST-MANDT").Text)            .FindById("wnd[0]/usr/txtRSYST-BNAME").Text = sapID            .FindById("wnd[0]/usr/pwdRSYST-BCODE").Text = sapPassword            .FindById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"            .FindById("wnd[0]").SendVKey(0)        End With    End Sub    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click        Try            ' sapID = TextBox1.Text            'sapPassword = TextBox2.Text            sap = CreateObject("SAPGUI.Scriptingctrl.1")            sapCon = sap.OpenConnectionByConnectionString(sapServer, True)            Create_File()            loginInfo()            prcss_data        Catch ex As Exception            MsgBox(ex.Message)        End Try    End Sub    Private Sub prcss_data()        With sapSession            .FindById("wnd[0]/tbar[0]/okcd").text = "se16"            .FindById("wnd[0]").sendvKey(0)            .FindById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").text = "zu1cd_fkkvkp"            .FindById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").caretPosition = 12            .FindById("wnd[0]").sendVKey(0)            '.FindById("wnd[0]/usr/ctxtI1-LOW").text = "W573121387"            '.FindById("wnd[0]").sendVKey(8)            '.FindById("wnd[0]/usr/ctxtI1-LOW").text = ""            .FindById("wnd[0]/usr/ctxtI1-LOW").caretPosition = 0            .FindById("wnd[0]").sendVKey(8)            .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell(-1, "GPART")            .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectColumn("GPART")            .FindById("wnd[0]/tbar[1]/btn[40]").press            Dim stt As String            For i = 1 To 10                stt = .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell(1, 3)                .FindById("wnd[0]/usr/txtI2-LOW").caretPosition = 10                .FindById("wnd[0]/usr/txtI2-LOW").setFocus                Write_log(stt)            Next            .FindById("wnd[0]").sendVKey(3)            .FindById("wnd[0]/usr/ctxtI1-LOW").text = "0200000882"            .FindById("wnd[0]/usr/txtI2-LOW").setFocus            .FindById("wnd[0]/usr/txtI2-LOW").caretPosition = 10            .FindById("wnd[0]").sendVKey(8)            .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").currentCellColumn = "OFFCYCLE"            .FindById("wnd[0]/usr/cntlGRID1/shellcont/shell").firstVisibleColumn = "BUSINITCODE"        End With    End Sub    Dim fs As Object    Dim fs_file As Object    Dim fname As String    Private Sub Write_log(ByVal linestr As String)        fs_file.writeline(linestr)    End Sub    Private Sub Create_File()        fs = CreateObject("Scripting.FileSystemObject")        fname = My.Application.Info.DirectoryPath + "\Log" + Date.Now.ToString("yyyyMMddHHmmss") & ".csv"        fs_file = fs.CreateTextFile(fname, True)    End Sub

Pasting filename in a panel using script

$
0
0

Hi Experts - I ran into a problem when trying to feed a filename into an open file dialog. I used this approach in the past with an "Open" dialog and thought same would work for "Import file" dialog box.

 

My main script is below:

 

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

If IsObject(WScript) Then

   WScript.ConnectObject session,     "on"

   WScript.ConnectObject application, "on"

End If

 

session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").text = "/niw32"

session.findById("wnd[0]").sendVKey 0

OrdNum = "7237602"

set Wshell = CreateObject("WScript.Shell")

session.findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").text = OrdNum

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"

session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_PCATTA_CREA"

 

'>>> these 2 lines above bring up the dialog box <<<<<

 

Wshell.run "c:\tmp\Scandf.vbs",1,False

 

'>> after the filename is dropped in the dialog box by the Scandf.vbs script it should continue with the process  <<

 

session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/subSUB_KOPF:SAPLCOIH:1102/btn%#AUTOTEXT001").press

session.findById("wnd[1]/usr/sub:SAPLBSVA:0201[1]/chkJ_STMAINT-ANWSO[0,0]").selected = true

session.findById("wnd[1]/usr/sub:SAPLBSVA:0201[1]/chkJ_STMAINT-ANWSO[0,0]").setFocus

session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[0]/tbar[0]/btn[11]").press

 

I am calling a script called Scandf.vbs where I have the filename I want to drop into the dialog box. This is the Scandf.vbs:

 

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

If IsObject(WScript) Then

WScript.ConnectObject session, "on"

WScript.ConnectObject application, "on"

End If

set Wshell = CreateObject("WScript.Shell")

MsgBox "in sub"

Do

bWindowFound = Wshell.AppActivate("Import file")

WScript.Sleep 1000

Loop Until bWindowFound

bWindowFound = Wshell.AppActivate("Import file")

if (bWindowFound) Then

Wshell.appActivate "Import file"

WScript.Sleep 100

Wshell.sendkeys "c:\EQ2814.txt"

WScript.Sleep 100

Wshell.sendkeys ""

end if

 

EQ2814.txt is the filename I want to drop in.

 

THe cursor is in the filename field and waiting for input. It just sits there after the dialog box is called and does not drop in the filename.

 

Can anybody see what I am doing wrong?

 

Thanks

 

Umur

FB03 Exporting of attachment

$
0
0

Hi guys!

 

I am currently developing a macro tool wherein I can export the attachment of a document using FB03 and saving it in a specific folder.

I was able to create one but I have the following problem:

> I don't know why there is an error with the path of the file whenever I try to link specific paths to a cell from my excel. But when I input the path directly to the VBA, it works. (hope this question was clear. )

> I am a VBA beginner so I would like to loop this macro and I want it to perform the export for a list of documents and not just one.

> Is it possible for me to insert the exported file into the excel sheet next to the document number?

 

Hope I was clear with what intend to do...Please help.

 

THANK YOU SO MUCH!!

 

 

Below are the details that I have in my Excel sheet

 

ABC
1Destination FileC:\Users\LIX2628\Desktop\PUll outs export\
2 Document NumberCo. CodeYear
1200072996u0012014

 

 

And below is the script that I used.

 

Sub FB03export()

 

 

Dim application

 

 

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

If IsObject(WScript) Then

   WScript.ConnectObject session, "on"

   WScript.ConnectObject application, "on"

End If

session.findById("wnd[0]").resizeWorkingPane 196, 15, False

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nfb03"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/txtRF05L-BELNR").Text = Cells(3, 2).Value

session.findById("wnd[0]/usr/ctxtRF05L-BUKRS").Text = Cells(3, 3).Value

session.findById("wnd[0]/usr/txtRF05L-GJAHR").Text = Cells(3, 4).Value

session.findById("wnd[0]/usr/txtRF05L-GJAHR").SetFocus

session.findById("wnd[0]/usr/txtRF05L-GJAHR").caretPosition = 4

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"

session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"

session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").currentCellColumn = "BITM_DESCR"

session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectedRows = "0"

session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").contextMenu

session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectContextMenuItem "%BDS_START_BDN"

session.findById("wnd[0]/shellcont[1]/shell").selectedNode = "Doc-00000001"

session.findById("wnd[0]/mbar/menu[0]/menu[6]").Select

session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]").Text = "C:\Users\LIX2628\Desktop\PUll outs export\"

session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]").caretPosition = 42

session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[0]/tbar[0]/btn[3]").press

session.findById("wnd[1]/tbar[0]/btn[12]").press

session.findById("wnd[0]/tbar[0]/btn[3]").press

 

 

End Sub

Exporting or saving report to excel from SAP 7.30

$
0
0

Dear Community,

 

I'm new to this forum and also new as VBA developer. Currently I'm working on the automation project in which i need to enter specific details on SAP (730) and generate report which look like excel-sheet but its not. When I select export to excel workbook the SAP save as window pops-up and I'm unable to access that window through macro and I was stuck there. Then I have identified many similar cases in this forum and provided solutions for it.

 

I tried to use below solution by calling separate vb script to control Save As window through my VBA code, but I'm stuck when there is any space in the file path where I need to save these files. I'm not much aware of SAP and vb script. Do I need to change any specific code below ?

 

Any help is much appreciated..thanks in advance.

 


My Code is as below:

 

 

session.findById("wnd[0]").sendVKey 8   'after this line the SaveAs window pop-up

 

FilePath = "c:\tmp\Sap download file\test1.xlsx")   'here is some space in file path

set Wshell = CreateObject("WScript.Shell")

wshell.run """c:\tmp\save_as.vbs """ & FilePath

 

session.findById("wnd[0]/tbar[1]/btn[16]").press

 

Save_as.vbs includes:

 

if Wscript.Arguments.count > 0 then
set fs = CreateObject("Scripting.FileSystemObject")
if fs.fileExists(WScript.arguments(0)) then
  Set myfile = fs.GetFile(WScript.arguments(0))
  myfile.Delete
end if
set Wshell = CreateObject("WScript.Shell")
Do
  bWindowFound = Wshell.AppActivate("Save As")
  WScript.Sleep 1000
Loop Until bWindowFound

Do
  Wshell.appActivate "Save As"
  Wshell.sendkeys WScript.arguments(0)
  WScript.Sleep 400
  Wshell.appActivate "Save As"
  Wshell.sendkeys "%s"
  WScript.Sleep 400
  bWindowFound = Wshell.AppActivate("Save As")
  WScript.Sleep 400
Loop Until not bWindowFound
end if
Viewing all 522 articles
Browse latest View live


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