📜 ⬆️ ⬇️

Automation of work in SAP using VBScript

For several years of working in SAP as a user, I have compiled a large number of different scripts to facilitate working in SAP, since SAP "out of the box" is quite inconvenient for fast and efficient work. It is particularly annoying that at one time it is impossible to insert more rows into the table than is displayed on the screen. It is necessary to insert parts, scrolling the table. On a low widescreen monitor, so generally terribly uncomfortable. Some time ago, before the creation of scripts, I set my monitor vertically and rotated the image in order to display more lines.


I decided to share my work with the public.

To achieve the development of the necessary things for work in the company is practically (and in fact) unrealistic. The company is large, bureaucracy, a lot of approvals, a pity for SAP programmers, a lot of intermediary departments, etc. Therefore, I slowly self-automated my (and not only my) work using VBScript. Running the "left" exe on the company's computers is prohibited by all sorts of policies, settings and third-party programs, but VBScript runs quietly.


The main method of scripting was to record actions into a macro using the means of SAP itself, with further analysis of the recorded data, studying help, searching for information on the Internet, etc. etc.


There are many examples of working with SAP on the Internet using VBScript, which is started 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 the session.findById code (“wnd [0]”). Maximize , which expands the SAP window. Working with such scripts “sharpened” under the first window is inconvenient for the following reasons:


  1. The SAP Logon window should be closed or minimized to tray. Otherwise, the script will try to work in it.
  2. In the first window, another transaction can be executed, or the results of the transaction will be displayed, or the transaction for entering parameters will be opened. In general, if something is open in the first window, except for the menu, launching a transaction through a script will not work.
  3. The first window can open a connection to another server.

An additional script was written to assist in this, which uploads the tree of the first SAP window to the XML file. It turns out like this:


image

Browsing SAP GUIs
Dim currentNode Set xmlParser = CreateObject("Msxml2.DOMDocument") '   XML 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" '   SAP session.findById("wnd[0]").maximize enumeration "wnd[0]" 'enumeration "wnd[0]/usr" MsgBox "!", vbSystemModal Or vbInformation Sub enumeration(SAPRootElementId) Set SAPRootElement = session.findById(SAPRootElementId) '   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) '   Set XMLSubNode = XMLRootNode.appendChild(xmlParser.createElement(SAPChildElement.Type)) '  Name Set attrName = xmlParser.createAttribute("Name") attrName.Value = SAPChildElement.Name XMLSubNode.setAttributeNode(attrName) '  Text If (Len(SAPChildElement.Text) > 0) Then Set attrText = xmlParser.createAttribute("Text") attrText.Value = SAPChildElement.Text XMLSubNode.setAttributeNode(attrText) End If '  Id Set attrId = xmlParser.createAttribute("Id") attrId.Value = SAPChildElement.Id XMLSubNode.setAttributeNode(attrId) '    - ,     If (SAPChildElement.ContainerType) Then enumChildrens SAPChildElement, XMLSubNode Next End Sub 


Commenting on one of the lines:


we get the results of traversing elements of either the entire SAP window, or only the UserArea (without the menu, toolbar, status bar).
')

A few nuances:


  1. If an element is not visible on the screen, then it does not exist, and it cannot be found either by name or by ID. To get to it, you need to deploy and make visible all the upstream elements. For example:
    • In the ME51N transaction, it is not possible to specify a “header note” if the header is collapsed. You must first expand the title.
    • In the transaction ME21N, to get to the field "Our sign" - you need not only to expand the title, but also switch to the "Communication" tab.
  2. When updating the screen, almost all GUI objects are recreated, and they need to be re-searched by name or ID. When accessing objects created in the script before the screen is updated, an error will occur.
  3. All VBScript commands that interact with SAP GUI elements are executed synchronously, i.e. VBScript code execution does not go further until SAP runs the command. It is very convenient, you do not need to insert pauses and / or cycles everywhere, checking for changes on the screen or waiting for the appearance of a window with a message.
  4. While the script is running and interacting with one window (mode) of SAP, you can safely work in other SAP modes as well as in Windows itself or other applications.

My scripts run directly from SAP. For this, an object of the type “Web address or file” is created in SAP with the full path to the script file.


