The DEF_LIST command can be used to define two types of list:

The following is the recommended way to define a working list in components. It defines a list containing an unlimited number of entries, within platform limits. The list will expand as required, and only occupy the space actually required

     Def_List Name(#emplist) Fields(#xEmployeeIdentification #xEmployeeSurname #xEmployeeGivenNames) Type(*Working) Entrys(*max)

A working list defined as in the following example, will occupy memory for 100 entries, although fewer entries may have been added:

     Def_List Name(#emplist) Fields(#xEmployeeIdentification #xEmployeeSurname #xEmployeeGivenNames) Type(*Working) Entrys(100)

Note: If the Entrys parameter is not defined, the working list will have the default of 50 entries.

See the Technical Reference guide for details of the DEF_LIST command.

In this step, you will define a working list and use it to contain currently selected entries in the list view Employs.

1.  Define a work field EmployKey in your form based on field xEmployeeIdentification. You will use this field to store the employee code in the working list. Your code should look like the following:

     Define Field(#Employkey) Reffld(#xEmployeeIdentification)

2.  Define a working list named EmployList, containing fields EmployKey,xEmployeeSurname, xEmployeeGivenNames and xEmployeeSalary. A working list has an Counter() parameter which contains the current number of list entries. Use the Repository field LISTCOUNT for this parameter.

     Your code should look like the following:

     Def_List Name(#EmployList) Type(*Working) Fields(#EmployKey #xEmployeeSurname #xEmployeeGivenNames #xEmployeeSalary) Counter(#LISTCOUNT) Entrys(*MAX)
 
3.  Drag and drop the field STD_NUM onto your form, above the 'Compute Selected' Group Box.

a.  On the Layout ribbon, give the field an Alignment of Bottom Center and Flow of Up

b.  Change margin Bottom to 10.

c.  On the Details tab, change Caption to Working List Entries and LabelType to Caption.

d.  Change LabelPosition to Top.

e.  Change Width to 120.

     Your design should look like the following:


4.  The LOC_ENTRY command locates an entry in a list, based on a Where clause, for example:

     Loc_Entry In_List(#EmployList) Where(#xEmployeeIdentification = #EmployKey) 

      Like LANSA's I/O commands (FETCH, UPDATE etc) the LOC_ENTRY command returns a status in field IO$STS, which may be tested using the IF_STATUS command.

     The working list EmployList should contain an entry for each selected entry in the Employs list view.

     Add code to the Employs.ItemGotSelection routine to perform the following:

     Assign STD_NUM to zero /* the list count */
     Locate an entry in EmployList where EmployeKey equals xEmployeeIdentification
     If Status is *OKAY
     - Assign EmployKey to xEmployeeIdentification
     - Add entry to EmployList
     End If

     Your code should look like the following:

     Evtroutine Handling(#Employs.ItemGotSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
     #iiiTotalSalary += #xEmployeeSalary
     #iiiTotalSalary1 #STD_NUM := 0
     Loc_Entry In_List(#EmployList) Where(#EmployKey = #xEmployeeIdentification)
     If_Status Is_Not(*OKAY)
     #EmployKey := #xEmployeeIdentification
     Add_Entry To_List(#EmployList)
     Endif
     Endroutine 

5.  Extend the Employs ItemLostSelection event routine, to delete an entry from list EmployList if a matching entry was located. Your code should like the following:

     Evtroutine Handling(#Employs.ItemLostSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
     #iiiTotalSalary -= #xEmployeeSalary
     #iiiTotalSalary1 #STD_NUM := 0
     Loc_Entry In_List(#EmployList) Where(#EmployKey = #xEmployeeIdentification)
     If_Status Is(*OKAY)
     Dlt_Entry From_List(#EmployList)
     Endif
     Endroutine 

6.  Add code to the Compute button Click event to set the form field STD_NUM to the working list count, from LISTCOUNT. Your code should now look like the following:

     Evtroutine Handling(#COMPUTE.Click)
     #iiiTotalSalary := *zeroes
     Selectlist
     If (#EMPLOYS.currentItem.selected = true)
     #IIITOTALSALARY_1 += #salary
     Endif
     Endselect
     #STD_NUM := #LISTCOUNT
     Endroutine
 
7.  Compile and test your form: