CSV.MODE

CSV.MODE

Top  Previous  Next

 

The CSV.MODE statement sets the conversion mode for CSV (comma separated variable) construction.

 

 

Format

 

CSV.MODE mode {, delim}

 

where

 

modeis the desired mode value.

 

delimis the delimiter to appear between items. If omitted or a null string, this defaults to a comma. If more than one character in length, only the first character is used.

 

 

The CSV mode setting determines the quoting rules and delimiter applied by the FORMCSV(), PRINTCSV and WRITECSV operations.

 

Three modes of conversion are supported:

1.Output conforms to the CSV format specification (RFC 4180). Items containing double quotes or the delimiter character are enclosed in double quotes with embedded double quotes replace by two adjacent double quotes.

2.Encloses all non-null values in double quotes except for numeric items that do not contain a comma. Embedded double quotes are replaced by two adjacent double quotes.

3.Encloses all values in double quotes. Embedded double quotes are replaced by two adjacent double quotes.

 

Mode 1 is used by default.

 

The optional delim component of this statement sets the delimiter character to be used, defaulting to a comma.

 

Any change to the mode or delimiter persists through subroutine calls. If changed within a subroutine, the previous value is restored on return. Use of EXECUTE to enter a new command processor level will reset the mode and delimiter to their default states. The previous mode and delimiter will be restored on return from the executed command.

 

An application can find the current CSV mode and delimiter by using the SYSTEM() function with key values 1043 and 1046 respectively. Tokens SYS$CSV.MODE and SYS$CSV.DELIM defined in the SYSCOM KEYS.H record can be used for these values.

 

 

Examples

 

S = 'ABC':@FM:'123':@FM:'A"B':@FM:'A,B'

CSV.MODE 1  ; DISPLAY FORMCSV(S)

CSV.MODE 2  ; DISPLAY FORMCSV(S)

CSV.MODE 3  ; DISPLAY FORMCSV(S)

 

The above program fragment would display

ABC,123,"A""B","A,B"

"ABC",123,"A""B","A,B"

"ABC","123","A""B","A,B"

 

 

CSV.MODE 1, '*'  ; PRINTCSV 'ABC', 'DEF', 'GHI'

 

The above program fragment would display

ABC*DEF*GHI

 

 

See also:

FORMCSV(), READCSV, WRITECSV