image

For scripts, I use WSF (Windows Script File) files, which consist of two parts:


  1. A generic file called SDK.vbs, containing the code used in each script, plus several functions and procedures that are not used in all scripts.
  2. Actually, VBScript itself, which performs my tasks. VBScript executes commands exactly in the SAP window from which it is launched.

WSF file structure
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> …   … </script> </job> 


Those. A WSF can consist of several scripts (in different programming languages), either scattered on separate files, or written in the WSF itself. When you run WSF, the code from the SDK.vbs file is first executed, and then the script code itself. Since WSF runs directly from SAP - then it is guaranteed to run in the very window from which it is launched. The active session is defined by the Set session = application.ActiveSession () command.


SDK.vbs consists of a connection code to SAP and the definition of an active session, and several supporting procedures and functions.


Further, in the script, for convenience, several objects and variables are defined:



Additional procedures and functions:


  1. Start transaction.
  2. Emulation of pressing the buttons Enter, F3, F5, F8.
  3. Dialog of opening a csv or txt file with the ability to create a file for writing. The file for recording is created in the same folder and has the same name, but “out” is added before the extension. Files for reading should not be UTF-8 encoded with BOM, since when reading the first line, three bytes are additionally read at the beginning of the file (#EFBBBF), which cause an error when inserting the read line into any SAP field.
  4. Filling one row in the table (for transaction ME51N).
  5. Work with clipboard.

Sdk.vbs
 '   WScript.Shell Set WshShell = WScript.CreateObject("WScript.Shell") ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '   SAP ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '   Set SapGuiAuto = GetObject("SAPGUI") '    GuiApplication (COM-) Set application = SapGuiAuto.GetScriptingEngine() '    GuiSession -  ,     SAP ' ..   WSF         SAP,    Set session = application.ActiveSession() WScript.ConnectObject session, "on" WScript.ConnectObject application, "on" '    GuiMainWindow Set Wnd0 = session.findById("wnd[0]") '    GuiMenubar Set Menubar = Wnd0.findById("mbar") '    GuiUserArea Set UserArea = Wnd0.findById("usr") '    GuiStatusbar Set Statusbar = Wnd0.findById("sbar") '    UserName = session.Info.User ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '     ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '   Sub startTransaction(transaction_name) session.StartTransaction transaction_name End Sub '   "Enter" Sub pressEnter() Wnd0.sendVKey 0 End Sub '   F2 Sub pressF2() Wnd0.sendVKey 2 End Sub '   F3 Sub pressF3() Wnd0.sendVKey 3 End Sub '   F5 Sub pressF5() Wnd0.sendVKey 5 End Sub '   F8 Sub pressF8() Wnd0.sendVKey 8 End Sub '   ,          Function selectFile(createOuputFile) Set objDialog = CreateObject("UserAccounts.CommonDialog") '      With objDialog .InitialDir = WshShell.SpecialFolders("Desktop") '   -   .Filter = "  (*.csv;*.txt)|*.csv;*.txt" result = .ShowOpen End With '     -  If (result = 0) Then WScript.Quit inputFile = objDialog.FileName '      Set fso = CreateObject("Scripting.FileSystemObject") Set inputStream = fso.OpenTextFile(inputFile) '   ? If (createOuputFile) Then outputFile = Left(inputFile, Len(inputFile) - 3) & "out" & Right(inputFile, 4) Set outputStream = fso.CreateTextFile(outputFile, True) '             selectFile = Array(inputStream, outputStream) Else '      Set selectFile = inputStream End If End Function '      ( 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" '   grid.modifyCell row, "MATNR", material '  grid.modifyCell row, "MENGE", kolvo '  grid.modifyCell row, "NAME1", zavod '  grid.modifyCell row, "LGOBE", "0001" '  grid.modifyCell row, "AFNAM", zatreboval '  End Sub ' Set, get and clear ClipBoard text in VBScript ' CLEAR - QuickClip("") ' SET - QuickClip("Hello World!") ' GET - Result = QuickClip(Null) Function QuickClip(input) '@description: A quick way to set and get your clipboard. '@author: Jeremy England (SimplyCoded) If IsNull(input) Then QuickClip = CreateObject("HTMLFile").parentWindow.clipboardData.getData("Text") If IsNull(QuickClip) Then QuickClip = "" Else CreateObject("WScript.Shell").Run "mshta.exe javascript:eval(""document.parentWindow.clipboardData.setData('text','" & Replace(Replace(input, "'", "\\u0027"), """", "\\u0022") & "');window.close()"")", 0, True End If End Function 


