Quantcast
Channel: SCN : Discussion List - Scripting Languages
Viewing all 325 articles
Browse latest View live

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.


Input from Excel to SAP - make cycle.

$
0
0

Hi masters.

Could someone help me with my different problem...again?

now Im working in trscn QM02. Excel create numbers of lines and add part number, then it fills long text of each part number... Script looks like this:

 

                                                                
                                                               
                                                               
                                       

Private Sub ITEMS_Click()

Dim App, Connection, session As Object

Set SapGuiAuto = GetObject("SAPGUI")

Set App = SapGuiAuto.GetScriptingEngine

Set Connection = App.Children(0)

Set session = Connection.Children(0)

 

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

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

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

session.findById("wnd[0]/usr/ctxtRIWO00-QMNUM").Text = Range("L37").Value

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

session.findById("wnd[0]/usr/tabsTAB_GROUP_10/tabp10\TAB10").Select

 

session.findById("wnd[0]/usr/tabsTAB_GROUP_10/tabp10\TAB10/ssubSUB_GROUP_10:SAPLIQS0:7210/tabsTAB_GROUP_20/tabp20\TAB01/ssubSUB_GROUP_20:SAPLIQS0:7110/tblSAPLIQS0POSITION_VIEWER/ctxtVIQMFE-BAUTL[9,0]").SetFocus

Application.Wait DateAdd("s", 1, Now)

Range("C2:C25").Copy   '''''''''Add part numbers...thats ok

SendKeys "^v", True

Application.Wait DateAdd("s", 1, Now)

session.findById("wnd[0]/usr/tabsTAB_GROUP_10/tabp10\TAB10/ssubSUB_GROUP_10:SAPLIQS0:7210/tabsTAB_GROUP_20/tabp20\TAB01/ssubSUB_GROUP_20:SAPLIQS0:7110/tblSAPLIQS0POSITION_VIEWER/txtVIQMFE-POSNR[0,0]").SetFocus

Application.Wait DateAdd("s", 1, Now)

Range("Q2:Q25").Copy '''''''''Add numbers of lines...thats ok

SendKeys "^v", True

Application.Wait DateAdd("s", 1, Now)

SendKeys "{ENTER}", True

 

'' Now it opens first line long text and insert the value of copied cell.

 

session.findById("wnd[0]/usr/tabsTAB_GROUP_10/tabp10\TAB10/ssubSUB_GROUP_10:SAPLIQS0:7210/tabsTAB_GROUP_20/tabp20\TAB01/ssubSUB_GROUP_20:SAPLIQS0:7110/tblSAPLIQS0POSITION_VIEWER/btnQMICON-LTFEHLER[8,0]").SetFocus

session.findById("wnd[0]/usr/tabsTAB_GROUP_10/tabp10\TAB10/ssubSUB_GROUP_10:SAPLIQS0:7210/tabsTAB_GROUP_20/tabp20\TAB01/ssubSUB_GROUP_20:SAPLIQS0:7110/tblSAPLIQS0POSITION_VIEWER/btnQMICON-LTFEHLER[8,0]").press

Application.Wait DateAdd("s", 1 / 3, Now)

Range("G2").Copy

SendKeys "{PGDN}"

Application.Wait DateAdd("s", 1, Now)

SendKeys "^v", True

Application.Wait DateAdd("s", 1 / 3, Now)

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

 

''First Long text is filled. Now I have the same script but it focus on second row/line long text in sap and takes value from next cell in excel:

 

session.findById("wnd[0]/usr/tabsTAB_GROUP_10/tabp10\TAB10/ssubSUB_GROUP_10:SAPLIQS0:7210/tabsTAB_GROUP_20/tabp20\TAB01/ssubSUB_GROUP_20:SAPLIQS0:7110/tblSAPLIQS0POSITION_VIEWER/btnQMICON-LTFEHLER[8,1]").SetFocus

session.findById("wnd[0]/usr/tabsTAB_GROUP_10/tabp10\TAB10/ssubSUB_GROUP_10:SAPLIQS0:7210/tabsTAB_GROUP_20/tabp20\TAB01/ssubSUB_GROUP_20:SAPLIQS0:7110/tblSAPLIQS0POSITION_VIEWER/btnQMICON-LTFEHLER[8,1]").press

Application.Wait DateAdd("s", 1 / 3, Now)

Range("G3").Copy

SendKeys "{PGDN}"

Application.Wait DateAdd("s", 1, Now)

SendKeys "^v", True

Application.Wait DateAdd("s", 1 / 3, Now)

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

.......

""And so on 24times...

 

End Sub

 

 

