扩展 SAP 树

Expanding a SAP Tree

我正在使用 UFT (vbscript) 自动执行 SAP 和网页之间的流程。使用 SAP 事务 S_ALR_87013534,我在 UFT 中有一段代码将完全展开树并提取与其中一个订单号关联的值:

set tree = SAPGuiSession("Session").SAPGuiWindow("Execute Drilldown Report").SAPGuiTree("TableTreeControl")
tree.OpenItemContextMenu "PRJ "&projNum,"PRJ "&projNum
tree.SelectMenuItemById "&EXPAND"
tree.SelectNode "PRJ "&projNum
colKey_plan1 = getColNameFromTitle(tree, "Plan 2--Overall")
rowContainingOrdNum = findBudget(tree, ordNum)
plannedProjectBudget = tree.Object.GetItemText(tree.Object.GetAllNodeKeys(rowContainingOrdNum(0)), colKey_plan1)

Function getColNameFromTitle(tree, title)
    set colNames = tree.Object.GetColumnNames
    For i = 1 To (colNames.length-1)
        selectedColTitle = tree.Object.GetColumnTitleFromName(colNames(i))
        If selectedColTitle = title Then
            getColNameFromTitle = colNames(i)
            Exit For
        End If
    Next
End Function

Function findBudget(tree, ordNum)
    rowContainingOrdNum = Array()
    Set columnNames = tree.Object.GetColumnNames()
    set columnKeys = tree.Object.GetColumnCol(columnNames(0))
    For i = 1 To (columnKeys.length-1)
        If InStr(columnKeys(i), ordNum)>0 Then
            AddItem rowContainingOrdNum, i
            Exit For
        End If
    Next
    findBudget = rowContainingOrdNum
End Function

Function AddItem(arr, val)
    ReDim Preserve arr(UBound(arr) + 1)
    arr(UBound(arr)) = val
    AddItem = arr
End Function

这很好用,但是当我使用不同的报告时,S_ALR_87013543,它仍然被识别为一棵树,但上面的代码不起作用,因为 Object 中没有 EXPAND 选项标题。我对 SAP 及其所有树以及如何使用自动化不是很熟悉,因此不胜感激任何指导或提示。

左边是我需要展开的报表,右边是代码使用的报表:

解决方案:

   Set TreeObj = SAPGuiSession("Session").SAPGuiWindow("Actual/Plan/Variance").SAPGuiTree("TableTreeControl").Object
    Set AllValues = TreeObj.GetAllNodeKeys
    Count = AllValues.Count
    Found = 0
    For i = 0 to Count-1
        NodeText = TreeObj.GetNodeTextByKey(AllValues(i))
        If NodeText = WBSelement Then
            Found = 1
            Exit For
        End if
    Next
    If Found = 1 Then
         SAPGuiSession("Session").SAPGuiWindow("Actual/Plan/Variance").SAPGuiTree("TableTreeControl").SelectNode WBS
    End If