Quantcast
Channel: SCN: Message List - Scripting Languages
Viewing all 1708 articles
Browse latest View live

Re: Copy-Paste dates from Excel in SAP script

$
0
0

Then you just have to define the variable.

 

for example:

 

. . .

Dim Delivery as String

If Not IsObject(application) Then

set SapGuiAuto = GetObject("SAPGUI")

. . .


Re: Copy-Paste dates from Excel in SAP script

$
0
0

Try putting:

 

     Dim Delivery As String

 

before the

 

     Delivery = GetSheetRowValue("Delivery")


and see if VBS throws any more error.

Re: Copy-Paste dates from Excel in SAP script

$
0
0

Still says that the delivery variable is not defined.

 

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

 

If Not IsObject(application) Then set SapGuiAuto = GetObject("SAPGUI")

 

Delivery = GetSheetRowValue("Delivery")

 

session.findById("wnd[0]/usr/tblSAPMM06ETC_1117/ctxtRM06E-EEIND[1,0]").text = mid(Delivery,1,4) & "/" & mid(Delivery,6,2) & "/" & mid(Delivery,9,2)

Re: Copy-Paste dates from Excel in SAP script

$
0
0

Apparentlyyou need theentire script.


Dim Delivery as String

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 = "me22"

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

session.findById("wnd[0]/usr/ctxtRM06E-BSTNR").text = GetSheetRowValue("PO")

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

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

session.findById("wnd[0]/usr/txtRM06E-EBELP").text = GetSheetRowValue("Item")

session.findById("wnd[0]/usr/txtRM06E-EBELP").setFocus

session.findById("wnd[0]/usr/txtRM06E-EBELP").caretPosition = 1

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

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

session.findById("wnd[0]/usr/txtRM06E-ETNR1").text = GetSheetRowValue("Ligne")

session.findById("wnd[0]/usr/txtRM06E-ETNR1").setFocus

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

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

Delivery = GetSheetRowValue("Delivery")

session.findById("wnd[0]/usr/tblSAPMM06ETC_1117/ctxtRM06E-EEIND[1,0]").text = mid(Delivery,1,4) & "/" & mid(Delivery,6,2) & "/" & mid(Delivery,9,2)

session.findById("wnd[0]/usr/tblSAPMM06ETC_1117/ctxtEKET-SLFDT[6,0]").text = GetSheetRowValue("Statistical")

session.findById("wnd[0]/usr/tblSAPMM06ETC_1117/ctxtEKET-SLFDT[6,0]").setFocus

session.findById("wnd[0]/usr/tblSAPMM06ETC_1117/ctxtEKET-SLFDT[6,0]").caretPosition = 0

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

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

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

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

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

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

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

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

 

Good Luck,

ScriptMan

Re: Input from Excel to SAP - make cycle.

$
0
0

Exactly.

Cstr() - for me new, very useful command.

 

Thanks Maestro.

Re: SAP CRM VBA Excel Macro, No data return

$
0
0

Hello ScriptMan,

 

Your logic works fine.

 

Could you please explain what is the meaning of "WA" in tData(i, "WA").

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!

Re: failed to connect to sap using php

$
0
0

Can you provide more information on what system level, rfc level, which RFC PHP package you are using?

 

Anything more than just that error?


Re: SAP CRM VBA Excel Macro, No data return

$
0
0

Hello.

 

"WA" is the workarea from table DATA of functionmodule RFC_READ_TABLE. Check this functionmodule in SE37. There you can see it.

 

Greetings,

 

Holger

Re: SAP CRM VBA Excel Macro, No data return

$
0
0

Hello Holger,

 

Yes,Now i checked it.

 

Thank you so much for your information.

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

Re: VB Script: check for existing open session

$
0
0

Hi Jason,

 

welcome in the Scripting Language forum.

 

Here a VBA snippet to connect an SAP System, if no other connections to the system exists:

 

Function GrabOrdersToday()

 

  Dim SapGuiAuto As Object
  Dim Application As SAPFEWSELib.GuiApplication
  Dim Connection As SAPFEWSELib.GuiConnection
  Dim i As Integer
  Dim Conn As String
  Dim Flag As Boolean

 

  Flag = False
  Set SapGuiAuto = GetObject("SAPGUI")
  Set Application = SapGuiAuto.GetScriptingEngine
  If Application.Connections.Count() > 0 Then
    For i = 0 To Application.Connections.Count() - 1
      Set Connection = Application.Children(i)
      Conn = Connection.Description()
      If Conn = "PRD" Then
        Flag = True
        Exit For
      End If
    Next
   
    If Flag = False Then
      Set Connection = Application.OpenConnection("PRD")
    End If
   
    'Insert your code here
   
    Set Connection = Nothing
  

  Else

 

    Set Connection = Application.OpenConnection("PRD")

   

    'Insert your code here

   

    Set Connection = Nothing


  End If

 

