cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I'm new, How do I script?

Former Member
0 Kudos

I am new to SAP, have been trying to understand it for a while, finally got into it at my job, but I don't know how to write scripts for SAP. I am a beginner, so I don't even know what the different pages/tables/forms are called, but I am an old hand at VBS with excel and access, as well as general computing.

I don't really have access to change anything within SAP that I know of as far as adding fields to the database or forms or changing the way anything looks or operates, but I am trying to make up for my lack of customizability by using scripting. I can make VBS do things in Excel with the data we use, and even prepare it to just be pasted into SAP forms, lists, etc. I have reached a certain limitation though, and that is SAP does not use standard "separate window" processes, and not everything is hotkeyed. I have no way with sendkeys to mark specific rows in task lists, and no way to make it hit the yes button on editing several long texts in a row (sometimes the auto-focus on yes does not activate, otherwise I could just use enter).

I need to know how to get information about customizing my gui with scripting that is native to SAP and integrating the VBS from Excel and Wshell with SAP scripting. Any "SAP scripting for dummies" books that start at a level of a person who has never even seen SAP would be excellent. Tutorial threads and such on here are also welcome.

I am so new to SAP i can't even really tell you what program I am using.

Under system>status>

The pertinent things I see:

SAP data:

Program(GUI)

SAPLCICU

SAP System data:

Component version:

SAP ECC 6.0

Database data:

Database system:

ORACLE

Release

10.2.0.4.0

Anything you can tell me about retrieving data from the database, customizing the actions of SAP through scripting, even a list of valid hotkeys for each type of screen/form/tables/pages, would be miraculously helpful.

Anything you can tell me about which program I am using, shortcuts to useful forums pertaining to this program, etc, would also be helpful beyond belief.

Please be gentle, I am new here and I am aware that I may anger the locals by asking such a basic question, or may have posted this in the wrong spot, etc, and I apologize in advance for any transgression.

Thanks for reading!

Accepted Solutions (1)

Accepted Solutions (1)

thomas_brutigam2
Active Participant
0 Kudos

Well first of all

you can "Record" all your Actions in SAP -

There's a Script-Recorder Built in-

Press Alt / F12

and a Dialog appears with a Stop, Record and Play Button on it ...

here you can give the Script you want to record a name and specify a place to record the script to.

Now you can do nearly everything you want to do to be recorded.

When you are finished - press the Stop Button and the Script-File is generated.

Now you can edit the Script per Editor and take a closer Look at the Actions that you did...

You will see that nearly every Control has it's own name and not exactly the same Properties as it is in Excel or Acces /VBA

Also a good way is to just read the Forum from the last page to the First - (so I did)

Sure only first take the Topics and if you think it's interisting open it and read it.

although you should try and try and try (and Error) (as you know thats the best way to learn)

and if you have Questions- just ask.

Remember theres no stupid questions- only stupid answers

Greetings

Thomas Bräutigam

Former Member
0 Kudos

Hi Thomas,

Myself i am new member to this community.

I am good in excel and excel VBA and i do a lot of macro in excel in order to save my time.

I am relaly intersting in learning SAP VBA, i mean i want to do automation work in SAP. It would be really greatful if you help me in learning - How to record, write and also if you can give me any author name book name to learn the same.

Actually i process PO & non-PO invoice in MIRO which take 15 minute to process the invoice.

I want to do some automation where i will put the data in excel e.g invoice no, invoice date etc and the data should be put into SAP using T-code MIRO automically.

If there is anyway to do this in faster way, kindly let me know.

Thanks in advance for your help in this matter.

thomas_brutigam2
Active Participant
0 Kudos

Hi danpre,

like I said before ...

it's not VBA (just a little less) it is VBS(cript)

The most language-Elements are the same in VBA (or VB) as in VBScript.

If you already have recorded the complete Actions for 1 Invoice (Alt / F12) then you can Edit the Script:

To get a Connection to an Existing Excel-Workbook you have to refer to the Excel-Object:


Set xclapp = SetObject("Excel.Application")

Now for the Workbook:


Set xclwbk = xclapp.Workbooks.Open("[path and workbookname]"} 'for e.g. C:\invoice.xls

