With GuiXT Controls you can make use of all "Windows Common Controls" which, as of Windows95, are part of the Windows operating system: ListView, TreeView and others. In this tutorial we will embed a ListView control into the SAP GUI window and fill it with data from the SAP system.

Our example enhances transaction VA03 (Display customer order). We will add a list of all customer orders placed within the last 30 days. With minor changes this example can easily be used for similar tasks. 

In the next tutorial we will add interactive sorting column by column and the possibility to click on a list row and display the order with VA03.

We start by implementing the GuiXT script for the initial screen in VA03. A pushbutton will allow the user to view and hide our new list display. To this purpose we use a variable  "va_show_list_control" that has the value "X" if the list is to be shown and "" when it is hidden:

if V[va_show_list_control=X]
  Box (14,0) (25,61) "Customer orders of past 30 days"
  Pushbutton (14,63) "x" size=(1,2) process="toggle_va_list_control.txt
  Control (15,1) (24.8,61) progid="Comctl.ListViewCtrl" name="va_list_control"
  Pushbutton (14,0) "Customer orders of past 30 days (order date)" size=(1,62)                         process="toggle_va_list_control.txt"

The InputScript "toggle_va_list_control.txt" simply changes the value of our status variable:

if V[va_show_list_control=X]
  Set V[va_show_list_control] ""
  Set V[va_show_list_control] "X"

In the "Control" command

  Control (15,1) (24.8,61) progid="Comctl.ListViewCtrl" name="va_list_control"

you specify the screen area and the so-called "ProgID" ("programmatic identifier" ) of the control to be displayed. The parameter name= sets the name of the GuiXT variable that will receive the control reference.

The "ProgID" is a unique name for the ActiveX component. All further attributes of the control (path, company name, version independent name etc.) are stored in the Windows registry. Physically, the control is implemented in a dll file; sometimes this can be an .ocx or a .exe file instead. 

The GuiXT script editor has a function "Tools->Display ActiveX controls" that lists all ActiveX controls installed on this PC.

So far we have created a pushbutton that displays an empty control:


In order to fill the list view control, we call a VBScript function "va03_init". We pass the reference to the control and the date for order selection in the user specific date format, using the GuiXT system variable V[today_user]:

Set V[date_from] &V[today_user] - 30
CallVbs va03_init
"&V[va_list_control]" "&V[d

In most cases the initialization of a control should be done only once. The option initflag=... helps you to decide whether the control has been newly created (flag variable set to "X"), or already existed (flag variable set to ""). With this option, our GuiXT script looks as follows:

if V[va_show_list_control=X]

  // show tree view
  Box (14,0) (25,61) "Customer orders of past 30 days"
  Pushbutton (14,63) "x" size=(1,2) process="toggle_va_list_control.txt"
  Control (15,1) (24.8,61) progid="Comctl.ListViewCtrl"
 name="va_list_control"   initflag="va_list_init"

  // initialize if necessary
  if V[va_list_init=X]

    // calculate date
    Set V[date_from] &V[today_user] - 30

    CallVbs va03_init "&V[va_list_control]" "&V[date_from]"



  Pushbutton (14,0) "Customer orders of past 30 days (order date)" size=(1,62)  process="toggle_va_list_control.txt"


When the user hides and re-displays the control, we want to update the list view with fresh data. This is why we delete the control reference variable, forcing a new creation of the control:

if V[va_show_list_control=X]
  Set V[va_show_list_control] ""
  Set V[va_show_list_control] "X"

  // force new control creation
  Set V[va_list_control]


Our GuiXT script is now complete and we can focus on the VBScript coding. The reference of the control is passed to the function  "va03_init" and we can immediately start to set attributes and call methods of the control; there is no "CreateObject" as in tutorial 3, since the GuiXT "Control" command has already created the object.

We set the layout parameters such as font, colors, column headings. Then we read the data from the SAP system via the "rfc()" method of the guixt object. The syntax and functions are similar to the GuiXT "Call" command. 

The function module that we call up is "Z_S10_SEARCHHELP", a function that has been written by Synactive as part of the Synactive S10 system (http://www.synactives10.com/s10forum). It reads searchhelp lists from the SAP system and can easily be used in GuiXT scripts.

In order to build up the parameters for the function module it is convenient to use two utility functions:

' Utility function: cut or enlarge a string to the specified length
Function xlen(f,n)
    xlen = Mid(f,1,n)
    IfLen(xlen) < n Then
        xlen = xlen + Space(n-Len(xlen))

' Utility function:  build up a select option line for SAP RFCs
Function set_selopt(name,field,sign,opt,val1,val2)
    set_selopt = xlen(name,30) & xlen(field,30) & xlen(sign,1) & xlen(opt,2) & xlen(val1,45) & xlen(val2,45)   

 The VBScript function to read the data and fill the list view is then as follows:

Function va03_init(lv, date_from)
    ' font
    lv.Font.Name = "Arial"
    lv.Font.Size = 10
    ' color
    lv.BackColor = RGB(240,240,240)   
    lv.View = 3    ' 3=lvwReport (from MS documentation)
    ' no label editing
    lv.LabelEdit = 1  '1=manually
(from MS documentation)   

    ' column headers       
    Call lv.ColumnHeaders.Add(,,"Order No", 1500)
    Call lv.ColumnHeaders.Add(,,"PO date", 2000)
    Call lv.ColumnHeaders.Add(,,"Customer", 2000)
    Call lv.ColumnHeaders.Add(,,"PO number", 3000)
    ' array of select options
    Dim selopt(0)
    selopt(0) = set_selopt("VMVAA","BSTDK", "I", "GE",  date_from, "")
    ' array of orders
    Dim orders
    Call guixt.Rfc("Z_S10_SEARCHHELP", "in.SEARCHHELP", "VMVAA",  "in.COLUMNS", 
"VBELN(10),BSTDK(10),KUNNR(10),BSTKD(20)", "table.SELOPT", selopt, 
"table.DATA(WIDTH:50)", orders) 
    ForEach Order In  orders
        Dim itmX
        Set itmX = lv.ListItems.Add(,,Mid(Order,1,10))
        itmX.SubItems(1) = Mid(Order,11,10)
        itmX.SubItems(2) = Mid(Order,21,10)
        itmX.SubItems(3) = Mid(Order,31,20)

Our embedded customer order list for VA03 is now complete:


A final tip when you use VBSEdit: To display all attributes and methods of an ActiveX control you need a CreateObject command. You can put this command in a "dummy" function that is never called:

'  to show object attributes in VBS editor
Sub dummy
    Dim x
    Set x = CreateObject("ComCtl.ListViewCtrl")
    Set x = CreateObject("ComCtl.TreeCtrl")
    Set x = CreateObject("Shell.Explorer")

Or, if you want to have a drop down list for the attribute names and methods available in VBSEdit for this ActiveX object when you type, for example, "lv. ", it is even better to use:

Function va03_init(lv, date_from)

    IfIsEmpty(lv) Then
      Set lv = CreateObject("ComCtl.ListViewCtrl")


The "CreateObject" is never executed, but for VBSEdit it furnishes the "typing" of the parameter during editing.