So is there a way how to make a loop in SAP, when I have for example 5 part numbers to have just one of this block - something like i, For and Loop function in excel? Its working now but there is error when it comes to row/line in SAP where it isnt long text (which is created by entering a number of line and adding PN, so 6th line in this case). Using error handler I jump to another command to save the inserted values in SAP and everything is OK, but I find it extremely unpractical, loooong and unsafe due other errors that may occur.

 

If there is a thread with this problem I will be pleased to just link me there or explain here.

And as usual thanks in advance for your effort and time.

VB Script: check for existing open session

$
0
0

I use the code below often.  It is part of many automated processes I call from some function modules in Access as a step in a macro.  As the code is written now, it kills any existing connection or session and logs me in and runs whatever procedures I have.  The problem with this is I also work in SAP throughout the day and my automated script kicks me out periodically.  I can have up to 5 sessions open at once.  I have no clue how to make the script below do the following:

1. First, check if an open session exists.

2. If a session exists, open a new one.

3. If 5 open sessions exist, pause and generate a message box alerting me that "5 sessions already exist"

 

 

Function GrabOrdersToday()

 

Dim Application As Variant

 

Set SapGuiAuto = GetObject("SAPGUI")

     Set Application = SapGuiAuto.GetScriptingEngine

     Set Connection = Application.OpenConnection("PRD")

     Set SapSession = Connection.Children(0)

 

If IsObject(WScript) Then

     WScript.ConnectObject SapSession, "on"

     WScript.ConnectObject Application, "on"

End If

 

SapSession.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "myuserid"

SapSession.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "mypassword"

SapSession.findById("wnd[0]/usr/pwdRSYST-BCODE").SetFocus

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

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

 

'In case you are already logged in...

If SapSession.Children.Count > 1 Then

     SapSession.findById("wnd[1]/usr/radMULTI_LOGON_OPT1").Select

     SapSession.findById("wnd[1]/usr/radMULTI_LOGON_OPT1").SetFocus

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

End If

 

...and then my actual script starts here where I run transactions or whatever I need.  I picked up this code a long time ago and it looks like it has some sort of If statement that is supposed to check for a login, but it doesn't.  Every time this code runs, it kills the existing session and logs me into SAP all over again.  I only want it to log me into SAP if no current session exists.  Thanks in advance for any help!

SAP CRM VBA Excel Macro, No data return

$
0
0

Dear experts and everyone else that feels in the mood to contribute,

 

I've been looking into some basic scripting when it comes to SAP and Excel. My legs are still unstable and I would see myself being in the start of a wonderful learning experience.

 

I've managed to establish a connection between MS Excel VB and SAP CRM Sandbox system using various forum posts and example codes from sdn. My next step would be to call a certain Function Module, pass some input parameters and then present the Export variables in a Excel sheet.

 

By looking at examples of this i've establish a theory but alas it does not work, hence I am asking for guidance on what I am doing wrong and how I could continue my newly started adventure.

 

As of now my code looks like this:

 

Sub CallFunctionModule()

 

'Declare the objects and variables

Dim functionCtrl As Object             'Function Control (Collective object)

Dim sapConnection As Object         'Connection object

Dim theFunc As Object                 'Function object

Dim Returnvalue As Boolean       'Used to check if data is returned

'Create a function object

 

Set functionCtrl = CreateObject("SAP.Functions")

Set sapConnection = functionCtrl.Connection

 

'**********************************************

'Create Server object and Setup the connection (The connection seems to be establish in a correct manner)

'**********************************************

sapConnection.Client = "000"

sapConnection.user = "USERID"

sapConnection.Language = "EN"

sapConnection.SystemNumber = "00"

sapConnection.Destination = "DEST"

sapConnection.System = "SYSTEM"

If sapConnection.logon(0, False) <> True Then

    MsgBox "No connection to R/3!"

    Exit Sub                                           'End program

End If

 

'*****************************************************

'Call function moduole

'*****************************************************

'Reference to a function object

Set theFunc = functionCtrl.Add("FUNC_MOD_NAME")

 

'Determine the import parameters for the function call

theFunc.exports("IMPORT1") = "1234"

theFunc.exports("IMPORT2") = "456"

Returnvalue = theFunc.Call

 

If Returnvalue = True Then

    MsgBox "SAP Data Found"

Else

    MsgBox theFunc.Exception

End If

 

End Sub

 

As of now I seemingly establish a connection and I am able to call the function module. But every time ReturnValue = false.

If I run the function module in SAP transaction SE37 with same parameters it executes successfully and export is created.

If I change the data for functionCtrl.Add("FUNC_MOD_NAME") or theFunc.exports("IMPORT1") i'll get error messages which to me would indicate that I am finding the function module and correctly refeering to the import parameters.

 

