BCSV

Synopsis

HELP:   Binary-to-CSV conversion
TYPE:   OBJECT
SYNTAX: > flcl BCSV(INPUT['str'/STREAM/DUMMY...],FORMAT['str'/STREAM/DUMMY...],UNLOAD=NONE/IMSL/IMSS/IMSH/IHDU/IMSL-BOTH/IMSL-WLEN/IMSL-WOLN/IMSS-BOTH/IMSS-WLEN/IMSS-WOLN/IHDU-BOTH/IHDU-WLEN/IHDU-WOLN/DB2U/DB2S/DB2IX,OUTPUT='str'/STREAM/DUMMY,FIOMODE=STOP/APPEND/OVERWRITE,APPEND,REMAIN,FALLOC(),EXCLUDE['str'...],REMOVE,RENAME='str',CCSID='str'/DEFAULT/ASCII/EBCDIC/BOMUTF/BOMUCS/SYSTEM/LOCAL,PLATFORM=WIN/UNX/ZOS/ZOS31/ZOS64/USS/USS31/USS64/VSE/BS2/MAC,MAXOCCURS=num,RECLEN=num,ENDIAN=SYSTEM/BIG/LITTLE/LOCAL,STYLE(),ZIP(),ROWIN='str'/STREAM/DUMMY,ROWOUT='str'/STREAM/DUMMY,COLTYPE['str'...],LOGGING.{},MESSAGE(),CHRSET=AUTO/ASCII/EBCDIC,DETECT(),NORUN)

Description

The BCSV command converts binary record files (e.g. mainframe COBOL or EBCDIC data) to UTF-8 CSV format. The binary layout is described by a schema file: a COBOL copybook, a PL/I structure file or an HLASM DSECT. Each structure found in the schema produces one CSV member in the output ZIP archive.

The FORMAT parameter specifies one or more schema files. The file format is detected automatically: each compiler is asked in turn whether it recognises the file, and it answers from the content. The file name plays no part in it -- on z/OS a schema is a member of a PDS library and has no extension at all. Multiple schema files and wildcards are supported.

The INPUT parameter accepts one or more binary data files. Each file is processed against all structures found in the schema. Wildcards and multiple values are supported.

The OUTPUT parameter specifies the path to the ZIP archive that receives the generated CSV members. The ZIP sub-object controls archive-level settings such as compression algorithm and member naming. The MEMBER parameter within ZIP() sets the naming pattern for each CSV member and supports input/output name mapping tokens (see filename handling documentation). The default pattern is [name].[table].csv, where [name] expands to the filename portion of the input path (without directory components) and [table] expands to the row-spec name derived from the COBOL 01-level identifier. For example, input file TST.IDAT.BCSVCHA.F45.bin with a schema whose 01-level is BCSV-CHAR-REC produces the member TST.IDAT.BCSVCHA.F45.bin.BCSV-CHAR-REC.csv.

BCSV sets the ZIP sub-object parameter EMPTY(DELETE) by default so row-specs that never match the input data do not leave empty member placeholders in the output archive. To keep empty placeholders, set EMPTY(NONE) explicitly in the ZIP sub-object.

When the same row-spec can occur more than once inside a single input file (e.g. multiple IMS segment blocks of the same type separated by other segments), the default MEMBER pattern [name].[table].csv will produce multiple ZIP entries with the same name. FLAM reads these correctly (the data is automatically concatenated on extract via the auto-append rule in flcl_main_input_to_output_name_mapping), but third-party ZIP tools may behave inconsistently because the ZIP specification does not define duplicate member names. To obtain ISO/IEC 21320-1 compliant output, include the [midN] token (archive- local member counter) in the MEMBER pattern, for example MEMBER='[mid4].[name].[table].csv'.

The source character encoding of string fields without explicit encoding annotation in the schema is controlled by the CCSID parameter. When the parameter is omitted, the default is resolved in the following order:

1. The environment variable FL_DEFAULT_EBCDIC_CCSID (on EBCDIC platforms such as z/OS) or FL_DEFAULT_ASCII_CCSID (on ASCII platforms such as Linux, Windows, AIX, Solaris), if set. 2. The character set derived from the LANG environment variable. On z/OS with LANG=DE_DE this resolves to IBM-1141; with LANG=EN_US to IBM-1140. On Linux a trailing charset after the dot is used directly, so LANG=de_DE.UTF-8 resolves to UTF-8. 3. The platform fallback IBM-1047 (EBCDIC) or ISO-8859-1 (ASCII) when LANG is unset or set to C.