End Function

 

Cheers

Stefan

Re: VB Script: check for existing open session

$
0
0

Thank you for your reply!  This looks very promising.  I am now getting an error "User-Defined Type not defined" at this line:

 

Dim Application As SAPFEWSELib.GuiApplication

 

I assume I am missing a Reference in my database for that object library?  It's not available in my current list of libraries as SAPFEWSELib.  Could it be called something else?  Or am I on the wrong path here?

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

Re: VB Script: check for existing open session

$
0
0

Hi Jason,

 

add in your VBA project a reference to the SAP GUI Scripting library.

 

Choose the menu Tools > References and press the button Browse... Now choose the file C:\Program Files\SAP\FrontEnd\SAPgui\sapfewse.ocx. This binds the SAP GUI Scripting API into the VBA-IDE. Press the Ok button and now you can use the SAPFEWSELib namespace.

 

This should solve your problem.

 

Good luck.

 

Cheers

Stefan


Re: Excel VB Code for getting the warning Icon text / Colour

$
0
0

Hello Ram,

 

welcome in the SAP Scripting Language forum.

 

You find a solution here to read the name of the icon. With the name of the icon you can differentiate its colors.

 

Cheers

Stefan

Re: Excel VB Code for getting the warning Icon text / Colour

$
0
0

Hi Stefan,

 

Today only i could check it.

 

It worked perfect.

 

Thanks a ton.

 

Below is just for your kind information.

 

Green = S_TL_G

Yellow = S_TL_Y

Red = S_TL_R


Thanks again Stefan.

Re: Excel VB Code for getting the warning Icon text / Colour

$
0
0

Hello Ram,

 

thanks for sharing this information.

 

Cheers

Stefan


Re: VB Script: check for existing open session

$
0
0
Sub Get_all_SAP_Sessions()    Dim SapGuiAuto As Object    Dim i%    Dim iSession%    Dim sapapplication    Dim Connection As SAPFEWSELib.GuiConnection    Dim Session As SAPFEWSELib.GuiSession    Dim strSessions$    i = 1    iSession = 0    ' There may be bad entries in the ROT from previous crashes    While i < 10 And SapGuiAuto Is Nothing       i = i + 1       On Error Resume Next       Set SapGuiAuto = GetObject("SAPGUI")       On Error GoTo 0    Wend    If SapGuiAuto Is Nothing Then        MsgBox "Could not connect to SAPlogon process. Did you start it?"        Exit Sub    End If        On Error Resume Next    Set sapapplication = SapGuiAuto.GetScriptingEngine    Set SapGuiAuto = Nothing    On Error GoTo 0    If sapapplication Is Nothing Then        MsgBox "Could not access GuiApplication. Maybe Scripting is disabled?"        Exit Sub    End If    Set SapGuiAuto = Nothing        For Each Connection In sapapplication.Children        If Not Connection.DisabledByServer Then            For Each Session In Connection.Children                If Session.Busy = False Then                    iSession = iSession + 1                    strSessions = strSessions & iSession & " => " & (Session.Info.SystemName & _                    " (" & CStr(Session.Info.SessionNumber) & _                    ") (" & Session.Info.Client & ") | User: " & _                    Session.Info.User & " | Transaction: " & _                    Session.Info.Transaction) & vbCrLf & iSession & " => System-ID: " & Session.ID & vbCrLf                End If            Next        End If    Next    MsgBox strSessions
End Sub

 

Above an example how I achieve to get all available SAP Sessions. Additional I implement an check if a Session is busy. In this case it will skip to get session info as this will block the check macro.

 

Holger

Re: Gathering MHTML reports

$
0
0

Hello Cathy.

 

As MHTML is an link to external Excel we will not be able to read Excel in place inside SAP IW33 cost tab.

 

 

But you can read directly from ALV-grid in cost tab:

 

    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]/tbar[1]/btn[8]").press    Session.FindById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1107/tabsTS_1100/tabpKOAU/ssubSUB_AUFTRAG:SAPLICO1:1100/btnPUSH1").press    ThisWorkbook.Sheets(2).Activate    Set Table_Message = Session.FindById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell")    Set Cols = Table_Message.ColumnOrder()    ROW_COUNT = Table_Message.RowCount() - 1    COL_COUNT = Table_Message.ColumnCount() - 1        For i = 0 To ROW_COUNT        For j = 0 To COL_COUNT            DoEvents            If i = 0 Then ThisWorkbook.Sheets(2).Cells(i + 1, j + 1).Value = Table_Message.GetDisplayedColumnTitle(CStr(Cols(j)))            ThisWorkbook.Sheets(2).Cells(i + 2, j + 1).Value = Table_Message.GetCellValue(i, CStr(Cols(j)))        Next    Next    
Columns.AutoFit
Viewing all 1708 articles
Browse latest View live


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