DETECT

Synopsis

HELP:   Row-spec auto-detection hints passed to ROWDET/DETFIX (all optional)
TYPE:   OBJECT
SYNTAX: DETECT(MINREC=num,MAXREC=num/DEFAULT/FULL,MAXCOL=num,MAXROW=num,ROWOUT='str'/STREAM/DUMMY,REUSE,NOMATCH,NORANGE,REGEXP,COLCAP=num,TARGET=ALL/TEXT/CHAR/BINARY/XML/CSV/FIX,DISABLE=num/NONE/CSV/FIX/XML/ALL,SETCHR,HINTS(),FORMAT=NONE/IMSL/IMSS/IHDU/RDW/CSV/FIX/XML)

Description

The DETECT sub-object passes optional hints to the ROWDET row-spec auto-detector. It is available inside any TABLE object parallel to COMPILE, and is also used directly by the ACSV command. All parameters are optional; omitting them enables full auto-detection with defaults.

DETECT itself carries flow-control parameters (sample sizing, output redirect, suppression switches). Type-detection HINTS -- charset, byte-order, BCD/INT/FLT/BIN family masks, default CCSIDs, null sentinel list -- live in the DETECT.HINTS sub-object so the top-level DETECT stays compact and the per-type filters can grow independently.

Detection accuracy and limitations

Auto-detection is a best-effort inference from the raw bytes; it is NOT guaranteed to reconstruct the original record layout. ROWDET can only place a column boundary where the data itself carries a distinguishing feature -- a type change, a separator, a constant filler, or a regular padding pattern. Where adjacent fields share the same physical type and no boundary marker, they merge into a single detected column.

Typical cases that cannot be split without a copybook (COMPILE):

ROWDET does exploit padding when it is present and constant across the analysed records: a constant leading-zero run marks the start of a zoned number, and a constant trailing-blank run marks the end of a text field, so multiple padded fields can be separated. This only works when the values stay narrower than the field width in every analysed record; if any record fills a field completely the padding signal disappears and the fields merge.

For a guaranteed-correct column structure, supply the record description via COMPILE (a COBOL/PL/I/assembler copybook or an explicit row-spec) instead of relying on DETECT.

Analysis depth and acceptance threshold

MAXREC controls how many records are analysed before deciding on a layout:

MINREC controls how many of those records must agree on the same layout for the detected row-spec to be accepted as valid:

MAXREC and MINREC work together: MAXREC caps the CPU cost of analysis while MINREC sets the confidence threshold. A file with occasional header or trailer records of a different length is still detected correctly as long as the dominant layout appears in at least MINREC records.

Example: a file with 7 data records (fixlen=80) and 1 header record (fixlen=20) is correctly detected with the defaults MAXREC=8 MINREC=2, since 7 of the 8 analysed records share fixlen=80.

detect(MAXREC=16 MINREC=4) -- analyse up to 16 records, require 4 to agree

How the character set is determined

Unless DETECT.HINTS.CHRSET names one, the character set is detected from the data, and it matters twice over: it decides how a column's content is read, and for fixed-length records it also decides where the column BOUNDARIES are, because the detector separates text from non-text byte by byte.

The detection weighs the bytes that tell the character sets apart -- blanks, digits and letters -- and ignores the ones printable in both. Where the sample leaves no clear lead, the two record families answer differently, on purpose:

Name CHRSET explicitly whenever the data is known -- an explicit value is never overridden by either rule.

Type-detection hints (DETECT.HINTS)

All charset, byte-order, family and CCSID hints live inside DETECT.HINTS. The HINTS sub-object groups its content into per-type sub-sub-objects DATE / INT / FLT / BIN / STR plus three cross-type scalars LOCALE / CHRSET / ENDIAN and the shared NULLST list. See the detect.hints manual page for the full per-type catalogue.

Cross-type scalars (HINTS.LOCALE / HINTS.CHRSET / HINTS.ENDIAN / HINTS.NULLST):

detect(hints(chrset=EBCDIC endian=BIG locale=DE))

