Skip to Content
0
Former Member
Jul 08, 2014 at 04:47 PM

How to move more than two columns data from excel to SAP

49 Views

Hi experts,

I am totally new in this SAP scripting area. I want to write a script can move from excel to SAP.

I record below script as a background job, with different WBS which is the in the column 2 in the excel. I also want to change the date and time( in column 3&4) when i schedule the report. But I dong know how to change it.

Set objExcel = CreateObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Open _

("D:\userdata\jiayi\Desktop\Other works\SAP\Script file\Sche RA.xlsx")

Introw = 2

Do Until Introw = 4

IF objExcel.Cells(Introw, 2)= "original" then

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

Else

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]/usr/ctxtP_POSID").text = objExcel.Cells(Introw, 2).Value

session.findById("wnd[0]/usr/ctxtP_DATUM").text = "01.08.2014"

session.findById("wnd[0]/usr/ctxtP_DATUM").setFocus

session.findById("wnd[0]/usr/ctxtP_DATUM").caretPosition = 10

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

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

session.findById("wnd[1]/usr/ctxtPRI_PARAMS-PDEST").text = "dumm"

session.findById("wnd[1]/usr/ctxtPRI_PARAMS-PDEST").caretPosition = 4

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

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

session.findById("wnd[2]/usr/tabsTABSTRIP/tabpTAB2/ssubSUBSCREEN:SAPLSPRI:0500/cntlCUSTOM/shellcont/shell").selectItem "PAART","Column2"

session.findById("wnd[2]/usr/tabsTABSTRIP/tabpTAB2/ssubSUBSCREEN:SAPLSPRI:0500/cntlCUSTOM/shellcont/shell").ensureVisibleHorizontalItem "PAART","Column2"

session.findById("wnd[2]/usr/tabsTABSTRIP/tabpTAB2/ssubSUBSCREEN:SAPLSPRI:0500/cntlCUSTOM/shellcont/shell").doubleClickItem "PAART","Column2"

session.findById("wnd[2]/usr/tabsTABSTRIP/tabpTAB2/ssubSUBSCREEN:SAPLSPRI:0500/ssubSUBSCREEN:SAPLSPRI:0600/ctxtPRI_PARAMS-PAART").text = "Z_LONG_ROW"

session.findById("wnd[2]/usr/tabsTABSTRIP/tabpTAB2/ssubSUBSCREEN:SAPLSPRI:0500/ssubSUBSCREEN:SAPLSPRI:0600/ctxtPRI_PARAMS-PAART").setFocus

session.findById("wnd[2]/usr/tabsTABSTRIP/tabpTAB2/ssubSUBSCREEN:SAPLSPRI:0500/ssubSUBSCREEN:SAPLSPRI:0600/ctxtPRI_PARAMS-PAART").caretPosition = 10

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

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

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

session.findById("wnd[1]/usr/btnDATE_PUSH").press

session.findById("wnd[1]/usr/ctxtBTCH1010-SDLSTRTDT").text = "06.07.2014"

session.findById("wnd[1]/usr/ctxtBTCH1010-SDLSTRTTM").text = "22:00:00"

session.findById("wnd[1]/usr/ctxtBTCH1010-SDLSTRTTM").setFocus

session.findById("wnd[1]/usr/ctxtBTCH1010-SDLSTRTTM").caretPosition = 8

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

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

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

end if

intRow = intRow + 1

Loop

objExcel.Quit