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

Re: Excel VBA Script for Services for Object ToolBox - the "Import File" dialog Box

$
0
0

Noted.

 

For my project I'm going to maintain one Excel File for easier distribution.

 

For the purpose of uploading file using Services for Object, I'm going to use the following steps:

 

  1. VBA to create a VBS file with the instruction line to loop and check for the Import File dialog box. If found, activate it then sendkeys five tab keys, the fullpath string of the file to be uploaded and enter key to the dialog box. The fullpath will be stored in a string variable which takes its values from the VBS file argument send by the VBA in the next step.
  2. VBA will shell WScript to run the VBS file with the fullpath string as its argument.
  3. VBA will execute the procedure to bring up the dialog box in SAP.
  4. If everything go as planned, the file will be uploaded to SAP and VBA will kill (i.e delete) the VBS file.

 

For the purpose of testing steps 2 and 3, I have manually created the VBS file. It works. Now I'm working on the codes to automate the creation of the VBS file (step 1) and delete it (step 4).

 

The setback is, if the VBS is interrupted before it finishes executing, VBA and Excel will hang until the Import File dialog box is manually closed in SAP.

 

Anyway, thanks again for your replies and guidance.

 

Regards,

Sayuti


Re: Connection to SAP from Excel

$
0
0

OK, as far as I see it, you'll need your IT Support to help to update the saplogon_bw.ini file

 

Michael

Beginner: Pull data from excel spreadsheet and loop transactions

$
0
0

I am very new to both scripting and SAP and don't know the proper terms for what I'm trying to do, so the search function wasn't much help. If someone can point me in the right direction that would be great.

 

I am currently trying to update a list of material codes in ME11 and MM02 from an excel spreadsheet with the data for all the fields I'm changing. I currently have recorded scripts that input anything that remains constant on the transactions, but on each one, there is at least one unique field. I'm hoping to have a script that will reference the excel spreadsheet and put a specific cell in the SAP field, save the transaction and then loop for each row in the excel spreadsheet. Any help or a point in the right direction would be appreciated.

Re: VBScript: Details on Connection errors

$
0
0

Hi Andreas,

 

Did you got any solution on how to capture RFC logon error?

 

I am able to login in SAP GUI Logon where as while connecting the same from vb script its not working.  The below line returns as false and the isconnected value is 8. 

 

If objconn.Logon(0, True) <> TrueThen

 

I couldn't able to figure out the exact issue using the vb script. And if anything can be done from SAP server end to check and trace the error also it will be helpful. 

 

Thanks

 

Regards,

Prakash

Re: How to scroll GUI table in VB

$
0
0

I recently faced with a similar situation with the GuiTableControl.

 

A colleague wanted to extract data from a table which only have 2 visible rows whereas there are 2000+ rows in total. My first thought, like yours, was to use VerticalScrollBar.Position to scroll down the table, but the script crashes after it completed the 1st loop.

 

After trial and error with different strategies, my VBA script finally works. The key is to re-declare the GuiTableControl object after each scroll. It seems that whenever the VerticalScrollBar position changes, the table is re-loaded is SAP and all the cells are reset in reference to the VerticalScrollBar position. This is probably why SAP throw an exception when trying to get the value from the table after the 1st loop - the GuiTableControl declared initially no longer exist in memory after the scroll.

 

Anyway, my solution steps are basically as follow:

 

  1. Declare the GuiApplication, GuiConnection and GuiSession objects as usual for initialization.
  2. Declare the GuiTableControl object e.g. sapTable = session.findbyid("theTableID"), then get the sapTable.VisibleRowCount and sapTable.RowCount.
  3. Set the looping parameters to start from whichever rows but maximum loops should be no more than RowCount / VisibleRowCount.
  4. Get the data using sapTable.GetCell(0,0).Text to maximum sapTable.GetCell( VisibleRowCount - 1, Columns.Count - 1).Text
  5. Set sapTableVerticalScrollBar.Position = sapTable.VerticalScrollBar.Position + sapTable.VisibleRowCount.
  6. Re-declare the sapTable object using the same "theTableID" in step 2 above.
  7. Loop step 4, 5 and 6 until finish.

 

This way, we eliminate the need to use VBS for Sendkey and only needs VBA to do the job.

 

Thanks,

Sayuti

Re: Beginner: Pull data from excel spreadsheet and loop transactions

$
0
0

Dear Grant,

 

What is the script language you are using - VBS or VBA? Since you are working with an Excel spreadsheet, my recommendation would be VBA. If you are using VBS, you need to use GetObject or CreateObject to reference the Excel Application whereby this is not necessary in VBA.

 

