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

How to Build an HTA/HTML UI to Code and Execute ABAP Reports

$
0
0

Hello community,

 

a longer time ago I introduced CCo (COM Connector) here. Later I presented here the possibility how to program and run an ABAP Report with the scripting language VBScript and CCo. Here is now a development with the same possibility and additional an UI to code the ABAP report. It is a hypertext application.

 

<html>  <head>    <title>      Execute an ABAP Report    </title>    <hta:application applicationname="ABAPReport" id="ABAPReport"      singleinstance="yes" border="thick" borderStyle="sunken"       version="1.0" />    <script language="VBScript">      '-Directives------------------------------------------------------        Option Explicit      '-Constants-------------------------------------------------------        Const RFC_OK = 0      '-ABAPExec--------------------------------------------------------        Sub ABAPExec()          '-Variables---------------------------------------------------            Dim SAP, hRFC, rc, hFuncDesc, hFunc, ABAP, i, hRow, hTable            Dim RowCount, charBuffer, Result          document.Output.Result.value = ""          Set SAP = CreateObject("COMNWRFC")          If Not IsObject(SAP) Then            Exit Sub          End If          hRFC = SAP.RfcOpenConnection( _            "ASHOST=" & document.ConnParams.ASHost.value & ", "  & _            "SYSNR=" & document.ConnParams.SysNr.value & ", " & _            "CLIENT=" & document.ConnParams.Client.value & ", " & _            "USER=" & document.ConnParams.User.value)          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              ABAP = Split(document.ABAP.Report.value, vbCrLf)              For i = 0 To UBound(ABAP) - 1                If Trim(ABAP(i)) <> "" Then                  hRow = SAP.RfcAppendNewRow(hTable)                  rc = SAP.RfcSetChars(hRow, "LINE", ABAP(i))                End If              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 the output area-------------------                  document.Output.Result.value = Result              End If          End If          rc = SAP.RfcDestroyFunction(hFunc)          rc = SAP.RfcCloseConnection(hRFC)          Set SAP = Nothing        End Sub              '-onLoad----------------------------------------------------------        Sub Window_onLoad()          window.moveTo 25,25          window.resizeTo 680,710        End Sub      </script>  </head>  <body>    <h1>      Execute an ABAP Report    </h1>    <form action="ConnParams.htm" name="ConnParams">      <p>        ASHost:         <input name="ASHost" type="text" size="10" maxlength="10"          value="ABAP">         SysNr.:         <input name="SysNr" type="text" size="2" maxlength="2"          value="00">         Client:         <input name="Client" type="text" size="3" maxlength="3"          value="001">         User:         <input name="User" type="text" size="12" maxlength="12"          value="BCUSER">      </p>    </form>    <input type="button" value="Execute ABAP Report"      onClick='ABAPExec()'>        <form action="ABAP.htm" name="ABAP">      <p><textarea name="Report" cols="72" rows="18" wrap="hard">
"-Begin-----------------------------------------------------------------  Report zTest Line-Size 72.  Write: 'Hello World from'.  Write: sy-sysid.
"-End-------------------------------------------------------------------</textarea>      </p>    </form>    <form action="Output.htm" name="Output">      <p>        <textarea name="Result" cols="72" rows="9" wrap="soft" readonly>      </textarea>      </p>    </form>  </body> </html>

 

ABAP1.jpg

As you can see it is very easy to build an external editor for ABAP reports, with the possibilities of HTML and CCo.

 

Cheers

Stefan


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

$
0
0

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("ASHOST=ABAP, SYSNR=00, " & _        "CLIENT=001, USER=BCUSER")      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("ASHOST=ABAP, SYSNR=00, " & _          "CLIENT=001, USER=BCUSER")        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

ScriptStructure1.jpg

 

CCo opens a powerful second channel to communicate with an SAP backend. 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/11/29:

  • New Version 0.93 is available.
  • New methods ClipBoardClear, ClipBoardRead and ClipBoardWrite to communicate via clip board.
  • Stable RFC interface since version 0.8 from 02.08.2013.
  • New HTA examples.

 

 

Comments are welcome.

 

Cheers

Stefan

SAP GUI Script Development tool on Windows 7 and SAP GUI 7.30

$
0
0

Hi members,

 

I have the following question pertaining to the standard SAP GUI Script development tool. I hope someone has hit this already and can provide an answer.

 

Is there a way to enable the SAP Script Development tool (the Merlin character which allows you to do click tests and examine GUI properties and SAP transaction) if you run SAP GUI for Windows 7.30 and Windows 7?

 

I did my homework and searched the SCN. I already know about:

  • Microsoft KB 969168 Microsoft Agent-enabled programs do not work in Windows 7; I installed the hotfix on my Win 7 computer, but it does not help
  • SAP Note 1633639 - Script Development Tool disabled from Windows 7; give you a background of the issue but refers to SAP GUI 7.20
  • I know about Scripting Tracker Lite and Bebo, both tools made and promoted by Stefan Schnell; I use them but switching back and forth between 2 apps is not optimal. Also you have to rescan all the active connections when you change the screen and this takes time if you run 6 connections/ Still good they exist.

 

I did not find any info for Windows 7 and SAP GUI 7.30

Thanks a bunch.