and the last step the Worksheet:


Set objSheet = xclwbk.Sheets("Tabelle1")

Now you can Access all Data in this Sheet via that code:


session.findbyId(wnd[0]------).Value = objsheet.cells(1,1).value 'for example Never use the Range Object---

before you let the first Invoice run thru SAP you should make a "TestRun" for Debugging...

Therefor you should provide an Error-Handler.

That is not as Easy as in VB or VBA...

Its totally Different:


'For Errorhandling:
On Error resum next  'no other way to go ...:'(
If err.number <> 0 then
msgbox err.number & err.description
'here the Code for Errorhandling
End if
'and go on

Last but not least a very meantfull tip: go at it slow !

at first only try Things to automate where nothing can go wrong (because of that not really good error-handling).

If you want further details ...

just ask them here !

Like i said theres no silly questions- only stupid answers

Greetings...

Thomas Br

Former Member
0 Kudos

HI Thomas,

Thanks for the reply.

I have never recorded anything in SAP.

Let me tell u what i need.

I have the details in excel sheet information of the vendor for eg invoice number,invoice date etc

And i want to put this detail in SAP using Tcode MIRO, how should i do this with automation as i have 100 invoice to be processed daily.

I want to tell SAP to take the date from the excel and put in the SAP using t-code MIRO.

Kindly explain me in detail how to go ahead and also you can give me any author book name for VB script so i can learn something from there as well.

Thanks again for your prompt relply.

thomas_brutigam2
Active Participant
0 Kudos

I have never recorded anything in SAP.

Then it's about Time ...

Press Alt + F12 an a Dialog will appear with a Record, Stop and a Play Button.

There is also a "..." key to select the Path And Filename to Enter a Path and Filename.

After you have the Script you want to Record a valild Path and Filename you can press the "Record" Button.

Now all Action you do in SAP will be Recorded.-

You will have to do one of your invoices to get the complete Script.

When you're done with all action Press the Stop Button.

Now you can open the vbs -Script in the Folder you saved it to.

Edit the File like i mentioned in my Posting above and get the Values from Excel, and replace the Data from your first Invoice.

Since you said that you know VBA, I guess you know what a For Next loop is ?

Kindly explain me in detail how to go ahead and also you can give me any author book name for VB script so i can learn something from there as well.

Since I learned VB (and VBA / S) by myself (try and Error - and thanks to the Internet)

I really dont have a book tip for VBS - just use Google (or anything else ...)

If you need a good advise, I think this Forum here is a good place to ask ?!

Greetings

Thomas Bräutigam

Former Member
0 Kudos

Hello Thomas,

At the outset, I am sorry if I am posting my question in the wrong thread.

I used the script as you said and automated all my work. But I am unable to run it from my colleague system (when I copied the same script file and pasted in my colleague system). He is having the same access rights which I have.

Any suggestios or help..

Thanks

Murugan

thomas_brutigam2
Active Participant
0 Kudos

Is Scripting Enabled on his System ?

look in the Options (Settings)...

Or is Scripting enabled but the Script is not running ?

Greetings

Thomas Bräutigam

Edited by: Thomas Br on Aug 14, 2010 5:13 PM

Former Member
0 Kudos

Hello Thomas,

Scripting is enabled in his system but the script is not running. I doubt its related something with user id?

Thanks

Murugan

Former Member
0 Kudos

Hello Thomas,

I am delighted that I have done VB Scripting a little bit advanced (copied from your thread...:-)) where it runs the reports and saves on my desktop as TXT file and converts into excel and triggers my excel macro..it all seems weired how fast my report was completed. I have done time study and my automation work and kept my fingers crossed. Automation took 4 minutes where as Manual work it took2hr 6 min to complete.

Now my only concern is This scripting is not working in my friends system. I tested in all the system with script enabled but no luck..:-(.

I carefully tested below code and it is stopping at 18th line (copied till 18th line) in all the systems saying "Control id could not be found". Any ideas?. If I solve this...then I would be much appreciated in my company...:-)