Below are examples of scripts with comments and a small description.


Starting an IQ09 transaction, pasting serial numbers from the clipboard, performing a transaction.
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> '   startTransaction("IQ09") '  " "  UserArea.findById("btn%_SERNR_%_APP_%-VALU_PUSH").Press() '  "  " session.findById("wnd[1]/tbar[0]/btn[24]").Press() '  "" (F8) pressF8() '  "" (F8) pressF8() </script> </job> 


Those. Immediately before running the script, you need to copy into the clipboard a column from serial numbers, 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"> '        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) '   startTransaction("MB51") ' /   UserArea.findById("ctxtMATNR-LOW").Text = "100000" '  UserArea.findById("ctxtWERKS-LOW").Text = "9999" '  UserArea.findById("ctxtLGORT-LOW").Text = "0001" '  UserArea.findById("ctxtBWART-LOW").Text = "101" '   UserArea.findById("ctxtBUDAT-LOW").Text = date_begin '   -   UserArea.findById("ctxtBUDAT-HIGH").Text = date_end '   -   UserArea.findById("ctxtLIFNR-LOW").Text = "" UserArea.findById("ctxtBUKRS-LOW").Text = "" UserArea.findById("ctxtEBELN-LOW").Text = "" '    UserArea.findById("txtMAT_KDPO-LOW").Text = "" ' .   UserArea.findById("txtZEILE-LOW").Text = "" ' . .  UserArea.findById("txtMBLNR-LOW").Text = "" '   UserArea.findById("txtMJAHR-LOW").Text = "" '  pressF8() '  " " Wnd0.findById("tbar[1]/btn[48]").Press() '  "  ->   -> ..." Menubar.findById("menu[3]/menu[2]/menu[1]").Select() '   "X " session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cmbG51_USPEC_LBOX").Key = "X" '   3-   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. Additionally, some input fields are cleared, which can be filled after the previous transaction start. The table uses a previously created format (specific to the user), which should be the third in the list. The sequence number of the format is easy to fix in the code.


Last month outbound deliveries (transaction VL06O).
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> '        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) '   startTransaction("VL06O") '  "  - . " UserArea.findById("btnBUTTON6").Press() '  " ..." Wnd0.findById("tbar[1]/btn[17]").Press() '    session.findById("wnd[1]/usr/txtV-LOW").Text = "MY_FORMAT" '  "" (F8) pressF8() '   UserArea.findById("ctxtIT_WTIST-LOW").Text = date_begin UserArea.findById("ctxtIT_WTIST-HIGH").Text = date_end '  "" (F8) pressF8() '  " ..." Wnd0.findById("tbar[1]/btn[33]").Press() '   "X " session.findById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cmbG51_USPEC_LBOX").Key = "X" '   3-  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 rest of the transaction start parameters are stored in the pre-created MY_FORMAT_2 format. The table also uses a previously created format (specific to the user), which should be the third in the list.


Removing moving average prices (transaction MM43).
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> zavod = InputBox("  ") If (zavod = "") Then WScript.Quit '    streams = selectFile(True) Set inputStream = streams(0) Set outputStream = streams(1) '   startTransaction("MM43") '    ,     Do While (Not inputStream.AtEndOfLine) '   UserArea.findById("ctxtRMMW1-VZWRK").Text = zavod '     material = inputStream.ReadLine() '   UserArea.findById("ctxtRMMW1-MATNR").Text = material '  "Enter" pressEnter() '  ": " UserArea.findById("tabsTABSPR1/tabpSP05").Select() '  "" UserArea.findById("tabsTABSPR1/tabpSP05/ssubTABFRA1:SAPLMGMW:2004/subSUB9:SAPLMGD2:2480/btnMBEW_PUSH").Press() '   price = UserArea.findById("subSUB3:SAPLMGD2:2802/txtMBEW-VERPR").Text '     price = Replace(price, ".", "") '  "" (F3) pressF3() '  "" (F3) pressF3() '       outputStream.WriteLine(material & vbTab & price) Loop '  "" (F3) pressF3() inputStream.Close() outputStream.Close() MsgBox "!", vbSystemModal Or vbInformation </script> </job> 


