cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting SAP table fields through VBA (SAP GUI)

07-27-2026 9:29 PM
BriceD Newcomer
130 views 0 comments
0 Likes
SAP Managed Tags
Labels
Expert InsightsLearning
Subscribe

Hi,

I managed to get the field names of the table I got when I'm using the FBL3N transaction in SAP.

To do so please find below my code:

Sub Get_Column_ID()
Application.ScreenUpdating = False

On Error Resume Next

Dim SapGuiAuto, objGui
Dim strConnection, strTransaction, session, openedtransaction
Dim i, j As Long, colOrd_ctn As Long, lastRow As Long
Dim msg

Set SapGuiAuto = GetObject("SAPGUI")
Set objGui = SapGuiAuto.GetScriptingEngine
Set strConnection = objGui.Children(i + 0)
Set strTransaction = strConnection.Children(i + 0)


For i = 0 To strConnection.Children.Count - 1

If strConnection.Children(i + 0).info.Transaction = "FBL3N" Then

Set openedtransaction = strConnection.Children(i + 0)

Let colOrd_ctn = openedtransaction.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").columnOrder.Count
ReDim colOrd_arr(0 To colOrd_ctn - 1)

For j = 0 To colOrd_ctn - 1
colOrd_arr(j) = openedtransaction.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").columnOrder.Item(j)

msg = msg & "Field " & j & ": " & colOrd_arr(j) & vbCrLf & vbCrLf

Next j

Else

End If

Next i

MsgBox msg

End Sub

 

The MsgBox gets me the full list of the fields.

My question is as follow: is it possible to modify the order of the fields using VBA? Is it also possible to add some extra fields using VBA? (i.e if I want to add the field "BUDAT" in column 11, how can I code that in VBA?)

Your help will be much appreciated!

0 Likes

Accepted Solutions (0)

Answers (0)