Joe Messingschlager
Joe Messingschlager

Reputation: 11

How can I clear all the SAP GUI fields when I open a T-Code?

When I open a T-Code from SAP GUI, some of the fields are pre-populated from past queries. Is it possible to enter a T-Code and all the fields in the next window to be forced blank?

I develop scripts for SAP GUI and run into problems if fields already have content from prior queries.

Upvotes: 1

Views: 4999

Answers (3)

Dávid Jenei
Dávid Jenei

Reputation: 73

My method for this is to loop through all the fields (and recursively on all children elements) and set the text value of them to an empty string.

On read-only fields it throws an error and this is why "On Error Resume Next" is necessary.

Sub Start_Clearing()

'setup SAP
    If Not IsObject(SAPApplication) Then
       Set SapGuiAuto = GetObject("SAPGUI")
       Set SAPApplication = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(Connection) Then
       Set Connection = SAPApplication.Children(0)
    End If
    If Not IsObject(Session) Then
       Set Session = Connection.Children(0)
    End If
    If IsObject(WScript) Then
       WScript.ConnectObject Session, "on"
       WScript.ConnectObject SAPApplication, "on"
    End If

    Dim UserArea As Object
    Set UserArea = Session.findByID("wnd[0]/usr")

    Clear_Fields UserArea

End Sub
'_______________________________

Sub Clear_Fields(Area As Object)
        
    Set SAPApplication = GetObject("SAPGUI").GetScriptingEngine
        
    Dim Obj As Object
    Dim NextArea As Object
    
    On Error Resume Next
    For i = 0 To Area.Children.Count - 1
        
        Set Obj = Area.Children(CInt(i))
        
        If Obj.ContainerType = True Then
            If Obj.Children.Count > 0 Then
                Set NextArea = SAPApplication.findByID(Obj.ID)
                Clear_Fields NextArea
            End If
        End If
        
        Obj.Text = ""
    Next i
    
End Sub

Upvotes: 0

Camifra
Camifra

Reputation: 41

You can empty some fields with :

""

session.findById("wnd[1]/usr/ctxtRMMG1_REF-BWTAR").Text = ""

But doesn't work all the time...

Upvotes: 0

Suncatcher
Suncatcher

Reputation: 10621

The history cannot be disabled user-wise. Period.

Either all or nobody.

If you want to disable the history go to SAPgui options into Local data setting

enter image description here

The history in Windows is a simple Access MDB file but it is password-protected, so you may try to crack it and delete only your user lines but it is a bunch of work.

However, I guess the history that makes you crazy is not what I described above, but SPA/GPA parameters. Check it first

Upvotes: 1

Related Questions