0

I have searched long time before I asked you for help.

I am searching for Material Characrteristic coordinates to use them for pasting the value.

Search - transport condition value of transport condition is marked

How to get location/coordinates of marked place?

Please see the code I am using during manual maintenance (macro recording)

session.findById("wnd[0]/usr/subSUBSCR_BEWERT:SAPLCTMS:5000/tabsTABSTRIP_CHAR/tabpTAB1/ssubTABSTRIP_CHAR_GR:SAPLCTMS:5100/tblSAPLCTMSCHARS_S/ctxtRCTMS-MWERT[1,4]").Text = col3

col3 is variable which I put in the place (MWERT[1,4])

Location of transport condition characteristic is different for every material, in this case it is MWERT[1,4]. How to get it every time and put into the code:

session.findById("wnd[0]/usr/subSUBSCR_BEWERT:SAPLCTMS:5000/tabsTABSTRIP_CHAR/tabpTAB1/ssubTABSTRIP_CHAR_GR:SAPLCTMS:5100/tblSAPLCTMSCHARS_S/ctxtRCTMS-MWERT[x,y]").Text = col3

(x,y) - new coordinates took by VBA.

I tried myKey = session.ActiveWindow.GuiFocus.ID - it doesn't give me coordinates of the characteristc value which is focused.

I tried .getFocusedNodeKey() but also it is not working session.findById("wnd[0]/usr/subSUBSCR_BEWERT:SAPLCTMS:5000/tabsTABSTRIP_CHAR/tabpTAB1/ssubTABSTRIP_CHAR_GR:SAPLCTMS:5100/tblSAPLCTMSCHARS_S/ctxtRCTMS-MWERT").getFocusedNodeKey()

I tried few others configurations and test myself but nothing worth to mention.

Thank you in advance for you help. Lukas

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • Is that `MSC2N`? – Storax May 02 '23 at 18:12
  • It is difficult to help without a SAP system to work with. Does [this post](https://blogs.sap.com/2020/08/19/tip-sap-gui-scripting-vba-code-snippet-to-detect-all-ids-of-the-ui-elements/) help? – user10186832 May 02 '23 at 18:22
  • 1
    It's a [`GuiTableControl` object](https://help.sap.com/docs/search?q=GuiTableControl&product=sap_gui_for_windows&version=latest). I guess the positioning makes the matching row displayed to be visible in first position (works like a manual scrolling). If `tbl` is your `GuiTableControl` object, `tbl.VerticalScrollbar.Position` will indicate the number of the first visible row. See also this [answer](https://stackoverflow.com/a/68715008/9150270) for code about scrolling vertically a `GuiTableControl` object. – Sandra Rossi May 02 '23 at 19:56

1 Answers1

2

Let's assume I am right and you talk about MSC2N. Let's also assume that session is a object which points the the above screen of MSC2N. And let's also assume that you have already run the search function. Then the following code will enter a new value in the cell which was found

    Dim session As SAPFEWSELib.GuiSession
    
    'your code to make sure we have a valid session


    Const SEARCH_TERM = "transport condition"
    
    ' your code to search for the SEARCH_TERM 
    
    
    Dim newValue As String
    newValue = "new Value"  ' Whatever the new value might be
        
    Dim guiTbl As SAPFEWSELib.GuiTableControl
    Set guiTbl = session.FindById("wnd[0]/usr/subSUBSCR_BEWERT:SAPLCTMS:5000/tabsTABSTRIP_CHAR/tabpTAB1/ssubTABSTRIP_CHAR_GR:SAPLCTMS:5100/tblSAPLCTMSCHARS_S/")
    
    Dim guiCol As SAPFEWSELib.GuiCollection
    Dim guiColElement As SAPFEWSELib.GuiTableRow
    Set guiCol = guiTbl.Rows
       
    Dim guiTxtCharacteristic As SAPFEWSELib.GuiTextField
    Dim guiTxtValue As SAPFEWSELib.GuiTextField
    
    Dim i As Long
    
    ' In some cases the search function will not scroll in such a way that
    ' the first row of the Gui Table Control does contain the result
    ' So we have to loop through the visible rows of the table control again, just to be sure
    ' Otherwise you just could use
'    Set guiColElement = guiCol.Item(0)
'    Set guiTxtCharacteristic = guiColElement.Item(0)
'    Set guiTxtValue = guiColElement.Item(1)
'    If guiTxtCharacteristic.Text = SEARCH_TERM And guiTxtValue.Changeable Then
'        guiTxtValue.Text = newValue
'    End If


    For i = 0 To guiCol.Count - 1
        Set guiColElement = guiCol.Item(i)
        If guiColElement.Count > 1 Then
            Set guiTxtCharacteristic = guiColElement.Item(0)
            Set guiTxtValue = guiColElement.Item(1)
                                                                           
            If guiTxtCharacteristic.Text = SEARCH_TERM And guiTxtValue.Changeable Then
                guiTxtValue.Text = newValue
                Exit For
            End If
        End If
    Next i

Further reading

Storax
  • 11,158
  • 3
  • 16
  • 33