How to use Windows PowerShell Script inside ABAP

$
0
0

Hello community,

 

Windows PowerShell is a mix of command-line shell and scripting language. You find more Information about PowerShell here and here.

 

With the free COM library ActiveXPosh.dll from SAPIEN you can also use PowerShell inside ABAP.

 

Here an example how to get all services and its state.

 

"-Begin-----------------------------------------------------------------
  Program zPSTest.

    "-TypePools---------------------------------------------------------
      Type-Pools OLE2 .

    "-Constants--------------------------------------------------------
      Constants OUTPUT_CONSOLE Type i Value 0.
      Constants OUTPUT_WINDOW Type i Value 1.
      Constants OUTPUT_BUFFER Type i Value 2.

    "-Variables---------------------------------------------------------
      Data PS Type OLE2_OBJECT.
      Data Result Type i Value 0.
      Data strResult Type String Value ''.
      Data tabResult Type Table Of String.

    "-Main--------------------------------------------------------------
      Create Object PS 'SAPIEN.ActiveXPoSH'.

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

        Call Method Of PS 'Init' = Result Exporting #1 = 0.

        If Result = 0.

          Call Method Of PS 'IsPowerShellInstalled' = Result.

          If Result <> 0.

            Set Property Of PS 'OutputMode' = OUTPUT_BUFFER.

            Call Method Of PS 'Execute' Exporting
              #1 = 'Get-WmiObject -class Win32_Service | Format-Table -property Name,State'.

            Call Method Of PS 'OutputString' = strResult.

            Split strResult At cl_abap_char_utilities=>cr_lf
              Into Table tabResult.

            Loop At tabResult Into strResult.
              Write: / strResult.
            EndLoop.

          EndIf.

        EndIf.

        Free Object PS.
      EndIf.

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

 

You can use with PowerShell all dotNET and Windows standard libraries. On this way you can extend your possibilities.

 

Cheers

Stefan

VA02 Sales Order Automation?

$
0
0

Hello All,

 

I am very new to this vbs.. so need you guidance and support to solve my query. I am trying to automate Sales order line items details updation and i have recorded the below script and than modified a bit e.g. added excel codes which take the values from the excel. Here is the overview of the script, First goes to transaction VA02 and then take the sales order number from the excel sheet and enter the sales order and go to Item Overview tab and updates the first line description and than page down button is pressed to go to the last empty line where details are update like Material code, Qty. Descrption, WBSe element, etc these are updated from excel sheet and then the required details are taken from the excel sheet and updated in the sales order and SO is then saved.

 

The script runs fine, but only when i update the SO which was used for recording, but if the SO is changed it gives me error due to the Line selected for updation of material, Description, Qty and WBSe... If you check below the item overview ROW is 6 for the recorded SO which is hard coded, so how this can be solved of removing the hard code coding to a variable one which depends on the SO row number.

 

MABNR[1,6]"

KWMENG[3,6]")

UEPOS[2,6]")

 

 

 

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 xclapp = CreateObject("Excel.Application")

Set xclapp = CreateObject("Excel.Application")

Set xclwbk = xclapp.Workbooks.Open("c:\va02.xlsx")

set xclsht = xclwbk.Sheets("Sheet1")

 

 

For i = 2 to 8

 

While (not xclsht.Cells(i, 1).Value = "")

 

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

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

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

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

session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = xclsht.Cells(i,1).Value

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

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02").select

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,0]").text = xclsht.Cells(i,2).Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,0]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,0]").caretPosition = 0

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,6]").text = "XXXXXX"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3,6]").text = "1"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-VRKME[4,6]").text = "EA"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,6]").text = xclsht.Cells(i,3).Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-PSTYV[7,6]").text = "ZP13"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-UEPOS[2,6]").text = "20"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-WERKS[8,6]").text = "85MP"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-PS_PSP_PNR[9,6]").text = xclsht.Cells(i,4).Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,6]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,6]").caretPosition = 10

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,6]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,6]").caretPosition = 12

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07").select

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN").verticalScrollbar.position = 11

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/ctxtKOMV-KSCHL[1,9]").text = "zpvp"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,9]").text = xclsht.Cells(i,5).Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,9]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,9]").caretPosition = 16

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\06").select

session.findById("wnd[1]").close

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-AFDAT[0,0]").text = xclsht.Cells(i,6).Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAREG[9,0]").text = "3"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAREG[9,0]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAREG[9,0]").caretPosition = 1

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAKSP[7,0]").text = ""

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAKSP[7,0]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAKSP[7,0]").caretPosition = 0

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\16").select

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\16/ssubSUBSCREEN_BODY:SAPMV45A:4462/subKUNDEN-SUBSCREEN_8459:SAPMV45A:8459/ctxtVBAP-ZZSMC").text = "o"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\16/ssubSUBSCREEN_BODY:SAPMV45A:4462/subKUNDEN-SUBSCREEN_8459:SAPMV45A:8459/ctxtVBAP-ZZSMC").caretPosition = 1

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

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

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

 

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

i = i + 1

Wend

 

 

 

 

Next

 

 

xclwbk.save

 

 

msgbox "Document Saved"

 

Set xclwbk = Nothing

Set xclsht = Nothing

xclapp.Quit

