HELP: Read a data field based on separators and optional enclosing characters (CSV - RCF4180) TYPE: OBJECT SYNTAX: CSV(COLNAM='str',CHRSET=NONE/SYSTEM/ASCII/UCS1/UTF8/EBCDIC/UCS2BE/UTF16BE/UCS2LE/UTF16LE/UCS4BE/UTF32BE/UCS4LE/UTF32LE/LOCAL,SEPCHR[num/COMMA/COLON/SEMICOLON/TABULATOR/BLANK...],FLDCHR[num/QUOTATION/APOSTROPHE/GRAVEACCENT/PARENTHESES/RBRACKETS/SBRACKETS/BRACES/CBRACKETS/ABRACKETS...],EXCCHR[num/TABULATOR...],PADCHR=num,ALIGN=num,HEADLN,CASEHL,NONFLD)
This object is used to read a column in CSV format, which exists in multiple variants. All that is necessary to parse CSV input is a list of column separators and optional field enclosing characters. A limit on the maximum length and/or an alignment can optionally be set for better format detection.
All control characters (0x00-0x19) are regarded as row delimiters. If a padding byte is specified, it is also regarded as control character. The field enclosing characters cannot be a control or whitespace character. The defined column separators are excluded from the control characters. An additional list of code points can be specified which are excluded from the control character list.
If a field is enclosed by field enclosing characters, any kind of control character and whitespace can be in the data. If the field enclosing character is also part of the actual data, it is expected to be escaped by doubling the character (i.e. two quotation marks for a quotation mark in the data). If a field consists of only two consecutive field enclosing characters, it is treated as an empty value. A special behavior is implemented for brackets. If one of the opening brackets "(<{[" is set as field enclosing character, then the corresponding closing bracket is expected for field termination. This allows reading CSV lines like: (John Doe),(123),(42,23)
If you need 0xC285 (UTF-8 NEL) as record delimiter or any other kind of binary delimiter, please use CNV.REC() for table formatting.
Sometimes, especially on mainframe systems, the last column has a separator and any remaining padding must be read as an additional column. In this case, the HEADLN switch has been added to prevent the use of a column name containing spaces. The HEADLN switch forces the return of true for headline recognition. This can be used as a default for all columns to prevent comparing each column name with the of each column name with the corresponding string. In this case, the first row is always read as a headline, which means it is ignored. To automatically detect a header, the COLNAM must match the string, and the CASEHL switch can be used to enable a case sensitive comparison.
The CHRSET parameter selects the character set used to interpret the field's delimiter bytes (separator, field enclosing character) and the field data itself.
CHRSET=NONE (default, value 0): per-row auto-detection. At the start of each new row the first bytes are examined to determine whether the data is EBCDIC or ASCII. The delimiter recognition map is selected accordingly. String fields without an explicit per-column CHRSET inherit this per-row result via their type converter. This mode handles mixed input files where some rows are in EBCDIC and others in ASCII.
CHRSET=SYSTEM: the platform's native charset is resolved once at open time (EBCDIC on z/OS, ASCII on Linux/Windows). No per-row detection is performed. Use this value when the charset is known to match the runtime platform and per-row sniffing overhead must be avoided.
All other CHRSET values (ASCII, EBCDIC, UTF8, ...) fix the charset permanently for this column. The delimiter map and type converter are configured at open time and do not change per row.
STRING: COLNAM='str' - Column name to detect the headline [COLUMN-NAME]NUMBER: CHRSET=NONE/SYSTEM/ASCII/UCS1/UTF8/EBCDIC/UCS2BE/UTF16BE/UCS2LE/UTF16LE/UCS4BE/UTF32BE/UCS4LE/UTF32LE/LOCAL - Character set of the CSV column [NONE=per-row auto-detect]
NONE - No character set definedSYSTEM - SYSTEM (environment specific (on mainframe EBCDIC else ASCII))ASCII - ASCII (mainly used in the for open system)UCS1 - UCS-1 (for text formatting identical to ASCII < 64k)UTF8 - UTF-8 (for text formatting identical to ASCII < 2M)EBCDIC - EBCDIC (mainly used on IBM mainframe)UCS2BE - UCS-2 Big Endian (multibyte character set < 64k)UTF16BE - UTF-16 Big Endian (multibyte character set < 2M)UCS2LE - UCS-2 Little Endian (multibyte character set < 64k)UTF16LE - UTF-16 Little Endian (multibyte character set < 2M)UCS4BE - UCS-4 Big Endian (multibyte character set < 64k)UTF32BE - UTF-32 Big Endian (multibyte character set < 2M)UCS4LE - UCS-4 Little Endian (multibyte character set < 64k)UTF32LE - UTF-32 Little Endian (multibyte character set < 2M)LOCAL - LOCAL (platform specific (on mainframe EBCDIC else ASCII))NUMBER: SEPCHR[num/COMMA/COLON/SEMICOLON/TABULATOR/BLANK...] - List of separator characters as Unicode codepoints [COMMA,SEMICOLON]
COMMA - Comma separated (default)COLON - Separated by colon (':')SEMICOLON - Separated by semicolon (';')TABULATOR - Separated by tabulator (x'0009')BLANK - Separated by blank (x'0020')NUMBER: FLDCHR[num/QUOTATION/APOSTROPHE/GRAVEACCENT/PARENTHESES/RBRACKETS/SBRACKETS/BRACES/CBRACKETS/ABRACKETS...] - List of field enclosing characters as Unicode codepoints [QUOTATION,APOSTROPHE,GRAVE]
QUOTATION - Quotation mark as enclosing characterAPOSTROPHE - Apostrophe as enclosing characterGRAVEACCENT - Grave accent as enclosing characterPARENTHESES - Round brackets as enclosing characterRBRACKETS - Round brackets as enclosing characterSBRACKETS - Square brackets as enclosing characterBRACES - Curly brackets as enclosing characterCBRACKETS - Curly brackets as enclosing characterABRACKETS - Angle brackets as enclosing characterNUMBER: EXCCHR[num/TABULATOR...] - Exclude from control characters as Unicode codepoint list [NONE]
TABULATOR - Apostrophe (Single quotation mark) as enclosing characterNUMBER: PADCHR=num - Binary padding character (is regarded as additional control character) [0x00]NUMBER: ALIGN=num - Align data to the next multiple of this value in bytes [1 (no alignment)]SWITCH: HEADLN - Read over head line without compare of column names [FALSE]SWITCH: CASEHL - Case-sensitive comparison of headline identifier [FALSE]SWITCH: NONFLD - No field enclosing character [FALSE]