If you dont mind sharing your current codes, we can look at it and offer further advise. Otherwise, the direction to go is to search through the content of this forum or read the SAP Scripting API.

 

Thanks,

Sayuti

Re: How to scroll GUI table in VB

$
0
0

Hello Sayuti,

 

thanks for sharing this interesting information

 

Cheers

Stefan

Re: Transferring data from Excel to SAP

$
0
0

Hi, I tried this and is working fine... but is there any way to generate in the excel file the result of the execution of each specific line? this is because if we run 2000 lines (for example) I want to know in which lines the modification was successful and in which font. Appreciated your help.


Re: How to scroll GUI table in VB

$
0
0

Hello Stefan,

 

I would like to write a vbscript code to search for entries in table.

 

11-18-2013 3-22-16 PM.jpg

 

I copied your code from previous replies but it's not working.

IfNotIsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
EndIf
IfNotIsObject(connection) Then
   Set connection = application.Children(0)
EndIf
IfNotIsObject(session) Then
   Set session    = connection.Children(0)
EndIf
IfIsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
EndIf
Dim WshShell
DimWScript
Set WshShell = WScript.CreateObject("WScript.Shell")

'Get the number of rows in the table
i = session.findById("wnd[0]/usr/tblSAPLQPAATC_PLMK").RowCount

'Go to each row and read the field 0,0
For j = 1To i

  'With Shift+Arrow Down you can scroll through the table
  WshShell.AppActivate"Title of the SAP Window"
  WshShell.SendKeys"+{DOWN}"
  WScript.Sleep125

  'Read the content of the field 0,0, in my case a key
  fld = session.findById("wnd[0]/usr/tblSAPLQPAATC_PLMK/txtPLMKB-KURZTEXT[0,0]").Text
  'If the content of field is identical to the line before,
  'we reach the end of the entries
  If fld = vfldThen
    MsgBoxCStr(j) & " entries"
    ExitFor
  EndIf
  vfld = fld

Next

 

Kindly please help me in right direction.

 

Thanks!

Re: How to scroll GUI table in VB

$
0
0

I use the Exceptionhandling because sometimes some Cells can kind of be "locked". If Value = GetCell().Text is used on one of there, an exception will be thrown and Value will contain the "old" Value from the last working Cell.

 

Of course you need to add On Error Resume Next in the beginning. Its not necessary to Use Err.Clear and If Err.Number = 0, you can also set Value to "" after writeing it to the CSV File.

 

Maybe like this:

 

'Exception Handling

On Error Resume Next

 

'Variablendeklaration

Dim TableID asString

Dim oTableControl As SAPFEWSELib.GuiTableControl

Dim CSV AsObject

Dim iRow AsLong

Dim Rows AsLong

Dim vRows AsInteger

Dim iCol AsInteger

Dim Cols AsInteger

Dim ScrollBarPosition_o AsLong

 

'Table ID initialisieren

TableID ="hier die ID eingeben"

 

'Das GuiTableControl in die Objektvariable "oTableControl" initialisieren

Set oTableControl = Session.FindById(TableID)

 

'Tabellengröße ermitteln

Rows = oTableControl.RowCount -1

Cols = oTableControl.ColumnCount -1

vRows = oTableControl.VisibleRowCount

 

'Initialisierung des Objekts zur Erstellung der CSV-Datei

Set CSV = _

    CreateObject("Scripting.FileSystemObject"). _

    CreateTextFile("C:\test.csv",True)

 

'Alle Spaltennamen in die erste Zeile der CSV-Datei schreiben

For iCol =0To Cols

    CSV.Write oTableControl.Columns.Item(iCol).Title & _

        IIf(iCol < Cols,";","")

Next

 

'Daten in die folgenden Zeilen bertragen

Dim Value AsString

Do

    For iRow =0To vRows

        IfNot iRow = vRows Then oCSV.WriteLine ""

        For iCol =0To Cols

       Value = oTableControl.GetCell(iRow, iCol).Text

        If IsNumeric(Value)AndNot isSAPDate(Value)Then

          Value = IIf(CDbl(Value)Mod2=0, _

                        CLng(Value),CDbl(Value))

          oCSV.Write Value & IIf(iCol < Cols,";","")

        EndIf

       Value =  ""

    Next

  

        'Scrollbar weitersetzen und alten Wert speichern

    ScrollBarPosition_o = oTableControl.VerticalScrollbar.Position

    oTableControl.VerticalScrollbar.Position = _

        oTableControl.VerticalScrollbar.Position + vRows

  

        'oTableControl neu initialisieren

    Set oTableControl = Session.FindById(TableID)