set xclapp = Nothing

 

 

Thanks for all your help in advance.

 

Sushil

Automation of SAP Netweaver portal

$
0
0

'Automating the SAP netweaver portal - The Everest of Automation!

'

'There are a few articles on the web discussing the automation of the SAP Portal - some even saying its a myth.

'

'Ok it is possible using VBA..(Excel). Could be adapted for vb script.

'

'This assumes you have some knowledge of HTML DOM and general automation.

'

'

'1. Get the URL of your portal. Sometimes the portal window does not display the address bar.

'This example will get the URL of a window with "Home - SAP NetWeaver Portal" (depending on your env).

'Open a portal and run this function.

 

 

Debug.Print oGetPortal.LocationURL

 

Function oGetPortal( _

Optional sWindowTitle AsString = "Home - SAP NetWeaver Portal" _

) AsObject

 

 

   Set objShellApp = CreateObject("Shell.Application")

   ForEach objWindow In objShellApp.Windows

  DoEvents

   If LCase(objWindow.LocationName) = LCase(sWindowTitle) Then

   Set oGetPortal = objWindow

   ExitFor

   EndIf

   Next

   Set objShellApp = Nothing

   Set objWindow = Nothing

EndFunction

 

 

'2 For automation you probably want to create a new instance of the IE portal rather than attach to

'an existing window. The Portal often runs on an intranet.

'In windows 7 the IE object automatically detaches from intranet pages - not very useful for automation.

'

'So the below code works around this issue & should work on earlier windows versions and non intranet pages

'it also opens up the portal in an IE window with an address bar and is easier to get access to the IE developer tools.

 

 

Debug.Print oGetLatestPortal.LocationURL

 

PrivateDeclareSub Sleep Lib"kernel32" (ByVal dwMilliseconds AsLong)

PrivateDeclareFunction GetForegroundWindow Lib"user32" () AsLong

Function oGetLatestPortal( _

  Optional sURL AsString = "http://myportalpath/portal#", _

  Optional sWindowTitle AsString = "Home - SAP NetWeaver Portal") AsObject

 

   Dim IE As InternetExplorer

   Set IE = New InternetExplorer

   ' only works for about 5 portal windows

 

  IE.Navigate sURL

   Dim hwnd AsLong

  hwnd = GetForegroundWindow() ' get latest IE window

   Set IE = Nothing  ' work around for windows 7 issue

 

  i = 0

   DoWhile i < 10And IE IsNothing

 

  i = i + 1

   Set objShellApp = CreateObject("Shell.Application")

   ForEach objWindow In objShellApp.Windows

  DoEvents

   If LCase(objWindow.LocationName) = LCase(sWindowTitle) Then

       If objWindow.hwnd = hwnd Then'active IE window if more than one with same title

                Set IE = objWindow

       EndIf

     EndIf

   Next

  DoEvents

  Sleep 100

   Loop

 

 

   If IE IsNothingThen

  MsgBox "nothing"

ExitFunction

  End If

 

   Set oGetLatestIE = IE

 

EndFunction

 

'3. Wait for IE page to load. You cannot do any automation until after

'the page is loaded. This function returns true if the page or frames top level is loaded (frames discussed later)

 

Debug.Print lWait(oGetLatestPortal)

 

Function lWait(LOIE AsObject) AsBoolean

  Dim t1 AsLong

  Dim t2 AsLong

  OnErrorResumeNext

  t1 = Timer

  t2 = t1 + 60

  Do

   If Timer > t2 Then lWait = False: ExitFunction

  If VarType(LOIE.Document) = vbString ThenExitDo

  Loop

  Do

   If Timer > t2 Then lWait = False: ExitFunction

  If LOIE.Busy = FalseThenExitDo

  Loop

  Do

   If Timer > t2 Then lWait = False: ExitFunction

  If VarType(LOIE.Document.readyState) = "C"ThenExitDo

  Loop

  Do

   If Timer > t2 Then lWait = False: ExitFunction

  If LOIE.Document.readyState = "complete"ThenExitDo

  Loop

  lWait = True

EndFunction

 

 

'4. Using developer tools in IE8+ (F12) with the window you just opened using the above code.

'Use the IE inspect tool (arrow) to click on the field or link/field/button you want to automate. This will

'expand the HTML DOM and show the HTML tag corresponding to the field. If you can see the tag you can automate

'it! But it can be tricky.

'

'5. Clicking on a link. Now that you have open a portal window you want to do something usually click on a link.

'Using the developer tools in IE. Find the link you want. If the link you want is inside a HTML form or frame

'tag see further on.

 

 

lWait IE

Set link = IE.Document.getElementById("MyLink_1_1")

link.Click

 

 

' Waiting for elements to appear.

'

' Even though you call lWait and IE is ready, the portal may be doing things. eg.

' displaying spinners (etc) Sometimes you must wait for the element to appear.

' Note elements can be forms, frames, links or fields or anything.

'

' safer way to get a element that will wait until it appears

Dim element AsObject

Dim t1 AsLong

Dim t2 AsLong

 

t1 = Timer

t2 = t1 + 10' secs

 

While element IsNothing

  DoEvents

   If Timer > t2 Then

  MsgBox "timeout"

   ExitDo

   EndIf