What am I missing here? Why is theFunc.Call always returning false? Does this mean I am not getting data or is there some other way of determining if data is correct? If I check declarations of Import parameters in the function modules I see they are declared as NUMC (Character string with only digits) which should accept String as valid input?

 

Any help on this is appriciated since i'm very much enjoying this new found playground.

 

Best Regards,

Ernst

Gathering MHTML reports

$
0
0

Dear All,

 

At the moment I am using SAP P12.

From T-code IW33 I am trying to gather data from MHTML.

I have tried to follow some scripts which looked fantastic, but just weren't able to apply to what I use.

The below is as far as I got.

 

 

 

Sub GetPlanCostData()
'---------------------------------
  '---------------------------------
' Parameters


'---------------------------------
   '-------- SAP LOGIN --------------
   '---------------------------------


    'If Right(CLPdirName, 1) <> "\" Then CLPdirName = CLPdirName & "\"

    On Error Resume Next

    If SAPApp Is Nothing Then
        Set SapGuiApp = GetObject("SAPGUI")
        Set SAPApp = SapGuiApp.GetScriptingEngine
       ' If SAPApp Is Nothing Then GoTo Exit_AllReport
    End If
    If Connection Is Nothing Then
        Set Connection = SAPApp.Children(0)
    End If
    If session Is Nothing Then
        Set session = Connection.Children(0)
    End If


    If Err = 0 Then flgSapIsOpen = True
    Err.Clear
   
    On Error GoTo 0

    If flgSapIsOpen = False Then
        Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
        Set Connection = SapGuiApp.OpenConnection(CLPsapName, True, False)
      '  If Connection Is Nothing Then GoTo Exit_AllReport
   '?     Set session = Connection.Children(0)

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

    End If

'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

'Start Processing in SAP
i = 2

Do While Cells(i, 1) <> ""


SO = Cells(i, 1)


session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/niw33"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").Text = SO
session.findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").caretPosition = 7
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpKOAU").Select
session.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1107/tabsTS_1100/tabpKOAU/ssubSUB_AUFTRAG:SAPLICO1:1100/btnPUSH1").press
session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").Select
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").Select
session.findById("wnd[1]/tbar[0]/btn[0]").press

 

i = i + 1
Loop

End Sub

 

 

 

I am very new to this, and I wanted to make something similar to what I was given some time ago.

Different t-code but gathers information I need.

 

Sub GetPlanCostData()
'---------------------------------
  '---------------------------------
' Parameters
FilePath = "C:\cemacro\"
'Sheets.Add.Name = "RESULTS"


' Clearthe folder
On Error Resume Next
    Kill "C:\cemacro\*.xls"
   On Error GoTo 0
On Error Resume Next
Kill "C:\cemacro\*.dat"
On Error GoTo 0

'---------------------------------
   '-------- SAP LOGIN --------------
   '---------------------------------
               
     Para_check = True
 
    CLPsapName = ActiveSheet.Range("F29").Value
    CLPuserid = ActiveSheet.Range("F30").Value
    CLPpasswd = ActiveSheet.Range("F31").Value
    'CLPdirName = ActiveSheet.Range("C5").Value
    CLPrptName = "Worksheet in Basis (1)"

    'If Right(CLPdirName, 1) <> "\" Then CLPdirName = CLPdirName & "\"

    On Error Resume Next

    If SAPApp Is Nothing Then
        Set SapGuiApp = GetObject("SAPGUI")
        Set SAPApp = SapGuiApp.GetScriptingEngine
       ' If SAPApp Is Nothing Then GoTo Exit_AllReport
    End If
    If Connection Is Nothing Then
        Set Connection = SAPApp.Children(0)
    End If
    If session Is Nothing Then
        Set session = Connection.Children(0)
    End If


    If Err = 0 Then flgSapIsOpen = True
    Err.Clear
   
    On Error GoTo 0

    If flgSapIsOpen = False Then
        Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
        Set Connection = SapGuiApp.OpenConnection(CLPsapName, True, False)
      '  If Connection Is Nothing Then GoTo Exit_AllReport
   '?     Set session = Connection.Children(0)

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

     

    End If

'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
'==============================================
'Clear out the status field in B-column
i = 2
Do While Cells(i, 1) <> ""
i = i + 1
Cells(i, 2) = ""
Loop

'==============================================

'Start Processing in SAP
i = 2

Do While Cells(i, 1) <> ""


WBS = Cells(i, 1)

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/ns_alr_87013542"
session.findById("wnd[0]").sendVKey 0

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

