Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to define filter and layout for MB56 result


Hi Gurus,

I just started to work with scripts, so please do not judge me.

Could you please help me to define filter for SAP T_code MB56 result in order to filter result for only specific materials, which are in  "component_list.txt" on C:drive. Also is there way to describe layout for MB56 result?

There is code, but it works in one SAP instance, and doesn't work in another.

session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").setCurrentCell -1,"MATNR"
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectColumn "MATNR"
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton "&MB_FILTER"
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem "&FILTER"
session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/btn%_%%DYN001_%_APP_%-VALU_PUSH").PRESS
session.findById("wnd[2]/tbar[0]/btn[23]").press


session.findById("wnd[3]/usr/ctxtDY_PATH").text = "C:/"
session.findById("wnd[3]/usr/ctxtDY_FILENAME").text = "component_LIST.txt"   --------------> sap stops here and wait for me to choose file name
session.findById("wnd[3]/usr/ctxtDY_FILENAME").caretPosition = 18
session.findById("wnd[3]/tbar[0]/btn[0]").press
session.findById("wnd[2]/tbar[0]/btn[8]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press

THANK YOU!!!

Elena

Former Member
replied

Hi Elena,

one should the first question clarify first. The other issues must be clarified later.

What you may not know, but unfortunately this is true, the SAP GUI Script Recorder can record any Windows dialogs. Here you have to look for workaround. And it might look like this:

Instead of the switch import from text file (session.findById("wnd[2]/tbar[0]/btn[23]").press)

we use the switch uploading from clipboard (session.findById("wnd[2]/tbar[0]/btn[24]").press). The only thing you still have to solve is the reading of a text file and filling the Windows clipboard.

The modified program code could look like this:

Set args = WScript.Arguments

V_FileName = args.Item(0)
V_Plant = args.Item(1)
V_Material = args.Item(2)
V_Batch = args.Item(3)

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.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 application, "on"
End If
session.findById("wnd[0]").resizeWorkingPane 134,24,false
session.findById("wnd[0]/tbar[0]/okcd").text = "/nMB56"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/chkPA_TRFPO").selected = false
session.findById("wnd[0]/usr/chkPA_ALCOA").selected = false
session.findById("wnd[0]/usr/chkPA_CHLAL").selected = false
session.findById("wnd[0]/usr/chkPA_KZNUL").selected = false
session.findById("wnd[0]/usr/chkPA_ALBTC").selected = true
session.findById("wnd[0]/usr/radPA_LIST").select
session.findById("wnd[0]/usr/ctxtPA_MATNR").text = V_Material
session.findById("wnd[0]/usr/ctxtPA_WERKS").text = V_Plant
session.findById("wnd[0]/usr/ctxtPA_CHARG").text = V_Batch
session.findById("wnd[0]/usr/radPA_LIST").setFocus
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").setCurrentCell -1,"MATNR"
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectColumn "MATNR"
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton "&MB_FILTER"
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem "&FILTER"
session.findById("wnd[1]/usr/ssub%_SUBSCREEN_FREESEL:SAPLSSEL:1105/btn%_%%DYN001_%_APP_%-VALU_PUSH").PRESS

Set fso = CreateObject("Scripting.FileSystemObject")

set myfile = fso.opentextfile("C:\RALF\component_LIST.txt")

myClip = myfile.readall

myfile.close

Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("clip")

Set oIn = oExec.stdIn

oIn.Write myClip

oIn.Close

Do While oExec.Status = 0

    WScript.Sleep 100

Loop

session.findById("wnd[2]/tbar[0]/btn[24]").press

session.findById("wnd[2]/tbar[0]/btn[8]").press
session.findById("wnd[1]/tbar[0]/btn[0]").press

Session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"
session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem "&PC"
Session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").Select
Session.findById("wnd[1]/tbar[0]/btn[0]").press
Session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "C:/RALF/"
Session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "component_batches.txt"
'Session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 17
Session.findById("wnd[1]/tbar[0]/btn[11]").press


set objExcel = getobject(,"Excel.Application")
objExcel.visible = true
Set objWorkbook = objExcel.Workbooks(V_FileName)
objWorkBook.Activate
objExcel.Run "SAP_ReturnMB56"

Set oIn = Nothing

Set oExec = Nothing

Regards,

ScriptMan

1 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question