On open-world platforms the LANG default is typically UTF-8, which does not match EBCDIC binary input. An explicit CCSID is therefore required whenever BCSV is used to convert z/OS EBCDIC data on a non-z/OS host.

PLATFORM provides an alternative to an explicit CCSID for that case. It redefines the FL_PLATFORM environment variable for the read operation, so that the EBCDIC/ASCII default of the steps above is selected by the emulated platform instead of the physical host. PLATFORM=ZOS (or USS, VSE, BS2) selects the EBCDIC default and decodes string columns without an explicit CCSID correctly on an open-world host; PLATFORM=WIN, UNX or MAC selects the ASCII default. When neither CCSID nor PLATFORM is given, a string column without encoding annotation carries no character set in the compiled row specification and is resolved at read time from the running platform. An explicit CCSID still takes precedence over PLATFORM.

MAXOCCURS limits the number of OCCURS repetitions expanded per record. A value of 0 (the default) means no limit is applied.

RECLEN sets the fixed record length used to cut the binary input byte stream into records before schema parsing. When set to 0 (the default), the record length is derived in the following order of priority:

1. From the schema compiler output when exactly one top-level record definition is present and its size is deterministic (uiRowCnt==1). 2. From a FIX-group filename qualifier embedded in the input filename base. All FIX-group tokens are recognized (FB, FBA, FBM, FBS, FBSA, FBSM, FR, FRA, FRM, FS, FSA, FSM, FE, FEA, FEM, FK, FKA, FKM, FL, FLA, FLM, FA, FM, F). The qualifier digit is the net user-data length, the same value that RECLENGTH takes. BCSV reads whole records including their attributes, so RECLEN is set to the physical length: the net length plus the format overhead (0 for plain FIX, 1 for ASA/MCC, 8 for RRDS, 9 for RRDS+ASA/MCC). A plain [.]F<n>[.] qualifier sets RECLEN=n directly (net = physical for plain FIX). Examples: MYDATA.FB80.bin -> physical RECLEN=80, DATA.FBA80.bin -> physical RECLEN=81 (80 data + 1 ASA). 3. From an explicit RECLEN parameter value.

Specify RECLEN explicitly when the schema has multiple top-level records (IMS, multi-segment), when the filename qualifier is not present, or when the auto-derived value needs to be overridden.

ENDIAN selects the byte order applied to COBOL COMP-5 fields during schema compilation. COMP-5 is "native endian" by COBOL standard, so a binary file generated by IBM Enterprise COBOL on z/OS carries COMP-5 halfwords in big-endian byte order while Micro Focus COBOL on Linux stores them little-endian. The default SYSTEM follows the runtime platform and emits no explicit endian qualifier on the COMP-5 column. Use ENDIAN=BIG on an open-world host to read a mainframe unload correctly (forces big-endian decoding on x86/amd64). ENDIAN=LITTLE forces little-endian. ENDIAN=LOCAL follows the physical runtime platform (identical to SYSTEM on non-virtualized hosts). Regular COMP/COMP-4/BINARY fields are always big-endian per COBOL standard and are not influenced by this parameter.

PL/I structure definitions are compiled by the PLI2ROW schema compiler. DCL/DECLARE statements with level numbers 1 to 15 are supported; each top-level level-1 structure yields one row specification. UNION blocks produce one row per alternative (analogous to COBOL REDEFINES). DIMENSION(n) or an inline subscript F(n) expands an array field into n consecutive columns with a numeric suffix; MAXOCCURS limits the expansion. Not supported: OCCURS DEPENDING ON (variable arrays) and UNION blocks nested beyond depth 2.

Supported PL/I data types and their emitted FLAM column type strings:

FIXED BIN(p) [SIGNED] type.integer(format.bin(signed endian=BIG)) FIXED BIN(p) UNSIGNED type.integer(format.bin(endian=BIG)) FIXED DEC(p) type.integer(format.bcd(signed type=PACKED)) FIXED DEC(p,q) q>0 type.float(format.bcd(signed type=PACKED fracdigits=q)) FLOAT DEC/BIN(p<=6) type.float(format.bin(type=HFP endian=BIG width=W32)) FLOAT DEC/BIN(7<=p<=16) type.float(format.bin(type=HFP endian=BIG width=W64)) FLOAT DEC/BIN(p>16) type.float(format.bin(type=HFP endian=BIG width=W128)) CHAR(n) type.string (CCSID from BCSV.CCSID parameter) CHAR(n) VARYING type.binary() (2-byte length prefix + n raw bytes) BIT(n) type.integer(format.bin(endian=BIG)) PICTURE '9...' type.integer(format.bcd(type=ZONED)) PICTURE 'S9...' type.integer(format.bcd(signed type=ZONED)) PICTURE '9V9...' type.float(format.bcd(type=ZONED fracdigits=q)) PICTURE 'S9V9...' type.float(format.bcd(signed type=ZONED fracdigits=q)) PICTURE 'X...' / 'A...' type.string (CCSID from BCSV.CCSID parameter) FILLER / unnamed field type.binary() drain skip (not in CSV output) PTR / LABEL / ENTRY / OFFSET not emitted