The materials for which you need to get the average prices are in a text file and arranged in a column. The script starts the transaction MM43, then switches to the tabs, presses the button to get to the desired field. The resulting price is written to the new file along with the material (via tabulation).


List of shipments with dates of completion of loading (transaction VT16).
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> '      curr_date = Date() curr_month = Month(curr_date) curr_year = Year(curr_date) date_begin = DateSerial(curr_year, curr_month, 1) '   startTransaction("VT16") '  "Enter" pressEnter() '  "" UserArea.findById("ctxtK_DALEN-LOW").Text = date_begin UserArea.findById("ctxtK_DALEN-HIGH").Text = "31.12.9999" '   UserArea.findById("ctxtK_SHTYP-LOW").Text = "0001" '    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() '  "" (F8) pressF8() '   "  ->   -> ..." Menubar.findById("menu[3]/menu[0]/menu[1]").Select() '      session.findById("wnd[1]/usr/lbl[1,3]").setFocus() '  "Enter" pressEnter() </script> </job> 


Transportation is selected from the interval - from the first day of the current month to 12/31/9999. The date of the first day of the current month is determined at the beginning of the script. Specified shipping points. For the generated report, the first format in the list is selected.


The following three scripts are intended for posting the shipped deliveries with a date equal to the end date of loading.


Shipped but not posted outbound deliveries (transaction VL06O).
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> '   startTransaction("VL06O") '  "  - . " UserArea.findById("btnBUTTON6").Press() '  " ..." Wnd0.findById("tbar[1]/btn[17]").Press() '    session.findById("wnd[1]/usr/txtV-LOW").Text = "MY_FORMAT_2" '   "" session.findById("wnd[1]/usr/txtENAME-LOW").Text = "" '  "" pressF8() '  "" pressF8() </script> </job> 


The table uses a previously created format.


Starting a VT16 transaction, inserting delivery numbers from the clipboard, executing a transaction.
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> '   startTransaction("VT16") '    session.findById("wnd[1]/tbar[0]/btn[0]").Press() '  " "   UserArea.findById("btn%_S_VBELN_%_APP_%-VALU_PUSH").Press() '  "  " session.findById("wnd[1]/tbar[0]/btn[24]").Press() '  "" (F8) pressF8() '  "" (F8) pressF8() '   "  ->   -> ..." Menubar.findById("menu[3]/menu[0]/menu[1]").Select() '      session.findById("wnd[1]/usr/lbl[1,3]").setFocus() '  "Enter" pressEnter() </script> </job> 


Similarly, the column of delivery numbers must first be copied to the clipboard.


Shipped, but not posted, outbound shipments from the clipboard (transaction VL06O).
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> '   startTransaction("VL06O") '  " " UserArea.findById("btnBUTTON4").Press() '      " " UserArea.findById("ctxtIT_WADAT-LOW").Text = "" UserArea.findById("ctxtIT_WADAT-HIGH").Text = "" '  " "  UserArea.findById("btn%_IT_TKNUM_%_APP_%-VALU_PUSH").Press() '  "  " session.findById("wnd[1]/tbar[0]/btn[24]").Press() '  "" (F8) pressF8() '  "" (F8) pressF8() '    " " -     If (Wnd0.findById("tbar[1]/btn[18]").Text = " ") Then '   UserArea.findById("cntlGRID1/shellcont/shell").selectAll '  "  ->    " Menubar.findById("menu[4]/menu[7]").Select() '        ( )        WshShell.SendKeys "{HOME}{DELETE}{DELETE}" Else MsgBox " !", vbSystemModal Or vbExclamation '  "" (F3) pressF3() '  "" (F3) pressF3() End If </script> </job> 