Per-type filters (HINTS.INT / HINTS.FLT / HINTS.BIN / HINTS.STR / HINTS.DATE):

Quick examples

detect(hints(chrset=EBCDIC endian=BIG int(bcd=PACKED width=I32) flt(family=HFP))) detect(hints(chrset=ASCII str(defasc='ISO-8859-15'))) detect(hints(int(fradig=2 bcd=PACKED))) -- 2 decimal places on detected BCD

Examples

# TABLE object with DETECT hints inside flcl conv:
read.bin(reclen=80 table(detect(hints(endian=BIG int(bcd=PACKED) flt(family=HFP)))))

# ACSV: EBCDIC z/OS data with German code page IBM-1141:
flacsv INPUT=cobol_unload.bin OUTPUT=out.zip DETECT(HINTS(CHRSET=EBCDIC ENDIAN=BIG INT(BCD=PACKED) FLT(FAMILY=HFP) STR(DEFEBC='IBM-1141')))

# ACSV: EBCDIC with platform default CCSID (FL_DEFAULT_EBCDIC_CCSID):
flacsv INPUT=cobol_unload.bin OUTPUT=out.zip DETECT(HINTS(CHRSET=EBCDIC ENDIAN=BIG INT(BCD=PACKED) FLT(FAMILY=HFP)))

# Linux C struct dump (LE floats, ASCII data, Western European strings):
flacsv INPUT=c_dump.bin OUTPUT=out.zip DETECT(HINTS(CHRSET=ASCII ENDIAN=LITTLE INT(BCD=NONE) FLT(FAMILY=IEEE) STR(DEFASC='ISO-8859-15')))

Reuse mode for mid-stream format changes

REUSE controls what happens when the format of incoming records changes mid-stream and all currently active row-specs fail to parse a record. This situation arises when binary files contain multiple logically distinct sections with different layouts.

In both modes an infinite-loop guard aborts re-detection if no record was successfully processed since the previous ROWDET call.

ROWOUT

ROWOUT writes the row-spec(s) detected by ROWDET to the specified file. The file contains one row() object per detected row-spec:

row(name='DETECTED' fixlen=20 col(name='COL0001' ...) col(name='COL0002' ...))

This output can be passed to flbcsv ROWIN= or used inside a TABLE object as a validated schema for repeated production processing.

flacsv INPUT=unknown.bin OUTPUT=result.zip DETECT(ROWOUT=inferred.tab) flbcsv INPUT=unknown.bin OUTPUT=prod.zip ROWIN=inferred.tab

SETCHR

SETCHR controls whether the detected character set is emitted as a format.str(chrset=...) annotation in the column specifications produced by CSV detection.

When SETCHR=ON the detected charset (ASCII or EBCDIC) is included in every type.string, type.integer, type.float, and type.date column spec that uses format.str():

col(name='COL0001' type.string(format.str(chrset=ASCII))) col(name='COL0002' type.integer(format.str(chrset=EBCDIC)))

When SETCHR=OFF (the default) the charset annotation is omitted and the column converter uses the row-level charset from the enclosing row-spec. Use SETCHR=ON when the ROWOUT file will be consumed in a context where the row-level charset is not available.

flacsv INPUT=mixed.bin OUTPUT=result.zip DETECT(SETCHR=ON ROWOUT=spec.tab)

Null sentinels for detected columns

DETECT.HINTS.NULLST sets the comma-separated null sentinel list applied to all type detectors. Empty values, NULL, NA, NaN and locale-specific synonyms are mapped to EMPTID by the per-type detectors so a column with sporadic "N/A" entries still classifies as INT or DATE rather than degrading to STRING.

A '+'-prefix appends the user-supplied list to the system default (see DEFAULTS.NULLST for the default list); without the prefix the user list replaces the default.

detect(hints(nullst="+TBD,-")) -- accept defaults plus "TBD" and "-" detect(hints(nullst="MISSING")) -- only "MISSING" is treated as null

Arguments