FIXED BIN byte sizes: p<=8 yields 1 byte, p<=16 yields 2 bytes, p<=32 yields 4 bytes, p>32 yields 8 bytes. BIT(n) uses the same rounding rules. FIXED DEC carries an implicit sign nibble (equivalent to COBOL COMP-3 with S). All IBM Enterprise PL/I integers and floats on z/OS are big-endian; the endian=BIG qualifier is always emitted. The ALIGNED attribute inserts natural alignment padding before BIN and FLOAT fields; padding bytes appear as drain+skip columns named _ALIGN_<offset>_. UNALIGNED (the default for fixed-block record layouts) places fields consecutively without gaps.

HLASM DSECTs are compiled by the ASM2ROW schema compiler. Every labelled DS statement inside a DSECT becomes one column; each DSECT in the file yields one row specification. ORG back-references produce one further row per segment, named <dsect>_ORG01, _ORG02 and so on -- the assembler equivalent of a COBOL REDEFINES.

Supported DS types and their emitted FLAM column type strings:

CLn type.string (CCSID from BCSV.CCSID parameter) PLn type.integer(format.bcd(signed type=PACKED)) ZLn type.integer(format.bcd(signed type=ZONED)) H / F type.integer(format.bin(signed endian=BIG)) A / Y type.integer(format.bin(endian=BIG)) E / L type.float(format.bin(type=HFP endian=BIG)) D / X / B type.binary() unnamed DS type.binary() drain skip, named _FIL_<offset>_

Natural alignment is applied as the assembler applies it: a gap before an aligned field appears as a drain+skip column named _ALIGN_<offset>_, and the alignment-only forms 0H, 0F, 0D and 0CLn advance the offset without producing a column. A DSECT therefore yields the record length the assembler would produce, padding bytes included -- supply that length as RECLEN when the input is a plain fixed-block stream.

Not supported: conditional assembly, COPY expansion, USING/DROP and DC value definitions.

FIELD ANNOTATIONS

A schema file says how wide a field is and how it is encoded. It does not say that the eight digits are a date, that this one text field is held in a different character set than the rest of the record, or that a field must not leave the house. All three compilers therefore read four annotations -- DATE, CCSID, BINARY and OMIT -- from the comment that belongs to the field, in the comment syntax of the language, so that the source stays compilable:

COBOL 05 ORDDAT PIC 9(8) COMP-3. *> DATE YYYYMMDD PL/I 2 ORDDAT FIXED DEC(8), / DATE YYYYMMDD / HLASM ORDDAT DS PL4 DATE YYYYMMDD

The full catalogue -- the patterns DATE accepts, how the emitted type follows the field type, and what a malformed annotation does -- is on the COMPILE manual page, which describes the same four keywords for every place a TABLE is compiled. The COLTYPE parameter of this command takes precedence over an annotation in the file.

CHARACTER COLUMNS: FIXED TYPE OR DETECTED TYPE

A character field in a schema -- PIC X/A in COBOL, CHAR in PL/I, CL in HLASM -- declares a width and nothing else. What it holds is not part of the declaration, and in data that has grown over the years it holds anything: a number written as digits, a date, an identifier, sometimes real binary content.

Without further instruction the compiler emits type.string() for such a column, which is the safe reading and often the less useful one: a number that arrives as text stays text.

Specifying the DETECT object switches this over. Every character column is then emitted as type.detect(), and the type is decided per value -- number, string, date or hex binary -- with the LOCALE of DETECT deciding the notation a number or a date is written in:

 flcl BCSV "input='KUNDEN.DAT' format='CUSTREC.asm' reclen=37
            detect() output='kunden.zip'"

An empty DETECT() is enough; the hints inside it narrow what may be recognised. The same switch exists as the DETECT keyword of the COMPILE sub-object wherever a TABLE is described, for instance in CONV.