If Not IsObject(application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

Set connection = application.Children(0)

End If

If Not IsObject(session) Then

Set session = connection.Children(0)

End If

If IsObject(WScript) Then

WScript.ConnectObject session, "on"

WScript.ConnectObject application, "on"

End If

session.findById("wnd[0]").resizeWorkingPane 178,28,false

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

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

session.findById("wnd[0]/usr/ctxtRS38M-PROGRAMM").text = "yef_display_excptn_notes"

script_man
Active Contributor
0 Kudos

Hi Murugan,

somewhere there is a difference between the own and the external system.

This difference can find out by recording the erroneous row in the external system with the local script recorder, and then comparing the two rows.

Regards,

ScriptMan

thomas_brutigam2
Active Participant
0 Kudos

Hi,

have you "recorded" the Sript on your "friends" Workstaition as well ?

or try the Script-Assistant one below Scripting Tool...

Call the TA sa38 and than try to locate the Textcontrol you want to fill

Enable the Assistant (Hit Test - *think its called so in English)

and then point with your Mouse to the Control!

A Red Frame should appear and the Assistant will Tell you the name of the Control.

if this is the same as in your Script there is another fault ...

Only needs testing an Debugging

Edit:

Just got another Idea :

is that a "Personal Setting" or Layout ? "yef_...

can it be that your CoWorkers cant long for that ?

Greetings

Thomas Bräutigam

(right now without SAP)

Klingon Rule No 99

Our Software needs no Debugging

Edited by: Thomas Br on Aug 17, 2010 12:48 PM

Former Member
0 Kudos

Hello Scriptman / Thomas,

I am very much delighted in sharing another idea which I implemented and tested successful...:-o). Its simple..I have done all the Scripting of my work and scheduled all the scripts using windows scheduler. This worked great with out my finger on keyboard.

My next task - (Since I know Excel VBA) I am going to write a code in excel to trigger the SAP Scripting at a given time..so that I Can link my other excel macros to run after SAP scripting ends.

In answering to both of you, with your different valuable approach (suggestion). I am going to test it tomorrow and will let you know...I Desperately need this solution..

Thomas,

that Yef...is a Global variant and not user specific.

Thanks a ton..

Murugan

Former Member
0 Kudos

Hello Thomas / Scriptman,

I have completed my excel vba that triggers VB Scripting but with liittle effort (not so easy as I thought - because MS office does not speak to VBS and as a reason by invoking shell32.dll I was able to complete it). Just to share the knowlege, I am pasting the code..

Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Sub Murugan()
    On Error Resume Next
    ShellExecute 0&, vbNullString, "C:\Documents and Settings\venkatmg\Desktop\xxxxxxxxx.vbs", vbNullString, vbNullString, vbNormalFocus
    On Error GoTo 0
    End Sub

Please remember: xxxxx.vbs should be your scripting file.

As I said, I have carefully compared and analysed the code by re-doing the playback script in my system and my friend sytem.

