Difference Between COPY TO ARRAY and SELECT INTO ARRAY

ID: Q104053

2.50 2.50a 3.00 | 2.00 2.50 2.50a

WINDOWS         | MS-DOS
kbprg

The information in this article applies to:

  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, versions 2.5 and 2.5a
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a

SUMMARY

Once an array has been created with the COPY TO ARRAY command, the array length remains constant even when a subsequent COPY TO ARRAY command is issued. However, the SQL SELECT INTO ARRAY command creates a new array each time it is issued.

MORE INFORMATION

The following steps illustrate this behavior using the FoxPro 2.x CUSTOMER table:

1. In the Command window, issue the following commands:

      SET DEFAULT TO <path to FoxPro TUTORIAL directory>
      USE customer

2. Open the Debug window, and type "ALEN(arr)" (without the quotation
   marks). Observe the value displayed after issuing each of the
   following commands:

      COPY TO ARRAY arr FIELDS state FOR state = "CA"
      * arr has 123 elements, all of which are "CA".

      COPY TO ARRAY arr FIELDS state FOR state = "AK"
      * arr still has 123 elements, but issuing the command
      * DISPLAYMEMORY LIKE arr will show that only the first
      * element of arr is "AK"; the rest are "CA".

   NOTE: If the second COPY TO ARRAY command returns a smaller number
   of elements than those existing in the array, only that number of
   elements will be overwritten; the others will retain their former
   value.

   If the second COPY TO ARRAY command returns a larger number of
   elements than those existing in the array, the result set will be
   truncated to the number of elements in the array.

   To obtain correct results, you must use the RELEASE command to
   release the array between consecutive COPY TO ARRAY commands.

3. Observe the value of ALEN(arr) after issuing the following
   commands:

      SELECT cno FROM customer INTO array arr WHERE state = "CA"
      * arr now has 123 elements, all of which are "CA".

      SELECT cno FROM customer INTO ARRAY arr WHERE cno = "AK"
      * ALEN(arr) =1; the value is "AK".

REFERENCES

"Commands & Functions," version 2.0, COPY TO ARRAY and SELECT - SQL "Language Reference," version 2.5, pages L3-317 and L3-862

Additional reference words: VFoxWin 3.00 FoxDos FoxWin 2.50 2.00 2.50a dimension declare KBCategory: kbprg KBSubcategory: FxprgSql

Keywords          : FxprgSql 
Version           : 2.50 2.50a 3.00 | 2.00 2.50 2.50
Platform          : MS-DOS WINDOWS


Last Reviewed: April 30, 1996
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.