' Blank fields in screen
session.findById("wnd[0]/usr/ctxtCN_PROJN-LOW").Text = ""
session.findById("wnd[0]/usr/ctxtCN_PROJN-HIGH").Text = ""
session.findById("wnd[0]/usr/ctxtCN_VBELN-LOW").Text = ""
session.findById("wnd[0]/usr/ctxtCN_VBELN-HIGH").Text = ""
session.findById("wnd[0]/usr/ctxtCN_PSPNR-HIGH").Text = ""
session.findById("wnd[0]/usr/ctxtCN_NETNR-LOW").Text = ""
session.findById("wnd[0]/usr/ctxtCN_NETNR-HIGH").Text = ""
session.findById("wnd[0]/usr/ctxtCN_ACTVT-LOW").Text = ""
session.findById("wnd[0]/usr/ctxtCN_ACTVT-HIGH").Text = ""
session.findById("wnd[0]/usr/ctxtCN_MATNR-LOW").Text = ""
session.findById("wnd[0]/usr/ctxtCN_MATNR-HIGH").Text = ""
session.findById("wnd[0]/usr/ctxt$6-KOKRS").Text = "1000"
session.findById("wnd[0]/usr/ctxt$6-VERP").Text = "0"
session.findById("wnd[0]/usr/txt$6-GJAHV").Text = "2000"
session.findById("wnd[0]/usr/txt$6-GJAHB").Text = "2100"
session.findById("wnd[0]/usr/ctxt$6-PERBV").Text = "1"
session.findById("wnd[0]/usr/ctxt$6-PERBB").Text = "12"
session.findById("wnd[0]/usr/ctxt$6-KSTAR").Text = ""


session.findById("wnd[0]/usr/ctxtCN_PSPNR-LOW").Text = WBS
session.findById("wnd[0]/usr/ctxt_6-KSTAR-LOW").Text = "400000"
session.findById("wnd[0]/usr/ctxt_6-KSTAR-HIGH").Text = "920000"

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

 

If session.findById("wnd[0]/sbar").Text = "Report 6PP1-001 does not contain any data pages." Then
' This means no Actual Cost, no Commitment and no Plan Cost exist.
Cells(i, 2) = "No Actual Cost, no Commitment and no Plan Cost exist"
session.findById("wnd[0]/tbar[0]/btn[3]").press


Else 'If data exist for the WBS in S_ALR, then save it into a file

'session.findById("wnd[0]/shellcont/shell/shellcont[2]/shell").hierarchyHeaderWidth = 232 ' Clear?
session.findById("wnd[0]/mbar/menu[0]/menu[3]").Select
session.findById("wnd[1]/usr/radLGRWO-X_EXPONLY1").Select
session.findById("wnd[1]/usr/ctxtLGRWO-OUT_FILE").Text = FilePath & WBS & ".dat"
session.findById("wnd[1]/usr/radLGRWO-X_EXPONLY1").SetFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[2]/usr/btnSPOP-VAROPTION2").press
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[1]/usr/btnBUTTON_YES").press



End If  'End If for checking if data exist for the WBS in S_ALR

i = i + 1
Loop



' Parameters
'FilePath = Cells(2, 3)
'Sheets.Add.Name = "RESULTS"

'------------------  Read the files
AddTime = Format(Now(), "yyyymmddhhmmss")
SheetName = "RESULTS" & AddTime

Sheets.Add.Name = SheetName
Sheets("Macro2").Activate
i = 2


k = 2
'================Start reading data files
'For each WBS in column A in Macro2 sheet
Do While ThisWorkbook.Sheets("Macro2").Cells(i, 1) <> ""
' Check if any datafile exist, by checking status column B in Macro 2 sheet
If ThisWorkbook.Sheets("Macro2").Cells(i, 2) <> "No Actual Cost, no Commitment and no Plan Cost exist" Then

WBS = ThisWorkbook.Sheets("Macro2").Cells(i, 1)

Fil = FilePath & WBS & ".xls"

Name FilePath & WBS & ".dat" As Fil


'Workbooks.Open Filename:=Fil
    Set wbkA = Workbooks.Open(Filename:=Fil)
   
   
    ' Count Rows in WBS file
    j = 2
    Do While Sheets(WBS).Cells(j, 1) <> ""
      j = j + 1
     
    Loop
   
   
    Range_String = "A" & 2 & ":Q" & j
    Range(Range_String).Copy
    ThisWorkbook.Activate
    Sheets(SheetName).Activate
   
    '*** Select the destination cell and copy
    Range_Target = "B" & k
    Range(Range_Target).Select
    ActiveSheet.Paste
    ActiveSheet.Cells(k, 1) = WBS
    
     ' ----- Close WBS file
    Application.DisplayAlerts = False
    wbkA.Activate
    wbkA.Close
    Application.DisplayAlerts = True

