cancel
Showing results for 
Search instead for 
Did you mean: 

Change ME22N confirmation key fail

Former Member
0 Kudos

Hi Dears,

I want to change confirmation key, and input confirmation automatically, but when I tried to run SAP script it always failed on this line.

This is to check if confirmation control is blank, if yes, then choice C001, some times PO line already has confirmation key, some times not.

And I always got problem when I try to choice confirmation label, some times it will failed as well.

Can some body help on this, many thanks in advance.

If Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "" Then

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "C001"

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").SetFocus

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

End If

Below is total script

Option Explicit

Public SapGuiAuto As Object, Applicat As Object, Connection As Object, Session As Object

Function Attach() As Boolean

On Error Resume Next

Set SapGuiAuto = GetObject("SAPGUI")

On Error GoTo 0

If SapGuiAuto Is Nothing Then

   Attach = False

   Exit Function

   Else

   Set Applicat = SapGuiAuto.GetScriptingEngine

   On Error GoTo 0

End If

If Applicat Is Nothing Then

   Attach = False

   Exit Function

End If

If Applicat.Children.Count = 0 Then

  Attach = False

  Exit Function

  Else

  Set Connection = Applicat.Children(0)

  On Error GoTo 0

End If

Set Session = Connection.Children(0)

If Session.ActiveWindow.Text = "SAP" Then

   Attach = False

   Exit Function

End If

Attach = True

End Function

Sub addABcon1025()

Dim i, PartNo, joblen, btt

Dim P

Dim Pline

Dim saptab

Dim POline, POnum, POdate, POqty

Application.DisplayAlerts = False

Application.EnableEvents = False

joblen = Sheet1.Cells(55555, 1).End(xlUp).Row

btt = Sheet1.Cells(55555, 4).End(xlUp).Row

If Attach Then

For PartNo = 2 To 10

'Range("d3:d9").ClearContents

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

Session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme22n"

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

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

Session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-EBELN").Text = Sheet1.Cells(PartNo, 4)

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

''以上是改成我想要的PO,不用再做更改了

POdate = Sheet1.Cells(PartNo, 3)

POqty = Sheet1.Cells(PartNo, 10)

Pline = Sheet1.Cells(PartNo, 5) / 10

If Pline = 1 Then GoTo 10

If Pline < 10 Then

Sheet1.Cells(PartNo, 2) = "'   " & Pline

Else

If Pline < 100 Then

Sheet1.Cells(PartNo, 2) = "'  " & Pline

Else

If Pline < 1000 Then

Sheet1.Cells(PartNo, 2) = "' " & Pline

End If

End If

End If

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB1:SAPLMEGUI:6000/cmbDYN_6000-LIST").SetFocus

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB1:SAPLMEGUI:6000/cmbDYN_6000-LIST").Key = Sheet1.Cells(PartNo, 2) ''换成第二行

''以上是根据PO item更改行,如果没问题不要更改。

10 Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0015/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16").Select

''以上是选择Confirmation label,现在如果本来就是默认的这个label 就会报错.

If Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "" Then

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "C001"

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").SetFocus

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

End If

If Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "" Then

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "C001"

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").SetFocus

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

End If

''以上是更改confirmation key,如果为空就增加

Next PartNo

End If

Application.DisplayAlerts = True

Application.EnableEvents = True

End Sub

''update on1024,增加判断是否已经有AB的地方

If Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/ctxtEKES-EBTYP[0,0]").Text = "" Then

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/ctxtEKES-EBTYP[0,0]").Text = "ab"

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/ctxtRM06E-EEIND[2,0]").Text = POdate

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/txtEKES-MENGE[4,0]").Text = POqty

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/txtEKES-MENGE[4,0]").SetFocus

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/txtEKES-MENGE[4,0]").caretPosition = 3

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

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

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

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

Session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press

End If ''如果第一个AB code 写过了

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

I tried these lines from your script and they worked for me except that, for me, the possible values for cmbMEPO1334-BSTAE are 0001 through 0007.

Are you sure C001 is one of your possible values?  Looks like it is possible to C001 via config (SPRO)

If C001 is not the problem, can you confirm which specific line below is failing within the IF statement?  That statement is really 2 significant separate lines (you can delete the SetFocus line.  It adds no value in a script unless you need to send an F4 key)

Is it when you try to check if cmbMEPO1334-BSTAE").Key = ""  or when you try to set it?

Also, I can't tell from the code provided if you are always adding a line item then attempting to set the confirmation control key or if you are changing it on previously created line items.  Once there is a receipt against the PO line item the confirmation control key is read-only. 

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0015/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16").Select

If Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "" Then

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "C001"

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").SetFocus

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

End If

Former Member
0 Kudos

Hi Chad Horihan,

Sorry to delay.

Yes C001 would be a problem. As our SAP setup, some other confirmation type would not support to input AB confirmation.

But you know, confirmation key can't be changed, if it is already set.

That's why I always got alert message.

So I add "On Error Resume Next".

Then I don't need If condition.

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "" Then

script_man
Active Contributor
0 Kudos

Hi Patrick,

unfortunately I do not work with the above transaction. I would imagine that an error occurs when a key is not there. In this case I would try the following:

on error resume next

If Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "" Then

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "C001"

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").SetFocus

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

End If

on error goto 0

Regards,

ScriptMan