' note, IEdoc can be IE.Document, SubFrame.contentWindow.Document or SubForm.Document (discussed later)

 

   Set element = IEdoc.getElementById("elementid")

 

Wend

 

'If you still have problems try to get an element preceeding the element you want

'Use the VB debugger and also put sleeps in and use while loops as shown also you must get any

' forms or frames preceeding the element.

'

'

'

'6. Elements in Forms or Frames

'If you still can't get the element by elementbyid or by looping through getElementsByTagName,

'It could be because the field you want is in a form or frame.

'You should get a reference to any forms or frame preceeding the element first. Use F12 developer tools

'to find out if there are any precedding forms or frames.

 

 

'6 a.HTML frames

'Get an obj reference to a html frame

 

Dim subframe1 AsObject

' Assuming you have any preceeding Forms or Frames

Set subframe1 = IE.Document.getElementById("frameid") ' example

 

lWait subframe1.contentWindow

 

'Once you get a obj reference to a frame you must get the sub document

'before you can do any further searches

 

Dim myframedocument AsObject

Set myframedocument = subframe1.contentWindow.Document

 

Set subframe2 = myframedocument.getElementById("frameid2") ' example

 

'

'6b HTML forms

'

'A HTML Form is similar, again you must get any preceeding Forms or Frames

Dim subform AsObject

Set subform = IE.Document.getElementById("formid") ' example

 

Dim myformdocument AsObject

Set myformdocument = subform.Document

 

Set mylink = myformdocument.getElementById("mylink") ' example

 

 

'7.Dynamic Content. In the portal HTML elements id's can change depending on the context ie whether certain

'sections are data driven or due to different user's role, certain elements are displayed. In the previous

'example Link_1_1 might be a different menu option on one users login to another. So in these cases

'you need to write more generic code. 2 examples.

'

' using a tags attributes

For k1 = 0To IE.Document.links.Length - 1

   If IE.Document.links.Item(k1).getAttribute("title") = "Show Attachments"Then

 

 

IE.Document.links.Item(k1).Click

ExitFor

 

   EndIf

 

Next k1

 

 

' Loop through a table looking for a link's screen text

Set oTbl = IE.Document.getElementById("myNavigationTable")

Set oTBody = oTbl.getElementsByTagName("TBODY").Item(0)

Set oTRow = oTBody.getElementsByTagName("TR").Item(0)

Set oTds = oTRow.getElementsByTagName("TD")

 

ForEach oTd In oTds

  DoEvents

   If InStr(oTd.innertext, "Link Text") > 0Then

   Set link = oTd.getElementsByTagName("A").Item(0)

   ExitFor

   EndIf

 

Next oTd

link.Click

 

 

 

'8.If you hit a back button element on a page you might have to

're-establish VB objects in your code as sometimes they lose reference.

'

'9.Finally this is not a turn key solution - ideally a function could be written to find a control

'by searching the DOM tree handling all frames and forms and waits

'

'I hope this post helps

Vba Work in diferent SAP mods

$
0
0

Hello, please i need help with a vba code, im currently working with iw32 transaction to count materials in te cost centers of the diferent areas, and ive developed a code to simplify this process; however i want to be able to open an amount of sap mods and be able to work with each of them at once, but evry time i open a new mod, the macro keeps on working with the previous one, can anybody help me with this!

 

Thanks

Focus on SAP window using VBA

$
0
0

Hi Im new here.

Can somebody help me with excel and SAP junction through VBA? I beg for help with focusing on another window during script being processed. Its SAP window. Its SAP ARP - transaction CO02 - change of order - adding an attachment. Im in the final step where small import window pops up and I just need to insert or search for the path of the file I want to add. Its kind of microsoft window - on the left are large buttons with desktop, documents and 2-3 more. But its called Import on the left upper corner. I want to use the sendkeys prompt - the path will be allways the same eg C:\File\xxx.pdf. So I thought it will be very easy just call the macro recorded in sap until the window shows, then sendkeys "C:\File\xxx.pdf" then continue with SAP macro to okay it and save - end.

Problem is when the window show and I sendkeys - it does not write anything in path box. When i run the macro until the window shows and type something on kb it write normally in the box.

 

Can somebody help me please with this? Ive tried an application"focus" ("microsoft") prompt (quotes are for I cant remember the exact phrase I dont have the excel and file with macro here or SAP) It does not help... maybe because its not windows window but SAP window.

Windows 7, Office 2007, work computer - so I dont have access to all OS features, but I think it does not matter. 

If somebody can tell me how the prompt is called in sap, then it will be easy: Something like: findbyID.......importwindow.input.text = the way to the file...

:

Thanks very much for your replies.

Mirek


GUI script in transaction EPRODCUST via Excel VBA

$
0
0

I am attempting to script transaction EPRODCUST for test data setup. The data entry recording works flawlessly, so thats nice. IE:

Session.findById("wnd[0]/usr/cntlCC_PARAM_LIST/shellcont/shell").modifyCell 1, "VALUE", DATEFROM

This will correctly place my test data into the cell of the referenced MDT.

 

My issue arises when I "press" the get key button in the toolbar, then attempt to read the created key out of the grid for later reference.

 

