Skip to Content
0
Former Member
Oct 12, 2013 at 06:18 PM

VA02 Sales Order Automation?

912 Views

Hello All,

I am very new to this vbs.. so need you guidance and support to solve my query. I am trying to automate Sales order line items details updation and i have recorded the below script and than modified a bit e.g. added excel codes which take the values from the excel. Here is the overview of the script, First goes to transaction VA02 and then take the sales order number from the excel sheet and enter the sales order and go to Item Overview tab and updates the first line description and than page down button is pressed to go to the last empty line where details are update like Material code, Qty. Descrption, WBSe element, etc these are updated from excel sheet and then the required details are taken from the excel sheet and updated in the sales order and SO is then saved.

The script runs fine, but only when i update the SO which was used for recording, but if the SO is changed it gives me error due to the Line selected for updation of material, Description, Qty and WBSe... If you check below the item overview ROW is 6 for the recorded SO which is hard coded, so how this can be solved of removing the hard code coding to a variable one which depends on the SO row number.

MABNR[1,6]"

KWMENG[3,6]")

UEPOS[2,6]")

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

Set xclapp = CreateObject("Excel.Application")

Set xclapp = CreateObject("Excel.Application")

Set xclwbk = xclapp.Workbooks.Open("c:\va02.xlsx")

set xclsht = xclwbk.Sheets("Sheet1")

For i = 2 to 8

While (not xclsht.Cells(i, 1).Value = "")

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

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

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

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

session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = xclsht.Cells(i,1).Value

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

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02").select

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,0]").text = xclsht.Cells(i,2).Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,0]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,0]").caretPosition = 0

session.findById("wnd[0]/tbar[0]/btn[83]").press

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,6]").text = "XXXXXX"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[3,6]").text = "1"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-VRKME[4,6]").text = "EA"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,6]").text = xclsht.Cells(i,3).Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-PSTYV[7,6]").text = "ZP13"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-UEPOS[2,6]").text = "20"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-WERKS[8,6]").text = "85MP"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-PS_PSP_PNR[9,6]").text = xclsht.Cells(i,4).Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,6]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,6]").caretPosition = 10

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,6]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtVBAP-ARKTX[6,6]").caretPosition = 12

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07").select

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN").verticalScrollbar.position = 11

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/ctxtKOMV-KSCHL[1,9]").text = "zpvp"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,9]").text = xclsht.Cells(i,5).Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,9]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\07/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,9]").caretPosition = 16

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\06").select

session.findById("wnd[1]").close

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-AFDAT[0,0]").text = xclsht.Cells(i,6).Value

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAREG[9,0]").text = "3"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAREG[9,0]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAREG[9,0]").caretPosition = 1

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAKSP[7,0]").text = ""

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAKSP[7,0]").setFocus

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4203/tblSAPLV60FTCTRL_FPLAN_TEILFA/ctxtFPLT-FAKSP[7,0]").caretPosition = 0

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

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\16").select

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\16/ssubSUBSCREEN_BODY:SAPMV45A:4462/subKUNDEN-SUBSCREEN_8459:SAPMV45A:8459/ctxtVBAP-ZZSMC").text = "o"

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\16/ssubSUBSCREEN_BODY:SAPMV45A:4462/subKUNDEN-SUBSCREEN_8459:SAPMV45A:8459/ctxtVBAP-ZZSMC").caretPosition = 1

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

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

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

session.findById("wnd[0]/tbar[0]/btn[3]").press

i = i + 1

Wend

Next

xclwbk.save

msgbox "Document Saved"

Set xclwbk = Nothing

Set xclsht = Nothing

xclapp.Quit

set xclapp = Nothing

Thanks for all your help in advance.

Sushil