The column with transportation numbers must first be copied to the clipboard from the results of operation VT16 (the previous script). After completion of the transaction:


  1. If there are no deliveries in the report, a corresponding message is displayed, then the script ends.
  2. If there are deliveries in the report - select the menu item “Post goods issue”, in the appeared window with the posting date, the first two characters (ie, day) are erased. Next, the script quits, 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. Pre-enable error handling script.


While writing an article, I decided to combine the first two scripts for posting the shipped supplies into one.


List of shipments to shipped, but not carried out, outgoing deliveries.
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> '############################################################## '    startTransaction("VL06O") '  "  - . " UserArea.findById("btnBUTTON6").Press() '  " ..." Wnd0.findById("tbar[1]/btn[17]").Press() '    session.findById("wnd[1]/usr/txtV-LOW").Text = "MY_FORMAT_3" '   "" session.findById("wnd[1]/usr/txtENAME-LOW").Text = "" '  "" pressF8() '  "" pressF8() Set grid = UserArea.findById("cntlGRID1/shellcont/shell") ' GuiGridView rowCount = grid.RowCount '    visibleRowCount = grid.VisibleRowCount '    '    ,     firstVisibleRow = visibleRowCount Do While (firstVisibleRow < rowCount) grid.firstVisibleRow = firstVisibleRow firstVisibleRow = firstVisibleRow + visibleRowCount Loop '     grid.SelectColumn("VBELN") '          grid.ContextMenu() grid.SelectContextMenuItemByText " " '    SAP pressF3() pressF3() pressF3() '############################################################## '    startTransaction("VT16") '    session.findById("wnd[1]/tbar[0]/btn[0]").Press() '  " "   UserArea.findById("btn%_S_VBELN_%_APP_%-VALU_PUSH").Press() '  "  " session.findById("wnd[1]/tbar[0]/btn[24]").Press() '  "" (F8) pressF8() '  "" (F8) pressF8() '   "  ->   -> ..." Menubar.findById("menu[3]/menu[0]/menu[1]").Select() '      (  "Lexa_1") session.findById("wnd[1]/usr/lbl[1,3]").setFocus() '  "Enter" pressEnter() </script> </job> 


The script uses the copy of the column with delivery numbers from transaction VL06O with a preliminary scrolling of the table to the end (so that all deliveries are copied).


Mass registration of the date and time of "PlantovTrans" in incoming deliveries (transaction VL32N).
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> data_prihoda = InputBox("   : 010213, 01022013, 01.02.13, 01.02.2013") If (data_prihoda = "") Then WScript.Quit vremya_prihoda = InputBox("   : 0130, 01:30") If (vremya_prihoda = "") Then WScript.Quit '    Set inputStream = selectFile(False) '   startTransaction("VL32N") '  ,     Do While (Not inputStream.AtEndOfLine) '     postavka = inputStream.ReadLine() '    UserArea.findById("ctxtLIKP-VBELN").Text = postavka '  "Enter" pressEnter() '    "" UserArea.findById("tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02").Select() '   UserArea.findById("tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV50A:1208/ctxtLIKP-TDDAT").Text = data_prihoda '   UserArea.findById("tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV50A:1208/ctxtLIKP-TDUHR").Text = vremya_prihoda '  "Enter"    ,     Do '  "Enter" pressEnter() Loop While (Len(Statusbar.text) > 0) '  "" Wnd0.findById("tbar[0]/btn[11]").Press() Loop '  "" pressF3() inputStream.Close() MsgBox "!", vbSystemModal Or vbInformation </script> </job> 


Inbound delivery numbers must be in a single-column text file. , , «», . - – Enter , .