The recording has an unfamiliar syntax, & Google isn't super useful in helping interpret where I'm going wrong.

 

Session.findById("wnd[0]/usr/cntlCC_PARAM_LIST/shellcont/shell").Cell 6, "VALUE"

 

How do I read the contents of this cell into a variable?

I've tried TESTVAR = Session.findById("wnd[0]/usr/cntlCC_PARAM_LIST/shellcont/shell").Cell 6, "VALUE" & it fails syntax check.

 

Apparently I know just enough to get myself into trouble...

Im more familiar with the syntax:

Session.findById("wnd[2]/usr/tblSAPLSZA6T_CONTROL2/txtADTEL-REMARK[6,0]").Text

where I declare the cell reference completely & use ".text" to read its contents.

 

cheers.

Control Visualizer

$
0
0

Hello community,

 

we all know the good old Scripting Wizard, which is not longer supported since Windows 7 and SAP GUI for Windows 7.20 PL?.

 

But SAP offers a Control Visualizer, maybe a replacment.

 

If you press the buttons  Ctrl  +  Shift  +  Z at the same time, it opens an additional window, called CMyControl Visualizer.

Hint: It is the Z key on keyboard with German keyboard layout.

 

Visualizer.jpg

You got the field name, the style, the content and some other technical stuff about the selected control.

I am not really sure if this is a replacment, but it seems a little bit.

 

Hint: It works not with any screen and it is not very stable.

 

Cheers

Stefan

How to relate the SAP objects with VBA programming?

$
0
0

Hi folks,

 

 

I am new to SAP.I was looking to automate some reports from SD modules.I want to know that Is it possible to work on SAP objects through VBA programming? If yes,tell me how to explore the SAP objects.

 

 

With Regards,

Hemanth chalamalasetti

Reading Excel Cell values using VB script

$
0
0

Hi All,

 

I am currently try to work on a blog where its aim to input the values from excel and based on the values it has to get the values from DB in sap and display it in the Output portion of the excel as mentioned in the following blog http://scn.sap.com/docs/DOC-31015. I have created the FM and done the basic things mentioned in the blog but I am facing an error "Run Tme Error '40036' Application-defined or object-defined error". Please find my code below and help to resolve the issue.

Attachment.png

With Regards,

Giriesh M

How to connect Access VBA with a customer specific function module using RFC

$
0
0

Hello,

 

I try to fetch some data from our SAP ERP system by using a customer specific function module.

The connection via RFC is working. Unfortunately, after trying to add the SAP function module to the connection, the result is still nothing.

 

I have a VBA function for the connection. The return value of this function is the working connectin to SAP system.

 

Private Function sapConnect() As Object
'---------------------------------------------------------------------------------------
' Procedure : sapConnect
' Author    : Steffen Retz
' Date      : 22.11.2013
' Purpose   :
'---------------------------------------------------------------------------------------
'
Dim sapConnection   As Object
Dim sapFunction     As Object
Dim RetVal          As Variant
Dim ME5             As Variant
Dim strSAP_System   As String   On Error GoTo sapConnect_Error
'Set sapConnect = False
Set sapFunction = CreateObject("SAP.Functions")
Set sapConnection = sapFunction.Connection
With sapConnection    .ApplicationServer = "xx.xxx.xx.xx"    .SystemNumber = xxx    .System = "xxx"    .client = "xxx"    .Language = "EN"    .User = m_strcUserName 'InputBox("Please insert your SAP user name", "SAP Connection: User")    '.Password = InputBox("Please insert you SAP password", "SAP Connection: Password")    RetVal = SysCmd(acSysCmdSetStatus, "Connecting to " & strSAP_System & " . . . ")            If .logon(0, True) <> True Then        If .logon(0, False) <> True Then            'No connection -> Error            .LastError             Exit Function        End If                Set sapConnect = sapFunction    End If    
End With
sapConnect_Exit:    On Error Resume Next    Exit Function    
sapConnect_Error:    Err.Number = vbObjectError + 1    Err.Source = m_strcClassName    Err.Description = "Error" & " <<>> " & Err.Description    LogError Err, Critical, "sapConnect"    GoTo sapConnect_Exit       On Error GoTo 0
End Function

 

The other function is using the returning connection to retrieve the data from the SAP system.

After adding the function module to the connection, I recognized that the object MyFunc is still empty.

 

Set MyFunc = R3.Add("Z_ZZMHP_HR_SAP_NOTES_READ")

 

I also tried this with RFC_READ_TABLE and BAPI_USER_GETLIST. Both function are working.

 

 

Private Function RFC_SAP_NOTES_READ(sapConnection As Object, arrSAPNotes As Variant) As Boolean
'---------------------------------------------------------------------------------------
' Procedure : RFC_SAP_NOTES_READ
' Author    : Steffen Retz
' Date      : 03.12.2013
' Purpose   : FM in SAP: Z_ZZMHP_HR_SAP_NOTES_READ
'---------------------------------------------------------------------------------------
'
 Dim strTemp As String
 Dim RetVal As Variant, nSecondsLeft As Long, nTotalSeconds As Long
 Dim R3, MyFunc, App As Object
 Dim j As Integer
' Define the objects to hold IMPORT parameters
 Dim IT_SAP_NOTES_KEY As Object
