4D v14

Current selection

Home

 
4D v14
Current selection

Current selection    


 

 

In addition to the manipulations explained in the video, you should also note that:  

The following diagram illustrates how 4D works, in other words the SELECTION-ACTION mode:

The concept of the Current selection is one of the fundamentals of 4D that is a little different than the usual ones, especially SQL.

A current selection is a list of records obtained by querying the table (equivalent to the WHERE clause in SQL)

In 4D, we continually have a current selection per table. This selection can contain anywhere from 0 to X records.

The current selection consists of the list of records on which we’ll perform processes. You can change the current selection between two processes.

The code below corresponds to the exercise carried out in this video (2 lines for declaring simple variables are added at the top):

 C_DATE($StartYear;$EndYear)
 C_LONGINT($Year)
 
 $Year:=2011
 $YearStart:=Date("01/01/"+String($Year))
 $YearEnd:=Add to date($YearStart;1;0;-1)
 
 ALL RECORDS([Technicians])
 $Num:=Records in selection([Technicians])
 
 ARRAY TEXT(ArrTechnicians;$Num)
 ARRAY LONGINT(Arr_NumInterventions;$Num)
 
 FIRST RECORD([Technicians])
 While(Not(End selection([Technicians])))
    QUERY([Interventions];[Interventions]Technician_Initials=[Technicians]ID) // we have the list of interventions for the technician in memory.
    QUERY SELECTION([Interventions];[Interventions]Intervention_Date>=$YearStart;*)
    QUERY SELECTION([Interventions];&;[Interventions]Intervention_Date<=$YearEnd)
 
    $Index:=Selected record number([Technicians])
    ArrTechnicians{$Index}:=[Technicians]LastName
    Arr_NumInterventions{$Index}:=Records in selection([Interventions])
 
    NEXT RECORD([Technicians])
 End while

To avoid setting the size of arrays before performing the loop and assigning a value to the $Index variable during the process (which lets us discover the Selected record number function), you can use the APPEND TO ARRAY command.

 
 

 
PROPERTIES 

Product: 4D
Theme: Current selection

 
ARTICLE USAGE

Self-training ( 4D v13)
Self-training ( 4D v14)