How You Can Automate Work In SAP With VBScript
For several years of working in SAP, as a user, I made a large number of different scripts to facilitate work in SAP, because SAP “out of the box” is quite inconvenient for fast and efficient work. Particularly annoying is that at one time it is impossible to insert more rows into the table that is displayed on the screen. It is necessary to insert parts, scrolling the table. On a small widescreen monitor, it’s so terribly inconvenient. I somehow long ago, before making scripts, my monitor set vertically and rotated the image to display more lines.
So, I decided to share my experience with the public.
To achieve the development of the things necessary for work in the company is practically (and in fact) unreal. Our company is large, and gets a bunch of approvals, and tries to save money on SAP programmers! Therefore, I quietly self-automated my work (and not only my own) using VBScript. As you may know that a running a third party software or any executable file on the company’s computers strictly prohibits by all sorts of policies but VBScript runs smoothly if it’s configured properly.
- The main methodology for composing scripts was the recording of actions in the macro of the SAP itself with further analysis of the recorded information, learning help, searching information on the Internet, etc.
On the Internet, there are many examples of working with SAP using VBScript, which is launched by double-clicking on the VBS file, but they are almost all designed to work with the first SAP window. At the beginning of such examples, there is usually a code session.findById (“wnd [0]”). Maximize, which expands the SAP window.
To work with such scripts, “programmed” under the first window – is inconvenient for the following reasons:
- The SAP Logon window must be closed or minimized to the tray. Otherwise, the script will try to work in it.
- In the first window, another transaction may be executed or will be in reports, or a transaction will be opened for entering parameters. In general, if something is opened in the first window, except for the menu – launching transactions through the script does not work.
- In the first window, you can open a connection to another server.
And, trying to help myself I wrote a script, which unloads the tree of GUI elements of the first SAP window into an XML file. It turns out like this:
Enumeration of the SAP GUI elements
</pre> Dim currentNode Set xmlParser = CreateObject ("Msxml2.DOMDocument") 'Creating an XML declaration xmlParser.appendChild (xmlParser.createProcessingInstruction ("xml", "version = '1.0' encoding = 'windows-1251'")) Set SapGuiAuto = GetObject ("SAPGUI") Set application = SapGuiAuto.GetScriptingEngine Set connection = application.Children (0) Set session = connection.Children (0) WScript.ConnectObject session, "on" WScript.ConnectObject application, "on" 'Maximize the SAP window session.findById ("wnd [0]"). maximize enumeration "wnd [0]" 'enumeration' wnd [0] / usr " MsgBox "Done!", VbSystemModal Or vbInformation Sub enumeration (SAPRootElementId) Set SAPRootElement = session.findById (SAPRootElementId) 'Creating a root element Set XMLRootNode = xmlParser.appendChild (xmlParser.createElement (SAPRootElement.Type)) enumChildrens SAPRootElement, XMLRootNode xmlParser.save ("C: \ SAP_tree.xml") End Sub Sub enumChildrens (SAPRootElement, XMLRootNode) For i = 0 To SAPRootElement.Children.Count - 1 Set SAPChildElement = SAPRootElement.Children.ElementAt (i) 'Create a node Set XMLSubNode = XMLRootNode.appendChild (xmlParser.createElement (SAPChildElement.Type)) 'Attribute Name Set attrName = xmlParser.createAttribute ("Name") attrName.Value = SAPChildElement.Name XMLSubNode.setAttributeNode (attrName) 'Attribute Text If (Len (SAPChildElement.Text)> 0) Then Set attrText = xmlParser.createAttribute ("Text") attrText.Value = SAPChildElement.Text XMLSubNode.setAttributeNode (attrText) End If 'Attribute Id Set attrId = xmlParser.createAttribute ("Id") attrId.Value = SAPChildElement.Id XMLSubNode.setAttributeNode (attrId) 'If the current object is a container, then iterate through the child elements If (SAPChildElement.ContainerType) Then enumChildrens SAPChildElement, XMLSubNode Next End Sub <pre>
Commenting on one of the lines:
- enumeration «wnd [0]»
- enumeration «wnd [0]/usr»
Then we get the results of bypassing the elements of either the entire SAP window or only UserArea (without the menu, toolbar, status bar).
A few nuances:
- If some element is not visible on the screen, then it does not exist, and there is neither a name nor an ID. To get to it, you need to deploy and make visible all the upstream elements. For example:
- In transaction ME51N, you can not specify a “Header Note” if the header is collapsed. You must first expand the title.
- In transaction ME21N, to get to the field “Our Sign” – you need not only to expand the title, but also to switch to the “Communication” tab.
- When updating the screen, almost all GUI-objects are created anew, and they need to be searched again by name or ID. When you access objects created in the script before updating the screen, an error will occur.
- All VBScript commands that interact with the SAP GUI elements are executed in synchronous mode, i.e. the execution of the VBScript code does not go on until SAP executes the command. This is very convenient, you do not have to insert pauses and/or cycles everywhere, checking the changes on the screen or waiting for the appearance of any message box.
- While the script is running and interacting with one window (mode) of SAP – you can safely work as in other modes of SAP, and in most Windows or other applications.
My scripts are run directly from the SAP. To do this, an object of type “Web address or file” is created in SAP in the selected folder, specifying the full path to the script file.
For scripts, I use WSF (Windows Script File) files, which consist of two parts:
A common file under the loud name SDK.vbs containing the code used in each script, plus several functions and procedures that are not used in all scripts.
Actually, VBScript itself, which performs our tasks. VBScript executes commands exactly in the SAP window from which it is running.
Windows Script File file structure
<script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> ... Script code ... </ script>
The WSF can consist of several scripts (in different programming languages), scattered over separate files, and registered in the WSF itself. When you start WSF, the code from the SDK.vbs file is executed first, and then the code of the script itself. Because WSF runs directly from SAP – it will be guaranteed to run exactly in the same window from which it is running. An active session is defined by the Set session = application.ActiveSession () command.
- SDK.vbs consists of a code for connecting to SAP and defining an active session, and several auxiliary procedures and functions.
Further in the script for the convenience of work, several objects and variables are defined:
- Wnd0 and UserArea – are used almost everywhere,
- Menubar, Statusbar, and UserName – in some scripts.
Additional procedures and functions:
- Run the transaction.
- Emulation of pressing the buttons Enter, F3, F5, F8.
- The dialog of opening a csv or text file with the ability to create a file for writing. The file for writing is created in the same folder and has the same name, but “out” is added before the extension.
- Filling one row in the table (for transaction ME51N).
SDK.vbs
'Create a WScript.Shell object Set WshShell = WScript.CreateObject ("WScript.Shell") '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'Connecting to SAP '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'Create an object Set SapGuiAuto = GetObject ("SAPGUI") 'Create an object of type GuiApplication (COM-interface) Set application = SapGuiAuto.GetScriptingEngine () 'Creating an object of type GuiSession is a session that corresponds to the active SAP window 'Ie. when you start WSF, the script itself will run in the same SAP window from which it is running Set session = application.ActiveSession () WScript.ConnectObject session, "on" WScript.ConnectObject application, "on" 'Create an object of type GuiMainWindow Set Wnd0 = session.findById ("wnd [0]") 'Create an object of type GuiMenubar Set Menubar = Wnd0.findById ("mbar") 'Create an object of type GuiUserArea Set UserArea = Wnd0.findById ("usr") 'Create an object of type GuiStatusbar Set Statusbar = Wnd0.findById ("sbar") 'Define the user's login UserName = session.Info.User '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'Supporting procedures and functions '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'Starting the transaction Sub startTransaction (transaction_name) Wnd0.findById ("tbar [0] / okcd"). Text = transaction_name pressEnter () End Sub 'Pressing the "Enter" Sub pressEnter () Wnd0.sendVKey 0 End Sub 'Pressing F2 Sub pressF2 () Wnd0.sendVKey 2 End Sub 'Pressing the F3 button Sub pressF3 () Wnd0.sendVKey 3 End Sub 'Pressing the F5 Sub pressF5 () Wnd0.sendVKey 5 End Sub 'Pressing the F8 button Sub pressF8 () Wnd0.sendVKey 8 End Sub 'Dialog for selecting a file, creating read streams from a file and writing to a file Function selectFile (createOuputFile) Set objDialog = CreateObject ("UserAccounts.CommonDialog") 'Fill in the properties and open the dialog With objDialog .InitialDir = WshShell.SpecialFolders ("Desktop") 'The start folder is the desktop .Filter = "Text files (* .csv; *. Txt) | * .csv; *. Txt" result = .ShowOpen End With 'If the file is not selected - we exit If (result = 0) Then WScript.Quit inputFile = objDialog.FileName 'Full path to the selected file Set fso = CreateObject ("Scripting.FileSystemObject") Set inputStream = fso.OpenTextFile (inputFile) 'Create output file? If (createOuputFile) Then outputFile = Left (inputFile, Len (inputFile) - 3) & "out" & Right (inputFile, 4) Set outputStream = fso.CreateTextFile (outputFile, True) 'Return an array from the read stream from the file and the write stream to the file selectFile = Array (inputStream, outputStream) Else 'Return the read stream from file selectFile = inputStream End If End Function 'Fill one row in the table (for ME51N) Sub fill_row (row, material, kolvo, zavod, zatreboval) Set grid = session.findById (UserArea.findByName ("GRIDCONTROL", "GuiCustomControl"). Id & "/ shellcont / shell") grid.modifyCell row, "KNTTP", "K" 'Account assignment type grid.modifyCell row, "MATNR", material 'Material grid.modifyCell row, "MENGE", number 'Number grid.modifyCell row, "NAME1", factory 'Factory grid.modifyCell row, "LGOBE", "0001 '' Warehouse grid.modifyCell row, "AFNAM", requested 'Requested End Sub
Next, I will give examples of scripts with comments and a small description.
Run the transaction IQ09, insert the serials from the clipboard, execute the transaction.
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> 'Run the transaction startTransaction ("IQ09") 'Multiple selection' button UserArea.findById ("btn% _SERNR _% _ APP _% - VALU_PUSH"). Press () 'Button "Load from the buffer" session.findById ("wnd [1] / tbar [0] / btn [24]"). Press () 'Copy button (F8) pressF8 () 'Execute button (F8) pressF8 () </ script> </ job>
And, immediately before running the script, you need to copy the column from the serial numbers to the clipboard, for example, from Excel or a text file.
Goods receipt for the current month (transaction MB51)
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> 'Determine the first and last days of the current month curr_date = Date () curr_month = Month (curr_date) curr_year = Year (curr_date) curr_day = Day (curr_date) date_begin = DateSerial (curr_year, curr_month, 1) date_end = DateSerial (curr_year, curr_month + 1, 0) 'Run the transaction startTransaction ("MB51") 'Fill / clear input fields UserArea.findById ("ctxtMATNR-LOW"). Text = "100000" 'Material UserArea.findById ("ctxtWERKS-LOW"). Text = "9999" 'Factory UserArea.findById ("ctxtLGORT-LOW"). Text = "0001" 'Warehouse UserArea.findById ("ctxtBWART-LOW") Text = "101" 'Movement type UserArea.findById ("ctxtBUDAT-LOW"). Text = date_begin 'Posting date - the beginning of the interval UserArea.findById ("ctxtBUDAT-HIGH"). Text = date_end 'Posting date - end of interval UserArea.findById ("ctxtLIFNR-LOW"). Text = "" UserArea.findById ("ctxtBUKRS-LOW"). Text = "" UserArea.findById ("ctxtEBELN-LOW"). Text = "" 'Purchase order UserArea.findById ("txtMAT_KDPO-LOW"). Text = "" 'Pos. sales order UserArea.findById ("txtZEILE-LOW"). Text = "" 'Pos. doc. material UserArea.findById ("txtMBLNR-LOW"). Text = "" 'Material Document UserArea.findById ("txtMJAHR-LOW"). Text = "" 'YearDocumMaterial pressF8 () 'Detail list button' Wnd0.findById ("tbar [1] / btn [48]"). Press () 'Menu' Settings -> View -> Select ... " Menubar.findById ("menu [3] / menu [2] / menu [1]"). Select () 'We select the formats "X SPECIAL TO USE" session.findById ("wnd [1] / usr / ssubD0500_SUBSCREEN: SAPLSLVC_DIALOG: 0501 / cmbG51_USPEC_LBOX"). Key = "X" 'Click on the 3rd format from the top session.findById ("wnd [1] / usr / ssubD0500_SUBSCREEN: SAPLSLVC_DIALOG: 0501 / cntlG51_CONTAINER / shellcont / shell") currentCellRow = 3 session.findById ("wnd [1] / usr / ssubD0500_SUBSCREEN: SAPLSLVC_DIALOG: 0501 / cntlG51_CONTAINER / shellcont / shell"). clickCurrentCell () </ script> </ job>
At the beginning of the script, the first and last days of the current month are determined. In addition, some input fields that can be filled after the previous transaction start are cleared. The table uses a previously created format (user-specific), which must be the third in the list. The sequence number of the format is easy to fix in the code.
Outgoing deliveries for the last month (transaction VL06O)
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> 'Determine the first and last days of the last month curr_date = Date () curr_month = Month (curr_date) curr_year = Year (curr_date) curr_day = Day (curr_date) curr_month = curr_month - 1 date_begin = DateSerial (curr_year, curr_month, 1) date_end = DateSerial (curr_year, curr_month + 1, 0) 'Run the transaction startTransaction ("VL06O") 'Button' List of deliveries - ref. N ' UserArea.findById ("btnBUTTON6"). Press () 'Button "Call option ..." Wnd0.findById ("tbar [1] / btn [17]"). Press () 'Enter the name of the format session.findById ("wnd [1] / usr / txtV-LOW"). Text = "MY_FORMAT" 'Execute button (F8) pressF8 () 'Enter the interval UserArea.findById ("ctxtIT_WTIST-LOW"). Text = date_begin UserArea.findById ("ctxtIT_WTIST-HIGH"). Text = date_end 'Execute button (F8) pressF8 () 'Select format ... button Wnd0.findById ("tbar [1] / btn [33]"). Press () 'We select the formats "X SPECIAL TO USE" session.findById ("wnd [1] / usr / ssubD0500_SUBSCREEN: SAPLSLVC_DIALOG: 0501 / cmbG51_USPEC_LBOX"). Key = "X" 'Click on the 3rd format session.findById ("wnd [1] / usr / ssubD0500_SUBSCREEN: SAPLSLVC_DIALOG: 0501 / cntlG51_CONTAINER / shellcont / shell") currentCellRow = 3 session.findById ("wnd [1] / usr / ssubD0500_SUBSCREEN: SAPLSLVC_DIALOG: 0501 / cntlG51_CONTAINER / shellcont / shell"). clickCurrentCell () </ script> </ job>
At the beginning of the script, the first and last days of the last month are determined. The remaining parameters of the transaction started are stored in the previously created MY_FORMAT_2 format. The table also uses the previously created format (user-specific), which must be the third one in the list.
Removing medium-slip prices (transaction MM43)
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> factory = InputBox ("Enter factory code") If (zavod = "") Then WScript.Quit 'File selection dialog streams = selectFile (True) Set inputStream = streams (0) Set outputStream = streams (1) 'Run the transaction startTransaction ("MM43") 'We read the lines from the file until we reach the end Do While (Not inputStream.AtEndOfLine) 'Introducing the plant UserArea.findById ("ctxtRMMW1-VZWRK"). Text = zavod 'Read the material from the file material = inputStream.ReadLine () 'We paste the material UserArea.findById ("ctxtRMMW1-MATNR"). Text = material 'Button "Enter" pressEnter () 'Logistics tab: CenterRasp' UserArea.findById ("tabsTABSPR1 / tabpSP05"). Select () 'Button "Accounting" UserArea.findById ("tabsTABSPR1 / tabpSP05 / ssubTABFRA1: SAPLMGMW: 2004 / subSUB9: SAPLMGD2: 2480 / btnMBEW_PUSH"). Press () 'Retrieve the price price = UserArea.findById ("subSUB3: SAPLMGD2: 2802 / txtMBEW-VERPR"). Text 'We remove the point in the price price = Replace (price, ".", "") 'Back button (F3) pressF3 () 'Back button (F3) pressF3 () 'We write material and price to the file outputStream.WriteLine (material & vbTab & price) Loop 'Back button (F3) pressF3 () inputStream.Close () outputStream.Close () MsgBox "Done!", VbSystemModal Or vbInformation </ script> </ job>
Materials for which you want to get medium-slip prices – are in a text file and located in a column. The script starts transaction MM43, then switches over tabs, presses the button to get to the required field. The resulting price is written to the new file along with the material (via tabulation).
List of shipments with the end dates of loading (transaction VT16)
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> 'Determine the first day of the current month curr_date = Date () curr_month = Month (curr_date) curr_year = Year (curr_date) date_begin = DateSerial (curr_year, curr_month, 1) 'Run the transaction startTransaction ("VT16") 'Button "Enter" pressEnter () 'Interval' CurrentConfiguration ' UserArea.findById ("ctxtK_DALEN-LOW"). Text = date_begin UserArea.findById ("ctxtK_DALEN-HIGH"). Text = "31.12.9999" 'Type of transportation UserArea.findById ("ctxtK_SHTYP-LOW"). Text = "0001" 'Fill shipping points UserArea.findById ("btn% _A_VSTEL _% _ APP _% - VALU_PUSH"). Press () Set table = session.findById ("wnd [1] / usr / tabsTAB_STRIP / tabpSIVA / ssubSCREEN_HEADER: SAPLALDB: 3010 / tblSAPLALDBSINGLE") table.findById ("ctxtRSCSEL_255-SLOW_I [1,0]"). Text = "1111" table.findById ("ctxtRSCSEL_255-SLOW_I [1,1]"). Text = "2222" table.findById ("ctxtRSCSEL_255-SLOW_I [1,2]"). Text = "3333" session.findById ("wnd [1] / tbar [0] / btn [8]"). Press () 'Execute button (F8) pressF8 () 'Menu item Settings -> View options -> Select ... " Menubar.findById ("menu [3] / menu [0] / menu [1]"). Select () 'Choose the first format in the list session.findById ("wnd [1] / usr / lbl [1,3]"). setFocus () 'Button "Enter" pressEnter () </ script> </ job>
Transportation is selected from the interval – from the first day of the current month to 31.12.9999. The date of the first day of the current month is determined at the beginning of the script. Points of shipment are indicated. For the generated report, the first format in the list is selected.
The following three scripts are designed to post shipment shipments with a date equal to the end date of the loading.
Shipped, but not conducted, outbound deliveries (transaction VL06O)
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> 'Run the transaction startTransaction ("VL06O") 'Button' List of deliveries - ref. N ' UserArea.findById ("btnBUTTON6"). Press () 'Button "Call option ..." Wnd0.findById ("tbar [1] / btn [17]"). Press () 'Enter the name of the format session.findById ("wnd [1] / usr / txtV-LOW"). Text = "MY_FORMAT_2" 'Clear the field' Created ' session.findById ("wnd [1] / usr / txtENAME-LOW"). Text = "" 'Button "Run" pressF8 () 'Button "Run" pressF8 () </ script> </ job>
The table uses a previously created format.
Run the transaction VT16, insert the delivery numbers from the clipboard, execute the transaction.
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> 'Run the transaction startTransaction ("VT16") 'We close the unnecessary window session.findById ("wnd [1] / tbar [0] / btn [0]"). Press () 'Multiple choice' button for outbound deliveries UserArea.findById ("btn% _S_VBELN _% _ APP _% - VALU_PUSH"). Press () 'Button "Load from the buffer" session.findById ("wnd [1] / tbar [0] / btn [24]"). Press () 'Copy button (F8) pressF8 () 'Execute button (F8) pressF8 () 'Menu item Settings -> View options -> Select ... " Menubar.findById ("menu [3] / menu [0] / menu [1]"). Select () 'Choose the first format in the list session.findById ("wnd [1] / usr / lbl [1,3]"). setFocus () 'Button "Enter" pressEnter () </ script> </ job>
Similarly, the column from the supply numbers must first be copied to the clipboard.
Shipped, but not carried out, outbound shipments from the clipboard (transaction VL06O)
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> 'Starting the transaction startTransaction ("VL06O") 'Button "For OM" UserArea.findById ("btnBUTTON4"). Press () 'Deletion of the start and end dates' Date of the DvizhMtr plans " UserArea.findById ("ctxtIT_WADAT-LOW"). Text = "" UserArea.findById ("ctxtIT_WADAT-HIGH"). Text = "" 'Multiple choice' button for transportation UserArea.findById ("btn% _IT_TKNUM _% _ APP _% - VALU_PUSH"). Press () 'Button "Load from the buffer" session.findById ("wnd [1] / tbar [0] / btn [24]"). Press () 'Execute button (F8) pressF8 () 'Execute button (F8) pressF8 () 'If there is no button "Position Perspective" - then there are no supplies If (Wnd0.findById ("tbar [1] / btn [18]"). Text = "Position view") Then 'Allocate all UserArea.findById ("cntlGRID1 / shellcont / shell"). SelectAll 'Menu' Subsequent functions -> Post goods issue posting ' Menubar.findById ("menu [4] / menu [7]"). Select () 'In the window that appears, we erase the first two characters (the day of the month) in the date field of the actual material movement WshShell.SendKeys "{HOME} {DELETE} {DELETE}" Else MsgBox "No deliveries!", VbSystemModal Or vbExclamation 'Back button (F3) pressF3 () 'Back button (F3) pressF3 () End If </ script> </ job>
The column with the transport numbers must first be copied to the clipboard from the results of transaction VT16 (previous script). After the transaction ends:
- If there are no supplies in the report, a corresponding message is displayed, then the script exits.
- If there are deliveries in the report – the menu item “Execute goods issue posting” is selected, in the appeared window with posting date the first two symbols (ie day) are erased. Next, the script exits and the user must enter the desired day and press Enter.
The presence/absence of deliveries in the report is determined by the presence/absence of the menu. The processing of errors by the script is included in advance.
While writing the article, I decided to combine the first two scripts for posting shipped shipments into one.
List of transportations for shipped, but not carried out, outbound deliveries.
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> '################################################# ############# 'Run the first transaction startTransaction ("VL06O") 'Button' List of deliveries - ref. N ' UserArea.findById ("btnBUTTON6"). Press () 'Button "Call option ..." Wnd0.findById ("tbar [1] / btn [17]"). Press () 'Enter the name of the format session.findById ("wnd [1] / usr / txtV-LOW"). Text = "MY_FORMAT_3" 'Clear the field' Created ' session.findById ("wnd [1] / usr / txtENAME-LOW"). Text = "" 'Button "Run" pressF8 () 'Button "Run" pressF8 () Set grid = UserArea.findById ("cntlGRID1 / shellcont / shell") 'GuiGridView rowCount = grid.RowCount 'Total filled rows visibleRowCount = grid.VisibleRowCount 'The number of visible rows 'Scroll the table to the end, so that all the supplies are copied firstVisibleRow = visibleRowCount Do While (firstVisibleRow <rowCount) grid.firstVisibleRow = firstVisibleRow firstVisibleRow = firstVisibleRow + visibleRowCount Loop 'Select the column with deliveries grid.SelectColumn ("VBELN") 'Copy the selected column to the buffer using the context menu grid.ContextMenu () grid.SelectContextMenuItemByText "Copy Text" 'Exit the SAP menu pressF3 () pressF3 () pressF3 () '################################################# ############# 'We start the second transaction startTransaction ("VT16") 'We close the unnecessary window session.findById ("wnd [1] / tbar [0] / btn [0]"). Press () 'Multiple choice' button for outbound deliveries UserArea.findById ("btn% _S_VBELN _% _ APP _% - VALU_PUSH"). Press () 'Button "Load from the buffer" session.findById ("wnd [1] / tbar [0] / btn [24]"). Press () 'Copy button (F8) pressF8 () 'Execute button (F8) pressF8 () 'Menu item Settings -> View options -> Select ... " Menubar.findById ("menu [3] / menu [0] / menu [1]"). Select () 'Choose the first format in the list (should be "Lexa_1") session.findById ("wnd [1] / usr / lbl [1,3]"). setFocus () 'Button "Enter" pressEnter () </ script> </ job>
The script uses the copy of the column with the delivery numbers from transaction VL06O with the table scrolling to the end (so that all the supplies are copied).
Mass registration of the date and time of PlanirovTrans in the incoming deliveries (transaction VL32N)
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> data_prihoda = InputBox ("Enter the date in the format: 010213, 01022013, 01.02.13, 01.02.2013") If (data_prihoda = "") Then WScript.Quit vremya_prihoda = InputBox ("Enter the time in the format: 0130, 01:30") If (vremya_prihoda = "") Then WScript.Quit 'File selection dialog Set inputStream = selectFile (False) 'Run the transaction startTransaction ("VL32N") 'We're sorting through the lines until an empty Do While (Not inputStream.AtEndOfLine) 'Reading a line from a file postavka = inputStream.ReadLine () 'Insert the delivery number UserArea.findById ("ctxtLIKP-VBELN"). Text = delivery 'Press "Enter" pressEnter () 'Switch to the "Transportation" tab UserArea.findById ("tabsTAXI_TABSTRIP_OVERVIEW / tabpT \ 02"). Select () 'We paste the date UserArea.findById ("tabsTAXI_TABSTRIP_OVERVIEW / tabpT \ 02 / ssubSUBSCREEN_BODY: SAPMV50A: 1208 / ctxtLIKP-TDDAT"). Text = data_prihoda 'We put in time UserArea.findById ("tabsTAXI_TABSTRIP_OVERVIEW / tabpT \ 02 / ssubSUBSCREEN_BODY: SAPMV50A: 1208 / ctxtLIKP-TDUHR") Text = vremya_prihoda 'Press "Enter" once or more if there are problems with the date Do 'Press "Enter" pressEnter () Loop While (Len (Statusbar.text)> 0) 'Click' Save ' Wnd0.findById ("tbar [0] / btn [11]"). Press () Loop 'Click "Back" pressF3 () inputStream.Close () MsgBox "Done!", VbSystemModal Or vbInformation </ script> </ job>
Inbound delivery numbers must be in a text file in one column. The script requests the date and time, then it sorts through all the supplies, prescribes PlanirovTrans, saves the delivery. If a message appears in the status bar – the script presses Enter until the status line becomes empty.
Transfer of non-serial goods between warehouses (transaction MB1B)
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> ' Factory zavod = InputBox ("Enter factory code") If (zavod = "") Then WScript.Quit 'Warehouse-sender sklad_source = InputBox ("Enter the source code of the warehouse-sender") If (sklad_source = "") Then WScript.Quit 'Recipient's warehouse sklad_destination = InputBox ("Enter the code of the warehouse-recipient") If (sklad_destination = "") Then WScript.Quit 'File selection dialog Set inputStream = selectFile (False) 'Run the transaction startTransaction ("MB1B") 'We introduce the form of motion UserArea.findById ("ctxtRM07M-BWARTWA"). Text = "311" 'Introducing the plant UserArea.findById ("ctxtRM07M-WERKS"). Text = factory 'Enter the sending warehouse UserArea.findById ("ctxtRM07M-LGORT"). Text = stock_source 'Button "Enter" pressEnter () 'Enter the receiving warehouse UserArea.findById ("ctxtMSEGK-UMLGO"). Text = stock_destination 'Button "Enter" pressEnter () 'Define the number of rows in the table Set simpleContainer = UserArea.findById ("sub: SAPMM07M: 0421") RowCount = simpleContainer.LoopRowCount intRow = 2 'We read the lines from the file until we reach the end Do While (Not inputStream.AtEndOfLine) 'Reading a line from a file stroka = inputStream.ReadLine () 'Split the line by tabs arr = Split (stroka, vbTab) material = arr (0) kolvo = Replace (arr (1), "", "") 'Remove the spaces in the number SAP_pos = (intRow - 2) Mod RowCount UserArea.findById ("sub: SAPMM07M: 0421 / ctxtMSEG-MATNR [" & SAP_pos & ", 7]"). Text = material UserArea.findById ("sub: SAPMM07M: 0421 / txtMSEG-ERFMG [" & SAP_pos & ", 26]"). Text = amount 'Press the "New" button if the table is over If (SAP_pos = (RowCount - 1)) Then Wnd0.findById ("tbar [1] / btn [19]"). Press () intRow = intRow + 1 If (intRow> 1000) Then inputStream.Close () MsgBox "Completed 999 items!", VbSystemModal Or vbCritical WScript.Quit End If Loop 'Button "Enter" pressEnter () inputStream.Close () MsgBox "Done!", VbSystemModal Or vbInformation </ script> </ job>
The script at the beginning of the work requests the factory and warehouses, then reads the material and quantity (separated by tabulation) from the text file, enters them into the table, automatically scrolling it. For one launch of the script, you can transfer no more than 1000 items.
Transfer of serial goods between warehouses (transaction MB1B)
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> ' Factory zavod = InputBox ("Enter factory code") If (zavod = "") Then WScript.Quit 'Warehouse-sender sklad_source = InputBox ("Enter the source code of the warehouse-sender") If (sklad_source = "") Then WScript.Quit 'Recipient's warehouse sklad_destination = InputBox ("Enter the code of the warehouse-recipient") If (sklad_destination = "") Then WScript.Quit 'File selection dialog Set inputStream = selectFile (False) 'Run the transaction startTransaction ("MB1B") 'We introduce the form of motion UserArea.findById ("ctxtRM07M-BWARTWA"). Text = "311" 'Introducing the plant UserArea.findById ("ctxtRM07M-WERKS"). Text = factory 'Enter the sending warehouse UserArea.findById ("ctxtRM07M-LGORT"). Text = stock_source 'Button "Enter" pressEnter () 'Enter the receiving warehouse UserArea.findById ("ctxtMSEGK-UMLGO"). Text = stock_destination 'Button "Enter" pressEnter () 'Define the number of rows in the table Set simpleContainer = UserArea.findById ("sub: SAPMM07M: 0421") RowCount = simpleContainer.LoopRowCount intRow = 2 'We read the lines from the file until we reach the end Do While (Not inputStream.AtEndOfLine) 'Reading a line from a file stroka = inputStream.ReadLine () 'Split the line by tabs arr = Split (stroka, vbTab) material = arr (0) serial = arr (1) SAP_pos = (intRow - 2) Mod RowCount UserArea.findById ("sub: SAPMM07M: 0421 / ctxtMSEG-MATNR [" & SAP_pos & ", 7]"). Text = material UserArea.findById ("sub: SAPMM07M: 0421 / txtMSEG-ERFMG [" & SAP_pos & ", 26]"). Text = "1" 'Button "Enter" pressEnter () 'We insert the series session.findById ("wnd [1] / usr / tblSAPLIPW1TC_SERIAL_NUMBERS / ctxtRIPW0-SERNR [0,0]"). Text = serial 'OK' button session.findById ("wnd [1] / tbar [0] / btn [0]"). Press () 'Press the "New" button if the table is over If (SAP_pos = (RowCount - 1)) Then Wnd0.findById ("tbar [1] / btn [19]"). Press () intRow = intRow + 1 If (intRow> 1000) Then inputStream.Close () MsgBox "Completed 999 items!", VbSystemModal Or vbCritical WScript.Quit End If Loop 'Press "Enter" pressEnter () inputStream.Close () MsgBox "Done!", VbSystemModal Or vbInformation </ script> </ job>
The script works in the same way as the previous script, only in the file, there should be a serial instead of the number, and in the table section, the script itself sets the number 1 for each material.
Create an order (transaction ME51N)
<job> <script language = "VBScript" src = "SDK.vbs"> </ script> <script language = "VBScript"> factory = 8888 demanded = 12345 mvz = "7777666666" note = "Note to Application" 'List of products. If some product is not needed, you need to put 0 in the quantity itemsArray = Array (_ Array (111111, 50, "Paper A4"), _ Array (222222, 50, "Toilet paper"), _ Array (333333, 0, "Liquid soap"), _ Array (444444, 0, "Stamp ink"), _ Array (555555, 10, "Marker"), _ Array (666666, 0, "Staples for stapler"), _ ) 'Run the transaction startTransaction ("ME51N") 'We select the required type of bid - NB UserArea.findByName ("MEREQ_TOPLINE-BSART", "GuiComboBox"). Key = "NB" 'Expand the top container if it is deployed Set buttonTop = UserArea.findByName ("SUB1: SAPLMEVIEWS: 4000", "GuiSimpleContainer"). FindByName ("DYN_4000-BUTTON", "GuiButton") If (Right (buttonTop.Tooltip, 2) = "F2") Then buttonTop.Press () 'Fill in the header note guiTexteditId = UserArea.findByName ("TEXT_EDITOR_0101", "GuiCustomControl"). Id & "/ shellcont / shell" UserArea.findById (guiTexteditId) .Text = note pos = 0 For Each item In itemsArray If (item (1)> 0) Then 'We fill one line in the table fill_row pos, item (0), item (1), zavod, zatreboval 'Button "Enter" pressEnter () 'We write down the cost center UserArea.findByName ("COBL-KOSTL", "GuiCTextField"). Text = mvz 'Button "Enter" pressEnter () pos = pos + 1 End If Next MsgBox "Done!", VbSystemModal Or vbInformation </ script> </ job>
Previously, the script sets the quantities for materials that must be in the application. If 0 is specified, then such material is not added to the application. For each material in the application, the cost center is automatically assigned. The script is not designed to work with a large number of materials (they do not fit into the visible part of the table).
There are more and more complex scripts, where three transactions are used in one script, but their transactions are specific to the company.
That’s all.