' Define the objects to hold the EXPORT parameters
 Dim ZZMHP_TT_HR_SAP_NOTES_ERRORMSG As Object
 Dim ET_SAP_NOTES As Object
 ' Use to write out results
 Dim ROW As Object
 Dim Result As Boolean
 Dim iRow, iColumn, iStart, iStartRow, iField, iLength As Integer   On Error GoTo RFC_SAP_NOTES_READ_Error
If sapConnection Is Nothing Then    Set R3 = sapConnect
Else    Set R3 = sapConnection
End If
 '*****************************************************
 'Call RFC function Z_ZZMHP_HR_SAP_NOTES_READ
 '*****************************************************
 Set MyFunc = R3.Add("Z_ZZMHP_HR_SAP_NOTES_READ")
'EXPORTS
Set IT_SAP_NOTES_KEY = MyFunc.exports("IT_SAP_NOTE_KEY")
IT_SAP_NOTES_KEY.Value = arrSAPNotes
'IMPORTS
Set ZZMHP_TT_HR_SAP_NOTES_ERRORMSG = MyFunc.imports("ZZMHP_TT_HR_SAP_NOTES_ERRORMSG")
Set ET_SAP_NOTES = MyFunc.imports("ET_SAP_NOTES")
 RetVal = SysCmd(acSysCmdSetStatus, "Extracting " & j & " . . . ")
MyFunc.Call
' Result = MyFunc.Call
' If Result = True Then
'     Set DATA = MyFunc.Tables("DATA")
'     Set FIELDS = MyFunc.Tables("FIELDS")
'     Set OPTIONS = MyFunc.Tables("OPTIONS")
' Else
'     MsgBox MyFunc.EXCEPTION
'     R3.Connection.LOGOFF
'     Exit Function
' End If      
 Close #2
 RetVal = SysCmd(acSysCmdRemoveMeter)
 RFC_SAP_NOTES_READ = True
RFC_SAP_NOTES_READ_Exit:    On Error Resume Next    Exit Function    
RFC_SAP_NOTES_READ_Error:    RFC_SAP_NOTES_READ = False    Err.Number = vbObjectError + 1    Err.Source = m_strcClassName    Err.Description = "Error" & " <<>> " & Err.Description    Debug.Print Err.Description    LogError Err, Critical, "RFC_READ_TABLE"    GoTo RFC_SAP_NOTES_READ_Exit       On Error GoTo 0
End Function

I can't find the error. Do I have to use a specific method for a customer specific fuction module?

Or is it not possible to use a customer specific function module?

 

Thanks for any help.

 

Best regards,

 

Steffen

Bebo, a Control and Activity Pad with Script Support for SAP Sessions

$
0
0

Hello community,

 

a long time ago I introduced Bebo here. Now a little refresh and reminder, because I develop Bebo since three years and it is a very reliable and  stable product. Bebo is a small utility to watch, navigate and control all SAP sessions. With Bebo you see all sessions clearly arranged in a tree. Also you can direct execute a transaction or a script to the selected session. The available transaction codes and other possibilities are an easy and individual customizing in a preference file. With Bebo you can organize your favorite transaction codes, activities and scripts in a tree as you want - one time for all application servers. Bebo helps you in the jungle of sessions and connections - it is a point of view.

 

Bebo is freeware and you can find it here.

 

2013/12/25: New version 3.37 of Bebo is available

  • The TAC SM34 maintain cluster is now a build in command.
  • The TAC SE16 view table has now its own icon, to help distinguish.

 

Suggestions and comments are welcome.

 

Cheers

Stefan

How to Info record long text with VBA

$
0
0

I am very new to VBA and I am trying to create a macro to copy the contents of an existing PIR in ME13 and create a new PIR in ME11.

I can get my macro (excel VBA) to copy all of the fields except for the two text fields. Can someone show me an example of how to copy the long text?

 

I have searched for answers in the forums but have not found any that I can make sense of.  I have never used or accessed the tables that I have seen referenced.

 

Any help would be greatly appreciated.


How an SAP GUI Script is Executed

$
0
0

Hello community,

 

there are several ways to execute an SAP GUI script:

 

  1. Via SAP GUI recorder, press Alt+F12, now choose the menu item Script Recording and Playback, load the script file and press Playback button.
  2. Via Drag'n'Drop with the script file to the session where the script should be executed.
  3. Via double click on the script file in the Windows Explorer.
  4. Via the command line in a console window with the command wscript.exe or cscript.exe and the name of the script file.

 

This are four ways but technically this are only two ways. One and two works technically equal, also as three and four.

 

One and two executes the script via MSScriptControl. This means that the SAP GUI for Windows instanciate the class MSScriptControl.ScriptControl from the msscript.ocx library and executes the SAP GUI Script as statement - I think.

 

To check it out I create the following test script:

 

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

 

  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]/tbar[0]/okcd").text = "/nSE16"

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

 

  WScript.Sleep 500

  WScript.Echo "Test"

 

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

 

The reaction with one and two are

001.JPG

