SELECT DIRECTIVE OUTPUT

Started by Patrick Denny, April 28, 2025, 12:31:14 PM

Previous topic - Next topic

Patrick Denny

Re: SELECT directive.

A nice feature I used excessively in FoxPro was the ability to output the results of a SELECT command to multiple formats.  You could output to:

1) An existing file (APPEND/INSERT).
2) A "created on the fly" permanent physical file.
3) A temp/MEMORY file.
4) A named physical "temp" file, similar to a *MEMORY* file, which would be auto deleted when closed or at the end of the program.
5) Other output formats, i.e. Excel, CSV, Tab Delimited, etc...

I believe the SELECT command syntax was simple:

SELECT ... [APPEND] TO [MEM|TMP|FILE|XLS|XLSX|CSV|TXT|etc] [filename]]

   - Type "FILE" would be an existing file or a file created by the SELECT command.
   - You might need to supply parameters for "created on the fly" files (FILE) and temp file (TMP) output:
       fieldname(type,length,etc){,fieldname(type,length,etc){,fieldname...}}
       If memory serves me, you could "name fields" for your output using an "AS" clause,
         something like: CUST_NUMBER AS CUSTID(C,6), CUST_NAME AS NAME(C,35), ...
          - "C" being character data, "N" numeric, "D" dates, etc..

When the results would be output to *MEMORY* or a named file, you could use that file in a subsequent SELECT command and perform additional data selection, via another SELECT command, to a) "filter" data, b) JOIN the output to another table, c) use your imagination!

I would be able to construct SELECT statements that were optimized to receive filtered output, then use that output to do "more" via additional SELECT commands or as data to use as needed.

With the ability to save and reuse the results, you could feed into "anything": Report Writer, Charts/Graphs, Queries/Lookups (to display the results), etc...  You might load a GRID or LIST_BOX using the results.  I believe that was even an OPTION in various controls, that the data source could be based on a SELECT statement.  You might also need to refresh/reload the control by refreshing the SELECT command at times, based on changing parameters.

This was powerful in that the results could be used "however you want" rather than being confined to a SELECT/NEXT RECORD command structure.  Since the data was auto generated and available for use, there was no additional programming needed to manually save the results to your desired (reusable) output format.

Mike King

You can do something similar by defining a query that has the fields you need then open the query using *query* ; panel ; library.

While it doesn't create actual files, it does provide a logical file that you can read and the data can come from multiple data sources using file links in the query definition.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com