cancel
Showing results for 
Search instead for 
Did you mean: 

Use empty line

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

script_man
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi,

and thank you Script Man

I'll try it.

One more clarification.

If I want to add more than one material will x increase every time when I add material?

I mean do the newly filled lines will be included in the loop?

BR

Guero

script_man
Active Contributor
0 Kudos

Hi Guero,

this loop is looking for the first free line from top to bottom. All newly filled lines are included in the new start of the loop.

Regards,

ScriptMan

Former Member
0 Kudos

Hi Script Man,

It works perfect.

Thank you!

Guero

Former Member
0 Kudos

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

script_man
Active Contributor
0 Kudos

Hi Guero,

in the moment when the script terminates with an error, you should record a script with the Script Recorder. Then you can see how this must look lfor parameter x in the next available line.

Regards,

ScriptMan

Former Member
0 Kudos

Hi Script Man,

I recorded the actions after termination of the script but everything seemed correct.

x increased by 1 as it should.

I've also tried to use nested for next instead of Do until but It didn't work either.

If you have any other solution please share it.

Regards

Guero

script_man
Active Contributor
0 Kudos

Hi Guero,

You should record a script for the parameter i = 11 and i = 12. This complete script could be published then here in the community. One would see it with more eyes and decide what to do.

Regards,

ScriptMan

Former Member
0 Kudos

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

script_man
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

script_man
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

script_man
Active Contributor
0 Kudos

Hi Guero,

I can not help you. Please insert a debugger.

For example:

wscript.exe //x c:\tmp\myScript.vbs

Regards,

ScriptMan

Former Member
0 Kudos

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]

session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-BANFN[13,1]

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

http://sap.ittoolbox.com/groups/technical-functional/sap-log-mm/saplmegui-number-differs-every-time-...

Anyway the solvation of the problem is behind my current skills.

Regards,

Guero

script_man
Active Contributor
0 Kudos

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

Answers (0)