( MB1B).
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> '  zavod = InputBox("  ") If (zavod = "") Then WScript.Quit ' - sklad_source = InputBox("  -") If (sklad_source = "") Then WScript.Quit ' - sklad_destination = InputBox("  -") If (sklad_destination = "") Then WScript.Quit '    Set inputStream = selectFile(False) '   startTransaction("MB1B") '    UserArea.findById("ctxtRM07M-BWARTWA").Text = "311" '   UserArea.findById("ctxtRM07M-WERKS").Text = zavod '  - UserArea.findById("ctxtRM07M-LGORT").Text = sklad_source '  "Enter" pressEnter() '  - UserArea.findById("ctxtMSEGK-UMLGO").Text = sklad_destination '  "Enter" pressEnter() '      Set simpleContainer = UserArea.findById("sub:SAPMM07M:0421") RowCount = simpleContainer.LoopRowCount intRow = 2 '    ,     Do While (Not inputStream.AtEndOfLine) '     stroka = inputStream.ReadLine() '      arr = Split(stroka, vbTab) material = arr(0) kolvo = Replace(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 = kolvo '   "",    If (SAP_pos = (RowCount - 1)) Then Wnd0.findById("tbar[1]/btn[19]").Press() intRow = intRow + 1 If (intRow > 1000) Then inputStream.Close() MsgBox " 999 !", vbSystemModal Or vbCritical WScript.Quit End If Loop '  "Enter" pressEnter() inputStream.Close() MsgBox "!", vbSystemModal Or vbInformation </script> </job> 


, ( ), , . 1000 .


( MB1B).
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> '  zavod = InputBox("  ") If (zavod = "") Then WScript.Quit ' - sklad_source = InputBox("  -") If (sklad_source = "") Then WScript.Quit ' - sklad_destination = InputBox("  -") If (sklad_destination = "") Then WScript.Quit '    Set inputStream = selectFile(False) '   startTransaction("MB1B") '    UserArea.findById("ctxtRM07M-BWARTWA").Text = "311" '   UserArea.findById("ctxtRM07M-WERKS").Text = zavod '  - UserArea.findById("ctxtRM07M-LGORT").Text = sklad_source '  "Enter" pressEnter() '  - UserArea.findById("ctxtMSEGK-UMLGO").Text = sklad_destination '  "Enter" pressEnter() '      Set simpleContainer = UserArea.findById("sub:SAPMM07M:0421") RowCount = simpleContainer.LoopRowCount intRow = 2 '    ,     Do While (Not inputStream.AtEndOfLine) '     stroka = inputStream.ReadLine() '      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" '  "Enter" pressEnter() '   session.findById("wnd[1]/usr/tblSAPLIPW1TC_SERIAL_NUMBERS/ctxtRIPW0-SERNR[0,0]").Text = serial '  "" session.findById("wnd[1]/tbar[0]/btn[0]").Press() '   "",    If (SAP_pos = (RowCount - 1)) Then Wnd0.findById("tbar[1]/btn[19]").Press() intRow = intRow + 1 If (intRow > 1000) Then inputStream.Close() MsgBox " 999 !", vbSystemModal Or vbCritical WScript.Quit End If Loop '  "Enter" pressEnter() inputStream.Close() MsgBox "!", vbSystemModal Or vbInformation </script> </job> 


, , 1.


( ME51N).
 <job> <script language="VBScript" src="SDK.vbs"></script> <script language="VBScript"> zavod = 8888 zatreboval = 12345 mvz = "7777666666" note = "  " '  .  -   ,   0   itemsArray = Array( _ Array(111111, 50, " 4"), _ Array(222222, 50, " "), _ Array(333333, 0, " "), _ Array(444444, 0, " "), _ Array(555555, 10, ""), _ Array(666666, 0, "  "), _ ) '   startTransaction("ME51N") '     - NB UserArea.findByName("MEREQ_TOPLINE-BSART", "GuiComboBox").Key = "NB" '   ,    Set buttonTop = UserArea.findByName("SUB1:SAPLMEVIEWS:4000", "GuiSimpleContainer").findByName("DYN_4000-BUTTON", "GuiButton") If (Right(buttonTop.Tooltip, 2) = "F2") Then buttonTop.Press() '    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 '      fill_row pos, item(0), item(1), zavod, zatreboval '  "Enter" pressEnter() '   UserArea.findByName("COBL-KOSTL", "GuiCTextField").Text = mvz '  "Enter" pressEnter() pos = pos + 1 End If Next MsgBox "!", vbSystemModal Or vbInformation </script> </job> 


, . 0, . . ( ).


, , .


...

Source: https://habr.com/ru/post/341576/


All Articles