Interestingly the codes are different..:-(...Please and please help.. I am pasting my code and my friends code..

My Friend code:

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 = "sa38"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxt").text = "yef_display_excptn_notes"
session.findById("wnd[0]/usr/ctxt").caretPosition = 24
session.findById("wnd[0]").sendVKey 19
session.findById("wnd[0]/usr/lbl[1,6]").setFocus
session.findById("wnd[0]/usr/lbl[1,6]").caretPosition = 2
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/tbar[1]/btn[40]").press
session.findById("wnd[0]/mbar/menu[0]/menu[4]/menu[2]").select
session.findById("wnd[1]/usr/sub/1/rad[1,0]").select
session.findById("wnd[1]/usr/sub/1/rad[1,0]").setFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxt").text = "C:\Documents and Settings\kumarish\Desktop\Open WC.xls"
session.findById("wnd[1]").sendVKey 0

My code

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").resizeWorkingPane 178,28,false
session.findById("wnd[0]/tbar[0]/okcd").text = "sa38"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRS38M-PROGRAMM").text = "yef_display_excptn_notes"
session.findById("wnd[0]/usr/ctxtRS38M-PROGRAMM").caretPosition = 24
session.findById("wnd[0]/tbar[1]/btn[18]").press
session.findById("wnd[1]/usr/ctxtRS38M-SELSET").text = "ap - open WC"
session.findById("wnd[1]/usr/ctxtRS38M-SELSET").caretPosition = 12
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/mbar/menu[0]/menu[4]/menu[2]").select
session.findById("wnd[1]/usr/sub:SAPLSPO5:0101/radSPOPLI-SELFLAG[1,0]").select
session.findById("wnd[1]/usr/sub:SAPLSPO5:0101/radSPOPLI-SELFLAG[1,0]").setFocus
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[1]/usr/ctxtRLGRAP-FILENAME").text = "C:\Documents and Settings\kumarish\Desktop\wc.xls"
session.findById("wnd[1]/usr/ctxtRLGRAP-FILENAME").caretPosition = 49
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 3

Thanks a lot for your patience and helping. I will be waiting for your reply..

Thanks

Murugan

Edited by: murugan.guna on Aug 24, 2010 7:06 PM

Former Member
0 Kudos

Hello Thomas / Scriptman

Please ignore my previous message as the format is different and no one can understand.

I have completed my excel vba that triggers VB Scripting but with liittle effort (not so easy as I thought - because MS office does not speak to VBS and as a reason by invoking shell32.dll I was able to complete it). Just to share the knowlege, I am pasting the code..

Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Sub Murugan()
    On Error Resume Next
    ShellExecute 0&, vbNullString, "C:\Documents and Settings\venkatmg\Desktop\xxxxxxxxx.vbs", vbNullString, vbNullString, vbNormalFocus
    On Error GoTo 0
    End Sub

Please remember: xxxxx.vbs should be your scripting file.

Former Member
0 Kudos

Hello Thomas and Script Man,

With herculean efforts, I was able to figure out the solution..:-) as to why the sap Macros are not running in another systems when it was running in my system (when every user has enabled the scripting option and have the same access rights what I have).

Reason - Low speed connection is disabled in my system (under saplogon connection options) and where as in another systems it is "Enabled". Hence I disabled it and enjoyed the fruit..:-)

Conclusion :

If users want to run SAP scripts they received from somebody else, then they must ensure that "Low speed connection" is disabled (under their SapLogon connection)..

If you have any queries please let me know. I would be glad to help..

Thanks

Murugan

Former Member
0 Kudos

Hello Murugan,

I am just testing this script , and it's really works great ..! really appreciate your hardwork and share it with us here.

I have another question:

once the t-code running and have the result , I export the result to Excel file , so from SAP then pop up a workbook in excel file but this workbook will automatically ended/close if we switch to another menu , while I should do safe as the workbook to certain folder & file name before it's disappear , What is the script in macro excel to do this ?

Thank you .

Best regards,

Agung

Former Member
0 Kudos

The user guide for scripting SAP says that SAPGUI is recordable from AppleScript's Script Editor. However, that appears not to be the case when we attempt it.

We have already recorded the queries we need to perform as SAPGUI scripts. If we could find a way to simply run those scripts from AppleScript, we would be done. We don't find a "run script" command in SAPGUI's AppleScript dictionary.

Thanks for any help!

Albert

Former Member
0 Kudos

Average of Values from SAP Find Tab to Fill in Excel Sheet

Hi there,

I'm trying to search a material name in material master using find page in SAP.

Then if no. of hits(occurrences) is >= 3 then whatever values are there for particular material in find tab, I will take average of that, and fill the values in Excel.

If number of hits ❤️ , then next go ahead.

Please, provide me the solution. If not possible with average function, we can do it using SUM of all and then divide it by n occurrences.

thomas_brutigam2
Active Participant
0 Kudos

Hi mohan,

please make a New Post ....

and plz describe your Problem a little more (TA and so on ....)


live long and prosper

Former Member
0 Kudos

Hi Thomas,

I didn't know that.

After reading your response now I find it's very easy to write VBscript using the in-build feature. great

Thanks

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Murugan

I have a question. Did you write test scripts or did you just test it? I am also new to testing. I have been asked to write test script for SAP in AP module for Payment. I have downloaded a template from Solution Manager but I am not able to write the steps for testing? Hence I asked you if you wrote or tested.. Appreciate guidance.

Thanks