FIOMODE controls the behaviour when the OUTPUT ZIP already exists on disk at the start of the command: STOP fails with an AEX error, APPEND (the default) opens the existing archive and adds new members to it, OVERWRITE closes the old archive on the first member write and replaces the content. Note that FIOMODE is evaluated on every ZIP-file-open decision during the run -- in a directory walk with a shared OUTPUT, this is not the same as "OVERWRITE once, then accumulate": for a clean-slate OUTPUT use FALLOC(RENEW), which deletes the file once before any opens.

APPEND is a shortcut switch that forces member-level append semantics (equivalent to the APPEND keyword of FIOMODE); REMAIN prevents an existing member with the same name from being overwritten when writing to an existing archive. Both switches are OFF by default.

FALLOC specifies platform-dependent file allocation parameters for the ZIP output archive. On z/OS this controls RECFM, LRECL, BLKSIZE, and space allocation, which is required when writing to a sequential dataset to avoid B37 abends. On other platforms FALLOC has no effect. The FALLOC(RENEW) switch deletes the OUTPUT file once before the first open so that every BCSV run produces a fresh archive -- recommended for directory-walk scenarios that must remain idempotent across reruns.

EXCLUDE filters the INPUT file list by glob pattern and may be specified multiple times; a file is skipped if any pattern matches. REMOVE deletes each input file after successful conversion. RENAME applies a naming pattern to each input file after conversion.

Compressed input (gzip, bzip2, xz/lzma, zstd, lz4, lzip) is auto-detected by magic bytes and transparently decompressed before the schema compiler sees the data. No parameter controls this behaviour. Uncompressed input passes through without any overhead. Base-encoded (Base16/32/64) or encrypted input is NOT auto-decoded by BCSV and must be pre-processed with flcl conv before being passed to BCSV.

BCSV also accepts a single member of an archive as binary input. Append the member name to the archive URL using the member-name syntax 'archive.zip/?MEMBER_NAME' on the INPUT parameter. When a member name is present, BCSV routes the read through the archive reader and auto- detects the archive format (ZIP or FLAM4 FL4) from the leading magic bytes; no explicit archive-type flag is required. This allows test inputs or reference data packaged into one archive on z/OS to be consumed directly on open-world systems without prior extraction.

UNLOAD selects the database unload envelope that wraps the binary input. The default value NONE treats the input as a plain fixed-block stream. The values IMSL (IMS DFSURGU0 LONG IBM), IMSS (IMS DFSURGU0 SHORT IBM) and IHDU (IMS HD Unload, DFSURGL0, physical DB image) activate IMS processing; FORMAT must then specify one or more COBOL copybooks, each describing one IMS segment type. For IMSL the segment name is read from bytes 6-13 of the IMS record prefix (EBCDIC, space-padded) and used to route each data record to the matching copybook structure; for IMSS records are discriminated by fixed length only; for IHDU a 36-byte physical prefix (SEG-CODE, PRE-LEN, ROOT-LEN, DB-KEY, PTR block, marker) is skipped via drain columns and row routing uses record-length disambiguation. Records with segment code 0x00 at record offset 4 (IMS header and trailer) are drained automatically without producing CSV output; in IHDU mode the catch-all drain row is named IHDU_UNKNOWN, in IMSL/IMSS mode IMS_EOF. Each recognized segment type produces one CSV member in the output archive. Further UNLOAD values (IMSH, DB2U, DB2S, DB2IX) are reserved for future releases; see the UNLOAD manual page for details.

In UNLOAD=IHDU mode each COBOL copybook may carry an optional * SEG-CODE X'NNNN' comment annotation immediately before the 01-level definition. When present, the schema compiler emits a type.binary(match(data=X'NNNN' fmterr)) predicate on the _hdu_seg_ drain column so records are precisely routed by their SEG-CODE discriminator. Records whose SEG-CODE does not match any annotated 01-level fall through to IHDU_UNKNOWN. Annotations must sit on a COBOL comment line (indicator * in column 7 for fixed format) with an even number of hex digits between the single quotes; malformed or absent annotations fall back to record-length-only disambiguation.

The STYLE object controls the CSV formatting and ZIP compression for the output archive. See the STYLE manual page for details.

To get syntax information, please use:

   flcl SYNTAX BCSV

To get help for a parameter, please use:

   flcl HELP BCSV.parameter[.parameter[...]]

To read the manual page for a parameter, please use:

   flcl MANPAGE BCSV.parameter[.parameter[...]]

To generate the user manual for the command, please use:

   flcl GENDOCU BCSV=filename

Parameters can be set as arguments in the command line (directly or per file) or as properties taken from the corresponding property file.

Arguments