k = k + j - 3 ' This variable keep track of printing position
End If ' End if checking the B-column in Macro2 sheet
i = i + 1
Loop

 

RESULT_sheet = SheetName

i = 2

WBS = ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 1)

Do While ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 2) <> ""

' Calculate diff between Plan Cost and Assigned cost, if Plan cost is to low, print  mount
If CDec(ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 6)) < CDec(ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 5)) Then
ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 19) = CDec(ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 5)) - CDec(ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 6))
End If

 

If Left(ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 2), 3) <> "All" Then

If ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 1) <> "" Then
WBS = ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 1)
End If

If ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 1) = "" Then
ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 1) = WBS
End If

End If

 

 

 

i = i + 1
Loop
i = i - 1
'Range_String = "A" & i & ":R" & i
'ThisWorkbook.Sheets(RESULT_sheet).Range(Range_String) = ""
'ThisWorkbook.Sheets(RESULT_sheet).Range(Range_String).Delete

'Cells(Range_String) = ""
Range_String = i & ":" & i

Rows(Range_String).Select
Selection.Delete Shift:=xlUp


Columns("G:R").Select
Selection.Delete Shift:=xlToLeft

ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 1) = "WBS"
ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 2) = "Cost Element"
ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 3) = "Actual Cost"
ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 4) = "Commitments"
ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 5) = "Assigned Cost"
ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 6) = "Plan Cost"
ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 7) = "Adjustment needed"

ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 8) = "Description"
ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 9) = "Amount"
ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 10) = "Curr"
ThisWorkbook.Sheets(RESULT_sheet).Cells(1, 11) = "CE"

 


'==== Create PRIM

i = 2
WBSold = ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 1)


Do While ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 1) <> ""

WBS = ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 1)

'Mark cells for each new WBS to make more easy to read
If WBS <> WBSold Then
RangeBoarder = "A" & i & ":K" & i
Range(RangeBoarder).Borders(xlEdgeTop).LineStyle = xlDash
End If

 

CE = Left(ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 2), 6)

' If external cost adjustment needed, then pepare PRIM
If Left(CE, 1) = "4" And ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 7) <> "" Then

TodayDate = Format(Now(), "yyyymmdd")

ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 8) = "PRIM " & CE & " Plan Cost Adjustment"
ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 9) = ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 7)
ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 10) = "KRW"
ThisWorkbook.Sheets(RESULT_sheet).Cells(i, 11) = CE

End If

WBSold = WBS
i = i + 1
Loop

      
' Resizing columne
Columns("A").ColumnWidth = 18.15
Columns("B").ColumnWidth = 38
Columns("C").ColumnWidth = 10
Columns("D").ColumnWidth = 11.9
Columns("E").ColumnWidth = 12.6
Columns("F").ColumnWidth = 12.6
Columns("G").ColumnWidth = 16.6
Columns("H").ColumnWidth = 29.5
Columns("I").ColumnWidth = 8
Columns("J").ColumnWidth = 3.71
Columns("K").ColumnWidth = 6
               


End Sub

 

 

 

However, I am nowhere near gathering all that excel data.

Your help will be very very much appreciated!!

 

BR,

Cathy

Excel VB Code for getting the warning Icon text / Colour

$
0
0

Hi,

 

Could anyone please help me to get the the warning / error icon color or text ?

 

Capture.PNG

 

I'm using the following code to assign the text or color to a variable which is not working.

 

WarningMessageText = session.findById("wnd[0]/usr/ssubSUBSCR_1200:SAPLCMFV:1200/tblSAPLCMFVT_MKAL/lblMKAL_AMPEL_X[8,0]").text

 

 

Thanks,

Ram

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

SAP GUI Appearance Changes After VBScript Manipulation

$
0
0


I can't seem to find any posts on this issue in the forum; perhaps someone out there knows how to fix this via VBScript.

 

