Need to create PO order in SAP.
The data coming from excel row by row need to create PO using SAP GUI scripting.
Had recorded the code also stuck at passing dynamic variable it is not working as expected.
Help would be highly appreciated as soon as possible.
You can achieve this using SAP GUI scripting with VBScript and Excel automation. Here’s a basic structure that reads each row from Excel and creates a PO in SAP dynamically:
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = False
Set objWorkbook = objExcel.Workbooks.Open(“C:\YourPath\PO_Data.xlsx”)
Set objSheet = objWorkbook.Sheets(1)
row = 2
Do While objSheet.Cells(row, 1).Value <> “”
mat = objSheet.Cells(row, 1).Value
qty = objSheet.Cells(row, 2).Value
vendor = objSheet.Cells(row, 3).Value
Connect to SAP
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApp = SapGuiAuto.GetScriptingEngine
Set SAPCon = SAPApp.Children(0)
Set session = SAPCon.Children(0)
session.StartTransaction "ME21N"
WScript.Sleep 2000
Header data
session.findById("wnd[0]/usr/ctxtRM06E-BSART").Text = "NB"
session.findById("wnd[0]/usr/ctxtEKKO-LIFNR").Text = vendor
Item data
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0014/subSUB1:SAPLMEGUI:1201/tblSAPLMEGUITC_1201/ctxtMEPO1211-MATNR[1,0]").Text = mat
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0014/subSUB1:SAPLMEGUI:1201/tblSAPLMEGUITC_1201/txtMEPO1211-MENGE[3,0]").Text = qty
Save the PO
session.findById("wnd[0]/tbar[0]/btn[11]").Press
row = row + 1
Loop
objWorkbook.Close False
objExcel.Quit
Set objExcel = Nothing
I assume your script is in text/string format stored somewhere. If yes, just place a placeholder in that string and just before try to run that script, replace that placeholder with the dynamic variable.
For example
Your script should be like this session.findById("wnd[0]/usr/ctxtXYZ").Text = "#Placeholder#"
Now use assign activity to replace the placeholder with variable like this