4D v16

カレントセレクション

ホーム

 
4D v16
カレントセレクション

カレントセレクション    


 

 



ビデオ中で説明されている操作に加え、以下の点にも留意してください:

以下の図は4Dがどのようにレコードセレクションを処理するかを図示しています:

カレントセレクションのコンセプトは4Dの主要なものであり、SQLなどで使用されるものとはずいぶん異なります。

カレントセレクションはテーブルに対するクエリの結果得られるレコードのリストです。

カレントセレクションは各プロセスごと、各テーブル毎にひとつずつ持つことができます。このセレクションには0個以上のレコードが含まれます。

プログラムがレコードを対象に何かの処理を行う際、カレントセレクションが対象となります。

 C_DATE($YearStart;$YearEnd)
 C_LONGINT($Year;$Num)
 
 $Year:=2011
 $YearStart:=Date(String($Year)+"/01/01/") // $Yearの元旦
 $YearEnd:=Add to date($YearStart;1;0;-1) // $Yearのおおみそか
 
 ALL RECORDS([Technicians])
 $Num:=Records in selection([Technicians])
 
 ARRAY TEXT(ArrTechnicians;$Num)
 ARRAY LONGINT(Arr_NumInterventions;$Num)
 
 For($i;1;$Num)
 
    GOTO SELECTED RECORD([Technicians];$i)
    QUERY([Interventions];[Interventions]Technician_Initials=[Technicians]ID)
    QUERY SELECTION([Interventions];[Interventions]Intervention_Date>=$YearStart;*)
    QUERY SELECTION([Interventions];&;[Interventions]Intervention_Date<=$YearEnd)
 
    ArrTechnicians{$i}:=[Technicians]LastName
    Arr_NumInterventions{$i}:=Records in selection([Interventions])
 
 End for

Today, we're going to learn what the current selection consists of and what kinds of interactions occur between selections and arrays.

We’re going to get started by creating a statistical array presented in a List box. It will obtain the number of services per technician for a given period.

For this purpose, we've created a STATS form containing a list box with 2 columns and a button used to perform the calculation.

In the button's method, we're initially going to select all the technicians.
This way we can determine the number of corresponding records found and use this number to set the size of our arrays.

So we have:

  • a text array which will be the array of technicians that have $Num rows
  • and a longint array that also has $Num rows.

We just got the names of these arrays in the list box:

  • technicians array => text array
  • number of interventions array => longint array

Once these initializations are done, we position ourselves on the 1st technician; then as long as there are still technicians, we're going to search for the interventions by these technicians.

So we'll be searching in the interventions for:

  • interventions where the initials of the technician
  • are the same as the ID of the technician

At this point, we have the list of interventions for the technician loaded in memory.

In order to determine the row of the arrays to fill in, we're going to ask 4D to provide the number of the technician being processed.

Once we have this information, we can fill in:

  • the array of technicians at the $Index row and indicate that this is the last name of the technician
  • as well as the number of interventions, still at the $Index row, which will correspond to the number of records found in the Interventions table.

At this point, we've finished the statistical part except for one small detail, we just need to remember to change records when we finish processing the first one.

We can test the form and check whether we actually get a certain number of interventions for each technician.

To limit this to a given period, we're going to modify the method here and indicate, for instance, that we want to set the period to a single year, for example 2011.
So we're going to set:

  • the start of a year as being the date of January 1st of that year
  • and another variable for the end of the year that adds one year, 0 months and -1 day to the start date of the year.
    Why -1 day? Because otherwise that will put us at January 1st of the following year.

Once we have indicated these 3 items of information, we can now complete the search by a search in the selection of interventions and we're looking for all the interventions where:

  • the date is above or equal to the start of the year
  • and less than or equal to the end of the year.

We can test the form again and see what has changed.
So we do have a decrease in the period.
Now we can just change the year to 2010, for instance, and test it again.
Try 2012 and we again have a new calculation which is performed routinely based on the information contained in the search.

 
 

 
プロパティ 

プロダクト: 4D
テーマ: カレントセレクション

 
履歴 

 
ARTICLE USAGE

セルフトレーニング ( 4D v16)