我正在执行一项将Excel与SAP连接的任务。
我想使用SUIM transaction
,但问题是不同系统的视图不同。
例如:
在系统A 中 我有这个代码:
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "suim"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").expandNode "02 1 2"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").topNode = "01 1 1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").expandNode "03 2 7"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").selectItem "04 2 8", "1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").ensureVisibleHorizontalItem "04 2 8", "1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").topNode = "01 1 1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").clickLink "04 2 8", "1"
** START OF DIFFERENCE **
session.findById("wnd[0]/usr/tabsTABSTRIP_TAB/tabpTAB3").Select
session.findById("wnd[0]/usr/tabsTABSTRIP_TAB/tabpTAB3/ssub%_SUBSCREEN_TAB:RSUSR002:1003/btn%_ACTGRPS_%_APP_%-VALU_PUSH").press
** END OF DIFFERENCE **
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,0]").Text = "*********"
和系统B,
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "suim"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").expandNode "02 1 2"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").topNode = "01 1 1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").expandNode "03 2 7"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").selectItem "04 2 8", "1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").ensureVisibleHorizontalItem "04 2 8", "1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").topNode = "01 1 1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").clickLink "04 2 8", "1"
** START OF DIFFERENCE **
session.findById("wnd[0]/usr/btn%_ACTGRPS_%_APP_%-VALU_PUSH").press
** END OF DIFFERENCE **
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,0]").Text = "*******"
因此,如您所见,只有标记的行有差异。
如何获取公共代码,以便只使用一个代码在两个系统中运行,我该怎么做?
答案 0 :(得分:0)
试试这个
Private Sub MySAPSub(SystemType As String)
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "suim"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").expandNode "02 1 2"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").topNode = "01 1 1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").expandNode "03 2 7"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").selectItem "04 2 8", "1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").ensureVisibleHorizontalItem "04 2 8", "1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").topNode = "01 1 1"
session.findById("wnd[0]/usr/cntlTREE_CONTROL_CONTAINER/shellcont/shell").clickLink "04 2 8", "1"
If (SystemType = "ABC 100") Then
session.findById("wnd[0]/usr/tabsTABSTRIP_TAB/tabpTAB3").Select
session.findById("wnd[0]/usr/tabsTABSTRIP_TAB/tabpTAB3/ssub%_SUBSCREEN_TAB:RSUSR002:1003/btn%ACTGRPS%APP%-VALU_PUSH").press
ElseIf (SystemType = "ABC 200") Then
session.findById("wnd[0]/usr/btn%ACTGRPS%APP%-VALU_PUSH").press
End If
session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,0]").Text = "*******"
End Sub
Private Sub CallMySAPSub()
' Call System ABC 100
MySAPSub ("ABC 100")
' Call System ABC 200
MySAPSub ("ABC 200")
End Sub