I have an Excel macro that manipulates SAP via embedded VBScript. The script was recorded using the SAP Script recorder.  After the code has run, the GUI appearance for popups (session.findById("wnd[1]) forms and subsequent forms look different and less user-friendly. The original session.findById("wnd[0] appearance seems unaffected and looks fine.  Is there a way to ensure that the original, default appearance for session.findById("wnd[1] is maintained after manipulating SAP via VBScript?  The only way I found so far is to log out of the SAP GUI

 

Example:

 

After drilling down to find a WBS code by clicking the drop down icon indicated below:

 

PopUpVBS.png

 

The subforms (popups - session.findById("wnd[1]) look like the screenshots below (before and after):

 

Before Running Script (every day user look and feel):

 

BeforeVBS.png

 

After running script:

 

AfterVBS.png


How to Count the Rows of a GUI Label Object

$
0
0

Hi,

 

I was wondering if anyone has any experience working with the GUI Label Object.  I'm able to navigate through it's rows by referring to the labels like this:

 

lblWBS = session.findById("wnd[1]/usr/lbl[1," & i & "]").Text

 

where i is a variable in a For Next loop.  In the example code above where i = 1, lblWBS would render "WBS Element"; when i = 3 lblWBS renders "121476.01.01.01.013533A, etc.  The narrow space between 1 and 3 is actually a label too so I assume it would be label 2.  You can see the example below. I also attached the .png file just in case you can't read the image I inserted.

 

GUI LBL.png

 

I need to be able to count the rows in this collection of lablel objects, or probably more accurately, count the labels in one colum.  I'm able to do this easily in a ALV grid but not in the GUI Label Object container.  Does anyone out there have any knowledge on this?

Connect excel 2010 64 bits with SAP

$
0
0

Hi!

 

I have a macro in Excel that connects to SAP.

With Office 32 bits and Windows 7 64bits works perfectly.

With Office 2010 64bits it returns the error '429' An ActiveX component cannot create the object.

 

 

I've tried to register libsvr32.dll and copy it to system32 directory but nothing works.

 

The error appears at line

 

  Set R3 = CreateObject("SAP.Functions")

 

I think there's some incompatibility between office 64 bits and SAP but I'm no really sure.

 

Could I use another method to connect SAP instead of libsvrc32.dll?

 

Help will be appreciated!

 

Thanks!

GuiXT Copytext or VBScript - not allowing to paste values to multiple selection

$
0
0

Hello Guru's of Scripting.

We have a requirement to download inspection lot information for 4500+ plants using transaction QA33. We cannot use all plants at a time to get result output. I would like to run this report in parts. example: 20 plants at a time.

QA33 screen with plant selection:

2-19-2014 9-17-06 AM.jpg

Multiple selection for plant:

2-19-2014 9-18-01 AM.jpg

 

Here is my code so far:

_______________________________________________________________________________________________________________________________**********************************************************************************************************************************************************************************

//Counter

Set V[i] 1

//Input file that contains more than 4500 plants

Parameter mat_file1 "C:\Documents and Settings\Desktop\ip2.txt"

//Intermediate file to copy 20 plants at a time

Parameter mat_file3 "C:\Users\Desktop\myfile.txt"

 

 

//create myfile.txt text file on C:\Users\Desktop\ location before running program

  OpenFile "&U[mat_file3]" -Output

  OpenFile "&U[mat_file1]"

 

 

 

 

 

 

 

label Read_File

  ReadFile "&U[mat_file1]" C

 

 

if not Q[ok]

    CloseFile "&U[mat_file1]"

    CloseFile "&U[mat_file2]"

    CloseFile "&U[mat_file3]"

    Return "Job done!" "&U[mat_file1]"

  endif

 

 

// loops

//1st loop to make sure the total no of records do not exceed 4500

If V[i<4500]

AppendFile "&U[mat_file3]" C

Set V[i] "&V[i]" + 1

//Checking to make sure we append only 20 plants at a time.

//These 20 plants are added to myfile.txt

if V[i=21]

//myfile has 20 file it goes to transaction qa33 screen

Goto next_step

endif

goto Read_File

endif

 

 

 

 

 

 

label next_step

 

 

//Deletes default values from selection fields

Set F[%_QL_ENSTD_%_APP_%-TEXT] ""

Set F[%_QL_ENSTD_%_APP_%-TO_TEXT] ""

Set F[Plant] ""

Set F[Maximum No. of Hits] ""

 

 

 

 

// Inspection Lot Selection

Screen RQEEAL10.1000

//Clicked on multiple selection button

  Enter "=%043"       // Multiple selection.6

 

 

 

// Multiple Selection for Order

 

 

Screen SAPLALDB.3000

//This is equivalent to clicking on delete button from multiple selection

Enter "/16" //delete contents

 

 

// Multiple Selection for Plant

 

 

Screen SAPLALDB.3000

 

//Copy 20 plants from myfile to text t1

Copytext fromFile="&U[mat_file3]" toText="t1"

//Copy those 20 plants from t1 to clipboard

Copytext fromText="t1" -toclipboard

//Next step is to click on paste icon on dynamic selection

Enter "/24" //copy from clipboard

 

 

// Multiple Selection for Material

Screen SAPLALDB.3000

  Enter "/8"

 

 

// Inspection Lot Selection

Screen RQEEAL10.1000

  Enter "/8"       // Execute

 

// Display data for inspection lot: Worklist for Inspection Lots

Screen SAPLSLVC_FULLSCREEN.0500

  Enter "/Menu=1,4,3"       // Local file...

 

// Save list in file...

Screen SAPLSPO5.0110

  Set R[Spreadsheet] "X"

  Enter

 

// Display data for inspection lot: Worklist for Inspection Lots

Screen SAPLSFES.0200

  Set F[DY_PATH] "C:\Users\Desktop"

  Set F[DY_FILENAME] "temp.txt"

  Enter "/7"       // Extend

 

 

// Display data for inspection lot: Worklist for Inspection Lots

Screen SAPLSLVC_FULLSCREEN.0500

  Enter "/3"

 

 

Set V[i] 1

//OpenFile "&U[mat_file3]" -Output

Set V[t2] ""

Copytext fromText="t2" toFile="C:\Users\Desktop\myfile.txt"

// Display data for inspection lot: Worklist for Inspection Lots

 

 

CloseFile "&U[mat_file3]" -Output

 

 

 

 

 

 

//Screen SAPLSLVC_FULLSCREEN.0500

//  Enter "/nqa33"

goto Read_File

 

******************************************************************************************************************************************************************************____________________________________________________________________________________________________________________________

 

 

 

 

Problem part of the code:

 

Copytext fromFile="&U[mat_file3]" toText="t1"

 

Copytext fromText="t1" -toclipboard

 

Enter "/24" //copy from clipboard


When I debug this code ..I see empty value for t1 or clipboard.

I have tried several Copytext options but no solution so far.

Please help me with this issue.

GuiXT solution OR VBScript but I want it to be able to paste 20 values.

I really appreciate you'r time and effort in this regard.


SAP Krazy



Tips and Tricks: SAP GUI scripting object hierarchy view

$
0
0

Hello community,

 

a good way to work with the object hierarchy of SAP GUI scripting is to load the file C:\Program Files\SAP\FrontEnd\SAPgui\sapfewse.ocx - this is the SAP GUI scripting API - in the object catalog of Excel or another Office application. Press Alt + F11 to go to VBA. Choose menu Tools > References and press the button Browse to select sapfewse.ocx. Now press F2 to open the object catalog and choose SAPFEWSELib. You see all classes with their elements and types.

 

Cheers

Stefan

Choosing the correct tab on ME22N or ME23N

$
0
0

hello.

 

I am looking to ensure that when I run this particular TCODE that the VBA checks to ensure I am on the correct tab (confirmations tab for example), and if i am not on the correct tab then to choose it.  I already have written some code that works sometimes, however, if i'm already on the tab i get an error and sometimes, it just gives me an error regardless.

 

       session.findbyid("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16").Select

 

Can anybody give me some direction?  Thank you!

Add informations from Excel to SAP

$
0
0

Hello guys!

 

I'm totaly new in this area, but I'm really excited about it!!

 

I need to export data from Excel to SAP (in a determinated function).

 

As example the sheet:

imagem.JPG

 

I need to fill the Sheet and use the macro that will use the informations that the sheet have in each row and create (for each row) a SAP Number (after this function, if I press enter it will generate a "Request ID") and put it automatically in the SAP ID Colum.

 

Is that even possible?

 

It will help me alot!!

 

I use SAP GUI.

 

Thx!!!!

Using Macro in Excel How to open a SAP directly?

$
0
0

Hi,

       Can Anyone Suggest and help me to do above Code in Excel,"Using Macro in Excel  How to open SAP directly"

 

Example: I want to Open T.CODE: MM01 directly, without login in to SAP, Using Macro, i want to open SAP Directly, Anyone Suggest me how to do it?.............

 

I Tried this But it  showing Run time Error'438', Object does not support this property or method........

VBCODE:

 

Dim sap As Object

Dim conn As Object

Sub T_login()

Set sap = CreateObject("SAP.Functions")

Set conn = sap.Connection

conn.System = "production"

conn.client = "800"

conn.user = "SAPUSER"

conn.Password = "123456"

conn.Language = ""

conn.Tcode = "MM01"

If conn.logon(0, False) Then

MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"

Else

End If

If Not IsObject(SapGuiApp) Then

Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")

End If

If Not IsObject(Connection) Then

Set Connection = SapGuiApp.OpenConnection("production", True)

End If

If Not IsObject(session) Then

Set session = Connection.Children(0)

End If

session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "CLIENT"

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

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

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

session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus

session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2

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

Set wshell = CreateObject("Wscript.Shell")

wshell.Run Chr(34) & Path & "\script.vbs" & Chr(34), 1, 1

End Sub

 

Anyone send me the Exact code related to this.................

 

Its very immediate requirement.................

 

 

Regards

Karthick


PHP SDK for SAP OData - Method

$
0
0

  Hello all,

 

I am currently trying to integrate PHP with SAP OData gateway. I got the Query, Read and Create working from various guides and blogposts, however, I am struggling with the Delete and Update.

 

I am using the following SDK: http://odataphp.codeplex.com/

 

In the case of the Delete, I am using the following code:

 

function deleteBank($id) {

   

    $scheme_agency_id = "LOCAL";

    $scheme_id = "Z_BANK_RFC_RRO";

    error_log('deleteBank() with id: ' . $id);

    $search = null;

 

    try {

        $proxy = new ZBANKRFCRRO("http://developer:xxxxxxxx@sapnwgw01:8042/sap/opu/sdata/sap/ZBANKRFCRRO");

        $query = "z_bank_rfc_rroCollection(value=%27$id%27,scheme_id=%27$scheme_id%27,scheme_agency_id=%27$scheme_agency_id%27)";

        $bank = $proxy->Execute($query . $search)->Result;

       

        $proxy->setMethod('HttpVerb::DELETE');

       

        //The object is added to the list of objects to delete in the database

        $proxy->DeleteObject($bank);

         //SaveChanges persists the changes in the database

        $proxy->SaveChanges();

       

    } catch(ODataServiceException $exception) {

        echo '{"error":{"text":'. $exception->getError().'}}';

    }  

}

 

 

Looking the SDK documentation, it instructs to use the DeleteObject method, however, after using a packet sniffer I can confirm that it's using a GET and not a DELETE (which is what the SAP GW expects).

 

Any thoughts, or guidance in how to change the http verb?

 

Thank

how to get data from SAP into the excel

$
0
0

Hi all,

 


I need data from SAP to excel using VBA. till now I was able to log into SAP and run the desired transaction I need using excel and VBA now my second biggest Challenge is to export the data I see in SAP into the excel sheet. there are options in SAP to export the data but I need to do it using the VBA. Kindly help me


Please see below the VB code I have written so far, but its just takes me to the data I need but now as I said my second biggest chalange is to get that data from SAP back to Excel.



 

Sub TEST()

'setting the connection with sap:

Dim App, Connection, session As Object

Set SapGuiAuto = GetObject("SAPGUI")

Set App = SapGuiAuto.GetScriptingEngine

Set Connection = App.Children(0)

Set session = Connection.Children(0)

 

 

 

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

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

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

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

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

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

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

session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell

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

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell -1, ""

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").SelectAll

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").contextMenu

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectContextMenuItem "&XXL"

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

 

End Sub




Regards,

Imran

SAPUI5 in NWDI

$
0
0

What sort of SCA dependencies do I need to do UI5 development through NWDI Track.

 

I need to create a track and define dependencies. I know I need the UI5 component. What else do i need?

 

Thank You!
Nitin    

parameters sintax for BAPIs in PHP?

$
0
0

Hi,

 

can someone help me with the parameters sintax for these bapis (bapi_salesorder_createfromdat2 and bapi_transaction_commit) in PHP?

 

More details ...

I wrote a PHP script calling thats bapis, I sent the values in arrays. When I ran the script I got any error, but it shows a list of empty data and at the bottom the follow messages:

No errors detected.

 

call function 'BAPI_TRANSACTION_COMMIT' successfull.

 

But there is no sales order created in the database.

 

I think, the sintax for the parameters are wrong or maybe all my logic

 

 

Attach files: My PHP script and a  file with the output of the execution (please change the extensions

 

I'm using wampserver 2.2 installed locally ( apache 2.2.21 - PHP 5.3.8 ) my SAP QAS is in Oracle.

 

thanks

 

-- sorry for my pour english --

Save SAP report in Excel format into specified drive

$
0
0

Hi Team,

 

I am new to SAP scripting and i have recorded below SAP Script to download a report from SAP in Excel format at specified format.

Here issue is that i am not able to record the Save as dialogue where the file needs to be saved automatically.

 

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 = "/nfbl3n"

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

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

session.findById("wnd[1]/usr/txtENAME-LOW").text = "10290492"

session.findById("wnd[1]/usr/txtENAME-LOW").setFocus

session.findById("wnd[1]/usr/txtENAME-LOW").caretPosition = 8

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

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

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

session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell

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

session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").select

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

session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").select

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

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

 

Can anyone of you help me to provide script for the same so that report is automatically saved in specified path.

 

Thanks

Viewing all 325 articles
Browse latest View live


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