on 10-19-2012 9:24 AM
Hi,
I am new in scripting.
I need to automate some actions using vbs, For example I want to add some materials using CN22.
The problem is that there are different number of materials already existing in the different NTWs and I need the new material to be inserted in the first empty line.
Please help me if you know any way to solve this using vbs.
'For example: In this case there is one material existing already and empty line used for new material is [1]
'but how to choose line [2 or other] if different number of materials already exist?
session.findById("wnd[0]/usr/tabsTABSTRIP_2700/tabpALLE/ssubSUBSCR_2000:SAPLCOMK:2701/tblSAPLCOMKTCTRL_2701/ctxtRESBD-MATNR[1,1]").text = "Material"
Thank you!
Guero
Hi again,
Let me reformulate the question.
How should it look like script which checks field by field in SAP if it is already filled and if it is not to fill required information which is stored in Excel file?
I suppose it should be something like bellow.
Please help to find the solution.
x=0
Do Until session.findById("wnd[0]/usr/tabsTABSTRIP_2700/tabpALLE/ssubSUBSCR_2000:SAPLCOMK:2701/tblSAPLCOMKTCTRL_2701/ctxtRESBD-MATNR[1,x]").text = " "
x=x+1
Loop
session.findById("wnd[0]/usr/tabsTABSTRIP_2700/tabpALLE/ssubSUBSCR_2000:SAPLCOMK:2701/tblSAPLCOMKTCTRL_2701/ctxtRESBD-MATNR[1,x]").text = sht.cells(i,2).Value
Thank you !
Guero
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Guero,
you can try the following:
x=0
Do Until session.findById("wnd[0]/usr/tabsTABSTRIP_2700/tabpALLE/ssubSUBSCR_2000:SAPLCOMK:2701/tblSAPLCOMKTCTRL_2701/ctxtRESBD-MATNR[1," & cstr(x) & "]").text = ""
x=x+1
Loop
session.findById("wnd[0]/usr/tabsTABSTRIP_2700/tabpALLE/ssubSUBSCR_2000:SAPLCOMK:2701/tblSAPLCOMKTCTRL_2701/ctxtRESBD-MATNR[1," & cstr(x) & "]").text = sht.cells(i,2).Value
Regards,
ScriptMan
Hi again,
I tried to use the same construction in ME21N. The script should insert purchase requisition (PR) and PR item but it only insert it once (x=0) and occurred error message
“The control could not be found by id”. The line for which the message is refered is “Do until..” .
Please let me know what is wrong with the script.
For i= 11 to 14
x=0
Do until session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13," & cstr(x) & "]").text = ""
x=x+1
Loop
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13," & cstr(x) & "]").text = sht.cells(i,15).Value 'Purchase requisition
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-BNFPO[14," & cstr(x) & "]").text = sht.cells(i,16).Value 'Requisition item
Next
BR
Guero
Hi ScriptMan,
Here bellow is the scipt for two sequent PRs inserted in ME21N.
Again for me everything seemed correct.
Probably the fields are specific format or else and their values could not be checked with Do loop
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/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00031"
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB0:SAPLMEGUI:0030/subSUB1:SAPLMEGUI:1105/ctxtMEPO_TOPLINE-SUPERFIELD").text = "Vendor"
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13,0]").text = "Purchase requisition"
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-BNFPO[14,0]").text = "PR item 1"
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13,0]").setFocus
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13,0]").caretPosition = 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13,1]").text = "Purchase requisition"
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-BNFPO[14,1]").text = "PR item 2"
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13,1]").setFocus
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13,1]").caretPosition = 0
session.findById("wnd[0]").sendVKey 0
Regards
Guero
Hi Guero,
you can try the following:
For i= 11 to 14
x=0
Do until session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13," & cstr(x) & "]").text = ""
x=x+1
Loop
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13," & cstr(x) & "]").text = sht.cells(i,15).Value 'Purchase requisition
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-BNFPO[14," & cstr(x) & "]").text = sht.cells(i,16).Value 'Requisition item
session.findById("wnd[0]").sendVKey 0
Next
Regards,
ScriptMan
Hi ScriptMan,
It's me again.
I've pasted the code you suggested but again the same error occurred:
The control could not be found by id
This error is related to
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13," & cstr(x) & "]").text = ""
and occurred when the second PR should be inserted (i=12).
Please help me to solve it.
Regards,
Guero
Hi Guero,
You can try the following:
For i= 11 to 14
x= i -11
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13," & cstr(x) & "]").text = sht.cells(i,15).Value 'Purchase requisition
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-BNFPO[14," & cstr(x) & "]").text = sht.cells(i,16).Value 'Requisition item
session.findById("wnd[0]").sendVKey 0
Next
Regards,
ScriptMan
Hi,
Thank you Script Man.
It stops again on the second PR.
The error is the same-The control could not be found by id. and this time it is related to:
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13," & cstr(x) & "]").text = sht.cells(i,1).Value 'Purchase requisition
Bellow is the code between for..next:
For i= 28 to 29
x=i-28
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13," & cstr(x) & "]").text = sht.cells(i,1).Value 'Purchase requisition
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-BNFPO[14," & cstr(x) & "]").text = sht.cells(i,2).Value 'Requisition item
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT14/ssubTABSTRIPCONTROL1SUB:SAPLMEGUI:1329/subTEXTS:SAPLMMTE:0200/cntlTEXT_TYPES_0200/shell").selectedNode = "F02"
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT14/ssubTABSTRIPCONTROL1SUB:SAPLMEGUI:1329/subTEXTS:SAPLMMTE:0200/subEDITOR:SAPLMMTE:0201/cntlTEXT_EDITOR_0201/shellcont/shell").text = sht.cells(i,15).Value + vbCr + "" + vbCr + "" 'Item text
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT14/ssubTABSTRIPCONTROL1SUB:SAPLMEGUI:1329/subTEXTS:SAPLMMTE:0200/subEDITOR:SAPLMMTE:0201/cntlTEXT_EDITOR_0201/shellcont/shell").setSelectionIndexes 8,8
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-NETPR[10,0]").text = sht.cells(i,9).Value 'Price
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT14").select
Next
Regards
Guero
Hi Script Man,
Thank you for your replies
Finaly I found the problem but it seems that it could not be solved by script.
The problem is that rows(ids) are not only different by the parameters between [13,x] which we control but also by the path before brackets.
Below are the paths to first and second PRs cells.
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13,0]
|
for the first cell subSUB0:SAPLMEGUI:0013
for the second subSUB0:SAPLMEGUI:0010
It seems that this is characteristic of SAP Enjoy transactions.
http://scn.sap.com/thread/380940
Anyway the solvation of the problem is behind my current skills.
Regards,
Guero
Hi Guero,
If you now know where the error occurs, you can try the following:
For i= 11 to 14
x= i -11
if x = 0 then
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13," & cstr(x) & "]").text = sht.cells(i,15).Value 'Purchase requisition
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-BNFPO[14," & cstr(x) & "]").text = sht.cells(i,16).Value 'Requisition item
else
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13," & cstr(x) & "]").text = sht.cells(i,15).Value 'Purchase requisition
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-BNFPO[14," & cstr(x) & "]").text = sht.cells(i,16).Value 'Requisition item
end if
session.findById("wnd[0]").sendVKey 0
Next
It assumes that all other parameters work like the second parameter. Otherwise, one would have determine the difference for the 3rd, 4th, 5th .. parameter.
Regards,
ScriptMan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.