To see reaction in a simulated context of SAP GUI for Windows I create the following test script:

 

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

 

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

    Option Explicit

 

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

    Dim ScrCtrl, Cmd

 

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

    Set ScrCtrl = CreateObject("MSScriptControl.ScriptControl")

    If IsObject(ScrCtrl) Then

 

      ScrCtrl.AllowUI = vbTrue

      ScrCtrl.Language = "VBScript"

 

      Cmd = "WScript.Echo ""Hello World"""

      ScrCtrl.ExecuteStatement Cmd

 

    End If

 

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

 

The reaction is the same as one and two

 

002.JPG

This knowledge gives us now a good base to understand the behaviour of the different executions forms better. On the one hand via MSScriptControl, on the other hand via WScript.

 

Hint: If you work with WScript you must define the connection (application.Children(x)) and session (connection.Children(y)) with correct values - here x and y as example. The standard defines always 0 - which means connection 0 and session 0, the first connection and session in the pool of all open connections and sessions.

 

Cheers

Stefan

A Look Behind the Curtain - Lift the veil from saplogon.exe

$
0
0

Hello community,

 

the SAP logon program saplogon.exe is the centre of rotation of all communication between the SAP GUI for Windows and the SAP application server. The SAP logon is the one and only. If you want to know more details about the activities of the saplogon.exe process, you have the possiblity to use Microsofts Process Monitor from www.sysinternals.com. Set the filter to the process name saplogon.exe.

 

001.JPG

If you activate the capture, you can see a lot of details of activities of the following operation areas:

  1. Access to the file system.
  2. Access to the registry.
  3. Monitoring of the process and its threads, also DLL and device driver access.
  4. Network activities.

 

With this way it is e.g. very easy to detect the procedure of the execution of a SAP GUI Script via the playback function of the SAP GUI Scripting recorder - see also here.

002.JPG

If you want to know and to learn more about the activities of the saplogon.exe process, use the Process Monitor. It is very good to understand how a lot of things work.

 

Cheers

Stefan

Is it possible to use RFC_READ_TEXT using existing connection??

$
0
0

Hello all!  I am new to VBA and know very little, your assistance is greatly apprecitated.

I am trying to create a macro that will copy long texts from a PIR.  The only way I have found to do it so far is using RFC_READ_TEXT.

My macro starts out using a SAP screen/connection that I already have open but when it gets to the RFC_READ_TEXT it wants me to sign in again.

Is there another way to call the read_text function module that will use my pre-existing conection?

Here is what I haave so far.

 

Sub pirCopier()

Dim Application, SapGuiAuto, Connection, session
Dim SID, bh1Wnd, CollCon, i, CollSes

Dim materialGroup
Dim vendor
Dim orderUnit
Dim sortTerm
Dim piDelivTime
Dim shippgInstr
Dim condition1
Dim condition2
Dim condition3
Dim condition4
Dim condition5
Dim description
Dim noteText
Dim poText


Set SapGuiAuto = GetObject("SAPGUI")
Set Application = SapGuiAuto.GetScriptingEngine
  Set CollCon = Application.Connections()
      If Not IsObject(CollCon) Then
        Exit Sub
      End If

 

'- Find R3 window -------------------------------------------
        For i = 0 To CollCon.Count() - 1

          Set Connection = Application.Children(CLng(i))
          If Not IsObject(Connection) Then
            Exit Sub
          End If

          Set CollSes = Connection.sessions()
          If Not IsObject(CollSes) Then
            Exit Sub
          End If
       
                    Set session = Connection.Children(0)
                    SID = session.info.systemname()
                   If Not IsObject(bh1Wnd) Then
                    If SID = "BH1" Then Set bh1Wnd = Application.Children(CLng(i)) 'R3
                   End If
        Next

If Not IsObject(bh1Wnd) Then
MsgBox "SAP R/3 window not found. Please open at least on session of SAP R/3."
Exit Sub
End If

 

'-------------- start pirCopier -------------

Set Connection = bh1Wnd
Set session = Connection.Children(0)

'open pir to be copied
session.findById("wnd[0]/tbar[0]/okcd").text = "/nME13"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/radRM06I-NORMB").Select
session.findById("wnd[0]/usr/ctxtEINA-LIFNR").text = ""
session.findById("wnd[0]/usr/ctxtEINA-MATNR").text = ""
session.findById("wnd[0]/usr/ctxtEINE-EKORG").text = "1001"
session.findById("wnd[0]/usr/ctxtEINE-WERKS").text = "0002"
session.findById("wnd[0]/usr/ctxtEINA-INFNR").text = Range("B2")
session.findById("wnd[0]/usr/radRM06I-NORMB").SetFocus
session.findById("wnd[0]").sendVKey 0

vendor = session.findById("wnd[0]/usr/ctxtEINA-LIFNR").text
desciption = session.findById("wnd[0]/usr/txtEINA-TXZ01").text
orderUnit = session.findById("wnd[0]/usr/ctxtEINA-MEINS").text
sortTerm = session.findById("wnd[0]/usr/txtEINA-SORTL").text
session.findById("wnd[0]/tbar[1]/btn[7]").press
piDelivTime = session.findById("wnd[0]/usr/txtEINE-APLFZ").text
shippgInstr = session.findById("wnd[0]/usr/ctxtEINE-EVERS").text
session.findById("wnd[0]/tbar[1]/btn[8]").press


