FORMAT

Synopsis

HELP:   Data format for automatic write or as default to simplify row specifications [ORG]
TYPE:   NUMBER
SYNTAX: FORMAT=ORG/FIX/LFD/DLM/VAR/CSV/TVD/XML

Description

This selection is used to define a base output format for a table to simplify the corresponding row specifications. If a default format is specified, then only the columns which differ from the defaults must describe theses differences.

For example: To write a CSV file that contains only the seventh, third and fifth column, it is sufficient to specify the three columns and their names and set the format and corresponding default values because they apply to all columns.

 fmt.tab(
   format=CSV
   default(ccsid=latin1)
   row(name='tabnam' col(name='col7') col(name='col3') col=(name='col5'))
)

By default, every column's value is enclosed in double quotes when writing in CSV format. If we don't want double quotes around the values in the second column, the row specification must be changed as follows:

 fmt.tab(
   format=CSV
   default(ccsid=latin1)
   row(name='tabnam'
        col(name='col7')
        col(name='col3' format.csv(method=none))
        col(name='col5')
   )
)

When specifying the format as FIX, there is no need to specify the format overlay in the column specification. Instead, the parameter MAXLEN or the synonym FIXLEN for the column must be set and the type defined.

For format LFD, the type specification is required and each value will be encoded with a two bytes length field in local endianness, containing the length of the data (S2X) by default. The VAR format works like LFD except that you get a pointer to the data instead of the data itself and a length field after the pointer (PPTRLEN) which is 32 bit long and in local endianness. The format VAR is only useful and possible when writing to memory. An error occurs when attempting to read this format from a file.

For the format DLM, the system specific text delimiter is the default delimiter and all data elements are converted to strings in the local character set. In other words, this format generates a text file with one line for each element.

If row specifications and no format are provided, the original data is written. For fixed length, length fields and delimiter formats, the result will be binary equal to the original file. However, when writing CSV, strings are enclosed by double quotes by default, which may result in CSV output that is not binary equal to the original CSV file.

A special behavior is implemented, if ORG is selected as format. In this case, the specified default settings are used to convert the data to the original form as close as possible. For example, by setting the SYSTEM switch as default, all strings are converted to the local character set, all binary integers, floats and length field are in system endianness, all text delimiter characters are changed to the system text delimiter, and so on. This mode is the default behavior if a table was read and 'write.record()' is used to write the table into records.

Selections