Skip to Content
0
Jun 27, 2022 at 08:27 PM

SAP P01 How do I identify different boxes/dropdown selections in code for scripting purposes

332 Views Last edit Jun 27, 2022 at 08:16 PM 3 rev

So I work in supply chain and I have been trying to write a script that pulls data from an Excel file and inputs it into SAP to keep track of when orders have been received, when they must be shipped by, etc. I used the record and playback to automatically create the backbone of the script for me but now I am adding in code to be able to input the data I want to display.

One problem I have come across is certain POs not generating properly in transaction code ME22N. For example, they will generate with the improper confirmation code ZPM2 which displays the text "SNC No Conf ASN Mand" in the dropdown for the confirmation control. We cannot add our AB lines for a ZPM2 code, it must be ZPM1.

Also, when ZPM2 is default in the PO, the box for override of SNC defaults in the header section will not be checked. You can only change from ZPM2 to ZPM1 if the override box is checked. I am trying to write my script so that it will look to see if ZPM2 is currently selected in the dropdown, the code is housed in an if statement.

The way I wrote my code for this problem is that the PO has item, item overview, and header tabs all closed before running the script. When I run the script it theoretically is supposed to open the item tab, and check to see if there is ZPM2/SNC No Conf ASN Mand in the dropdown. If that is true, the if statement runs: close up the item tab again, open the header tab, check the box to override SNC defaults, close the header tab, open the item tab, change to ZPM1 (SNC Conf not Allowed), hit enter, close the item tab,

If the issue with the incorrect confirmation code being selected is not true then it is supposed to skip over the if statement entirely and run through the rest of the script normally.

image.png

image.png

During this process I noticed how in SAP, when it records a script for you, it will identify certain boxes to input data and certain tabs in the PO by long lines of code. So I am trying to figure out if there is a way to find out which lines of code represent which boxes in the SAP GUI so I may code the script to delete or search for specific input in any of these boxes.

I am not sure what the syntax would be to check for problems like

1. An AB line already exists in the item tab

2. ZPM2 is already selected in the greyed out dropdown when the override of SNC defaults box hasn't been checked yet

3. What is the identifier for each box you can input data into in the ME22N transaction code. I notice that the confirmations tab identifies each row and column as an array but how does it work for boxes in the other tabs?

Here is my code below for the issue with checking for and changing the confirmation code. The if statement won't even run. I believe this is because the if statement uses a line of code that tries to CHANGE the confirmation code and not just READ to see what confirmation code has been selected. But when I change the condition in the if statement to a .selected instead of .key, I get this error below. I don't know how the syntax for the GUI works its extremely lengthy and confusing.

image.png

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

'ZPM2 means SNC CONF NO ASN MAND 'should be a . selected. and not a .key???

session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB3:SAPLMEVIEWS:1100/subSUB1:SAPLMEVIEWS:4002/btnDYN_4000-BUTTON").press

'This closes the item tab

session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB1:SAPLMEVIEWS:1100/subSUB1:SAPLMEVIEWS:4000/btnDYN_4000-BUTTON").press

'This opens the header tab

session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT11/ssubTABSTRIPCONTROL2SUB:SAPLMEGUI:1227/ssubCUSTOMER_DATA_HEADER:SAPLXM06:0101/chkEKKO_CI-ZZSNCSET").selected = true

'This checks override of SNC defaults

session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB1:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1102/tabsHEADER_DETAIL/tabpTABHDT11/ssubTABSTRIPCONTROL2SUB:SAPLMEGUI:1227/ssubCUSTOMER_DATA_HEADER:SAPLXM06:0101/chkEKKO_CI-ZZSNCSET").setFocussession.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB1:SAPLMEVIEWS:1100/subSUB1:SAPLMEVIEWS:4000/btnDYN_4000-BUTTON").press

'This closes the header tab in SAP

session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB3:SAPLMEVIEWS:1100/subSUB1:SAPLMEVIEWS:4002/btnDYN_4000-BUTTON").press

'This opens up the item tab

session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT17/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").key = "ZPM1"

'Changes to ZPM1, means SNC CONF NOT ALLOWED

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

session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB3:SAPLMEVIEWS:1100/subSUB1:SAPLMEVIEWS:4002/btnDYN_4000-BUTTON").press

'This closes the item tabsession.findById("wnd[0]/tbar[0]/btn[11]").press

'Save button

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

'Pencil button

End If

Attachments

image.png (13.1 kB)
image.png (10.8 kB)
image.png (4.2 kB)