'--- start of copy long texts ---------------------------------------------

Set funcControl = VBA.CreateObject("SAP.Functions")
Set RFC_READ_TEXT = funcControl.Add("RFC_READ_TEXT") '<------------ This is where it wants me to re sign in
Set tblText_Lines = RFC_READ_TEXT.Tables("TEXT_LINES")

 

'----- copy po long

 

text from pir ---------

tblText_Lines.AppendRow
tblText_Lines(1, "TDOBJECT") = "EINE"
tblText_Lines(1, "TDNAME") = Range("B2") & "100100002"
tblText_Lines(1, "TDID") = "BT" 'PO text

If RFC_READ_TEXT.Call = True Then
   
        If tblText_Lines.RowCount > 0 Then
   
            For intRow = 1 To tblText_Lines.RowCount ' Change Next line to write a different header row
       
                If intRow = 1 Then
                poText = tblText_Lines(intRow, "TDLINE")
                Else
                poText = poText & vbCrLf & tblText_Lines(intRow, "TDLINE")
                End If
            Next
        Else
       
            GoTo poTextEnd
   
        End If

    Else

        MsgBox "ERROR CALLING SAP REMOTE FUNCTION CALL FOR PO TEXT"

    End If
   
    'Result Table set back
Do Until tblText_Lines.RowCount = 0
     Call tblText_Lines.rows.Remove(1)
Loop

poTextEnd:


End Sub

VBS Input Data Into Shell Container (Long Text Editor)

$
0
0

Greetings,

 

I am having an issue with using VBS to place text within shell container. Transaction CG12, create a phrase, click phrase item, then double click on your entered phrase text to open the long text editor. Trying to make script write to this word application within the SAP GUI, haven't had much luck. If you're a script master please assist. A simple subset of the code is below, simply get the focus within the window to set text using hard coded text or a variable.

 

Can run this script after navigating to CG12 if you like.

 

CG12_longtext_editor.png

Sub Phrase_Load()

 

If Not IsObject(App) Then

   Set SapGuiAuto = GetObject("SAPGUI")

   Set App = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(Connection) Then

   Set Connection = App.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 App, "on"

End If

 

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

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

session.findById("wnd[0]/usr/ctxtRCGPHIOT-PHRGRP").Text = "GRAPHIC"

session.findById("wnd[0]/usr/txtRCGPHIOT-PHRTEXT").Text = "Jelly beans on the sidewalk"

session.findById("wnd[0]/usr/txtRCGPHIOT-PHRTEXT").SetFocus

session.findById("wnd[0]/usr/txtRCGPHIOT-PHRTEXT").caretPosition = 5

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

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

session.findById("wnd[0]/usr/tblSAPLC115LG_IOTAB_CTR/txtRCGPPIOT-PHRTEXT[1,3]").SetFocus

session.findById("wnd[0]/usr/tblSAPLC115LG_IOTAB_CTR/txtRCGPPIOT-PHRTEXT[1,3]").caretPosition = 23

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

container_text = session.findById("wnd[0]/usr/cntlSCMSW_CONTAINER_2102/shellcont/shell").Text

'session.findById("wnd[0]/usr/cntlSCMSW_CONTAINER_2102/shellcont/shell").setDocument 1, "SAP.DocumentContainerControl.1"

 

End Sub

How to use Windows PowerShell Script inside ABAP

$
0
0

Hello community,

 

Windows PowerShell is a mix of command-line shell and scripting language. You find more Information about PowerShell here and here.

 

With the free COM library ActiveXPosh.dll from SAPIEN you can also use PowerShell inside ABAP.

 

Here an example how to get all services and its state.

 

"-Begin-----------------------------------------------------------------
  Program zPSTest.

    "-TypePools---------------------------------------------------------
      Type-Pools OLE2 .

    "-Constants--------------------------------------------------------
      Constants OUTPUT_CONSOLE Type i Value 0.
      Constants OUTPUT_WINDOW Type i Value 1.
      Constants OUTPUT_BUFFER Type i Value 2.

    "-Variables---------------------------------------------------------
      Data PS Type OLE2_OBJECT.
      Data Result Type i Value 0.
      Data strResult Type String Value ''.
      Data tabResult Type Table Of String.

    "-Main--------------------------------------------------------------
      Create Object PS 'SAPIEN.ActiveXPoSH'.

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

        Call Method Of PS 'Init' = Result Exporting #1 = 0.

        If Result = 0.

          Call Method Of PS 'IsPowerShellInstalled' = Result.

          If Result <> 0.

            Set Property Of PS 'OutputMode' = OUTPUT_BUFFER.

            Call Method Of PS 'Execute' Exporting
              #1 = 'Get-WmiObject -class Win32_Service | Format-Table -property Name,State'.

            Call Method Of PS 'OutputString' = strResult.

            Split strResult At cl_abap_char_utilities=>cr_lf
              Into Table tabResult.

            Loop At tabResult Into strResult.
              Write: / strResult.
            EndLoop.

          EndIf.

        EndIf.

        Free Object PS.
      EndIf.

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

 

You can use with PowerShell all dotNET and Windows standard libraries. On this way you can extend your possibilities.

 

Cheers

Stefan

Viewing all 522 articles
Browse latest View live