Tech Tip: Reality CSV Files

Interacting with delimited file structures for import and export is very important within your enterprise software. Comma Separated Values format is the most common.

Reality has included an easy format for interacting with CSV files. By using the MAKE-SPECIAL TCL command, you can create a Q-POINTER like file that will turn a CSV file into a MultiValue file. This allows you to use standard SELECT/LIST/SORT statements, and MultiValue Basic OPEN/READ/WRITE statements against the data.

You will need to provide a few options to help define how to interact with the CSV files, but the general syntax is

 
MAKE-SPECIAL {filename} CSV {filepath}

For example,

 
MAKE-SPECIAL UNION CSV C:\temp\union.csv

This will turn the CSV file in figure 1 into a Q-Pointer that displays the output found in figure 2.

"Surname","City","Country"
"Wilkinson","Newcastle","UK
"O'Driscoll","Dublin","Eire"
"Michalak","Paris","France"

Fig. 1

:LIST UNION

Page    1                               13:43:58  06 Apr 2005
Surname... City...... Country...

Wilkinson  Newcastle  UK
O'Driscoll Dublin     Eire
Michalak   Paris      France

3 Items listed.
Fig. 2

The command will create dictionary names based on the heading row. The dictionary names will be created by removing all the extra spaces in the column description and replacing the remaining spaces with periods. Eg, "First Name" becomes First.Name

There are a few options that will come in handy when working with CSV files. Since not all CSV files include headers in the first line, you have the ability to define them yourself.

Include NOHEADING to tell the Q-Pointer that there is no Header line in the CSV file.

 
MAKE-SPECIAL UNION CSV c:\temp\union.csv NOHEADING

No Dictionary items will be created when NOHEADING is supplied.

Do you have a Tech Tip to share? E-mail it to editor@intl-spectrum.com

Featured:

Sep/Oct 2011

menu
menu