LoopWhile ScrollBarPosition_o <oTableControl.VerticalScrollbar.Position

CSV.Close

Re: How to scroll GUI table in VB

$
0
0

Sorry I forgot to include more information.

 

Program name: SAPLQPAA

Dynpro: 0150

Screen title : Display Inspection Plan: Characteristic Overview

Transaction code: QP03

 

In this transaction we list all the test (insp. character) that needs to be recorded to post approve OR reject (usage decision)

 

we have more than 200 tests listed in the inspection plans and searching for exact tests is manual work.

1) SAP in built search icon is disabled in this transaction (QP03).

2) its table and not grid view. I came to know about gridview relevant vbscript codes from you in this form and using them activley ..thanks to you. But how do we put vbscript code to search lets say inspection character from table view in QP03.

 

I really appreciate you taking time to answer my stupid questions.

 

Thank you!!

PHP and BAPI_CUSTOMER_CREATEFROMDATA1 problem

$
0
0

Hi guys,

 

I am having difficulties creating customers via BAPI_CUSTOMER_CREATEFROMDATA1, the function is working without problems in SE37 but not via RFC.

 

I keep getting the following error.

 

Errors found during saprfc-Calls:

 


saprfc::callFunction('BAPI_CUSTOMER_CREATEFROMDATA1')
Import-Parameter=PI_PERSONALDATA could not be set. (Does it exist?)

 

My parameters are.

 

$personal_data['PI_PERSONALDATA'] = array(    'FIRSTNAME'     =>  'ZSOLDOS',    'LASTNAME'      =>  'SZABOLCS TEST',    'DATE_BIRTH'    =>  '26.05.1987',    'CITY'          =>  'WEBSERVICE LAND',    'STREET'        =>  'DECEBAL 20/6',    'COUNTRY'       =>  'RO',    'COUNTRYISO'    =>  'RO',    'REGION'        =>  'MS',    'TEL1_NUMBER'   =>  '0751380275',    'E_MAIL'        =>  'szabi@bysobi.com',    'LANGU_P'       =>  'RO',    'LANGUP_ISO'    =>  'RO',    'CURRENCY'      =>  'RO'
);


$personal_data['PI_COPYREFERENCE'] = array(
    'SALESORG'      =>  'BYSO',    'DISTR_CHAN'    =>  '01',    'DIVISION'      =>  '01',    'REF_CUSTMR'    =>  '600102'
);




$result = $b2c->sapConnection()->callFunction("BAPI_CUSTOMER_CREATEFROMDATA1",    array(        array("IMPORT","PI_PERSONALDATA",$personal_data['PI_PERSONALDATA']),        array("IMPORT","PI_COPYREFERENCE",$personal_data['PI_COPYREFERENCE'])    )
);


$result_commit = $b2c->sapConnection()->callFunction("BAPI_TRANSACTION_COMMIT",         array(            array("IMPORT","WAIT", ""),            array("EXPORT","RETURN", array()),         )); 

if($b2c->sapConnection()->getStatus() == SAPRFC_OK) {    print_r($result);
} else {    echo 'nope';
}

Re: PHP and BAPI_CUSTOMER_CREATEFROMDATA1 problem

Re: PHP and BAPI_CUSTOMER_CREATEFROMDATA1 problem

$
0
0

Hi Justin,

 

Thank you for the documentation but my problem is that the parameter is not recognized by the RFC call.

 

On the other hand I've made many Z function implementation via PHP, but this standard BAPI seems not to work

Re: How to scroll GUI table in VB

$
0
0

Hello Maxmilian,

 

Can this code be converted to vbscript? I already have sevral vbscripts that interact with Guixt and input assistant and would like vbscript over VBA.

 

 

Thanks for your time and efforts.


Re: How to scroll GUI table in VB

$
0
0

Hello,

 

sorry but TAC QP03 doesn't exists on my test system. So I take TAC OAC0, it is also a table too.

 

OAC0.JPG

 

To search one entry the following code, based on the code discussed here in this thread, works. I am searching for the entry CUSTSTRUCT:

 

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

 

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

 

  '-Variables-----------------------------------------
    Dim SapGuiAuto, application, connection, session
    Dim WshShell, i, j, fldtxt

 

  '-Main----------------------------------------------
    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

 

    Set WshShell = CreateObject("WScript.Shell")

 

    i = session.findById("wnd[0]/usr/tblSAPLSCMS_CREPC_SREP").RowCount

 

    For j = 1 To i

 

      fldtxt = session.findById("wnd[0]/usr/tblSAPLSCMS_CREPC_SREP/txtI_SREP-CREP_ID[0,0]").Text

 

      If fldtxt = "CUSTSTRUCT" Then
        Exit For
      End If

 

      WshShell.AppActivate _

        "Display Content Repositories: Overview"
      WshShell.SendKeys "+{DOWN}"

 

    Next

 

    MsgBox fldtxt & " found in line " & CStr(j)

 

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

 

