Purpose
Find the internal name of a column in a grid control

In order to use SAP GUI scripting methods or native control methods for the SAP grid control you will often need the internal column names, for example "AUFNR" for the column "Order". Here we describe three possible ways to ascertain these internal names.

Solution 1: Use the SAP GUI scripting recorder
Start the script recording via the SAP GUI options:

 

 

Then change the width of each column for which you want to find out the name. Stop the recording and display the generated .vbs file; it will contain the internal column names. Example:

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setColumnWidth "AUFNR",14
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setColumnWidth "AUART",6
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setColumnWidth "GSTRP",11
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setColumnWidth "KTEXT",43 

The column names in this example are AUFNR, AUART,GSTRP, KTEXT.

 

Solution 2: Use a SAP GUI trace
Switch on the "GridView control" trace in the SAP GUI options:

Then start the transaction so that the grid is displayed. Switch off the trace and display the trace file. It will contain lines of the following kind:

...
<41=GridView Control : SetInfoTable: ColumnOutputLength(pInfoTableLineStretched->m_nOutputLength)=2
<41=GridView Control : F=1, T=1, nwidth=21
<41=GridView Control : SetInfoTable: ColumnNo=2
<41=GridView Control : SetInfoTable: ColumnID=AUFNR
<41=GridView Control : SetInfoTable: ColumnText=Order
<41=GridView Control : SetInfoTable: ColumnOutputLength(pInfoTableLineStretched->m_nOutputLength)=12
<41=GridView Control : F=2, T=2, nwidth=91
<41=GridView Control : SetInfoTable: ColumnNo=3
<41=GridView Control : SetInfoTable: ColumnID=AUART
<41=GridView Control : SetInfoTable: ColumnText=Order Type
<41=GridView Control : SetInfoTable: ColumnOutputLength(pInfoTableLineStretched->m_nOutputLength)=4
...

Here you see the internal column names and the corresponding column titles.


Solution 3: Use the GuiXT "Native control Interface"

The "Native conrol interface" is available in GuiXT Controls version 2019 Q1 1 and above. You can use it to write a small helper function that returns the column names and titles.

Add the following Visual Basic function in one of your VB.NET dlls in a suitable class, e.g. dll "utilities.dll" and class "grid":

  ' return internal column names
    Public Function DevHelpColumnNames() As String

        Dim gridview As GridView = guixt.getcontrol("grid")

        If gridview Is Nothing Then
            Return "Grid not found"
        End If

        Dim msg As String = ""

        For k As Integer = 1 To gridview.GetColCount()
            msg &= "// " & gridview.GetColIDFromPos(k) & vbTab _
                    & OCXUTF8(gridview.GetColText(k)) & vbCrLf
        Next

        Return msg

    End Function

    Private Function OCXUTF8(str As String) As String
        Return System.Text.Encoding.UTF8.GetChars  _
                  (System.Text.Encoding.Default.GetBytes(str))
    End Function


Add a GuiXT button in the SAP grid screen which calls up the "DevHelpColumnNames" function via an InputScript:


GuiXT script


pushbutton
(toolbar) "Show column names" process="show_column_names.txt"


 




The InputScript (see below) will also insert the column names into the Windows clipboard so that you can paste the names into your script or VB program:






InputScript

/ Development only: show internal column names
CallVB column_names = utilities.grid.DevHelpColumnNames
Message "&V[column_names]" title="Column names Insert via Ctrl+V"

// copy to Windows clipboard for script insertion
Set text[column_names] "&V[column_names]"
CopyText fromText="column_names" -toClipboard

Return 

Components
Controls