This is the result:

Result.JPG

Hope it helps. Let us know the results.

 

Cheers

Stefan

 

Re: How to scroll GUI table in VB

$
0
0

I'm getting an error message "Object required: WScript" for the above script and the one I found here..http://scn.sap.com/thread/3336725

 

I modified your previous program like this..

 

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

 

IfNotIsObject(application) Then
    Set SapGuiAuto = GetObject("SAPGUI")
    Set application = SapGuiAuto.GetScriptingEngine
  EndIf

  IfNotIsObject(connection) Then
    Set connection = application.Children(0)
  EndIf

  IfNotIsObject(session) Then
    Set session = connection.Children(0)
  EndIf

Dim ContentToFind
ContentToFind = InputBox("Enter search text") 
'Set WShell = CreateObject("WScript.Shell")
'Set WShell = WScript.CreateObject("WScript.Shell")
'  session.findById("wnd[0]/tbar[0]/okcd").text = "/nSU01D"
'  session.findById("wnd[0]/tbar[0]/btn[0]").press 
'  session.findById("wnd[0]/usr/ctxtUSR02-BNAME").text = "SSHUGA"
'  session.findById("wnd[0]/tbar[1]/btn[7]").press 
'  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG").select

  table = "wnd[0]/usr/tblSAPLQPAATC_PLMK"
  Set tab = session.findById(table)

  'ContentToFind = "& Input"
  ContentToFind = "Trait - YG purity"

  For i = 0To tab.Rows.Count - 1

    '-Search for entry in the table-------------------------------------
      If session.findById(table & "/txtPLMKB-KURZTEXT[11," & CStr(i) & _
        "]").Text = ContentToFindThen
        session.findById(table).verticalScrollbar.position = "" & CStr(i) & ""
        'session.findById("wnd[0]/usr/txtRQPAS-ENTRY_ACT").text = "" & CStr(i) & ""
        session.findById("wnd[0]").sendVKey0
        fld = session.findById(table & "/txtPLMKB-KURZTEXT[11," & CStr(i) & _
        "]").Text
        MsgBox fld & " Found it"
        ExitFor
      EndIf

    '-Send key down-----------------------------------------------------
'      WShell.AppActivate "Display User"
'      WShell.SendKeys "{DOWN}"
'      WScript.Sleep 250

    '-Send page down for the next rows, if the entry was not found------
      If i = tab.Rows.Count - 1Then

'Page down is 82
        session.findById("wnd[0]").sendVKey82
        Set tab = session.findById(table)
        i = 0
      EndIf

    '-Exit if first empty row reach-------------------------------------
      IfTrim(session.findById(table & "/txtPLMKB-KURZTEXT[11," & _
        CStr(i) & "]").Text) = ""Then
        ExitFor
      EndIf

  Next

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

 

 

commented out WShell and using sendVKey 82.

This script runs but is not searching for text "Trait - YG purity" but returns some random text.

I think its not scrolling window right.

 

Thanks a lot!

Re: How to scroll GUI table in VB

$
0
0

Hello,

 

try this:


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

 

  '-Directives----------------------------------
    Option Explicit
   
  '-Variables-----------------------------------
    Dim WshShell
   
  '-Main----------------------------------------
    Set WshShell = CreateObject("WScript.Shell")
    If IsObject(WshShell) Then
      MsgBox "It works"
      Set WshShell = Nothing
    Else
      MsgBox "Can't initialize WScript.Shell"
    End If

 

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

 

Tell us the result.

 

Cheers

Stefan

Re: How to scroll GUI table in VB

$
0
0

I get a popup "It works"

Not sure why I'm getting object required: WScript error.

 

 

Thanks Stefan.

Re: How to scroll GUI table in VB

$
0
0

Hello,

 

did you start your script via a double click on the file in the Windows Explorer or via playback in the SAP GUI for Windows? I never use the playback function. I use always the double click with the correct connection and session number (red marked).

 

Set connection = application.Children(0)

Set session = Connection.Children(0)

 

Try it and let us know the results.

 

Cheers

Stefan

Viewing all 1708 articles
Browse latest View live


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