The WRITE command selects information from a working list (or table if the SVTABLE keyword is used) and saves it to the separated variable file nominated by the FILE keyword.

To write a file to the local file system only requires the FILE keyword.

To write a file to a remote file system using the FTP protocol requires the HOST keyword with appropriate USER, PASSWORD and access details for the remote server.

The service determines the encoding to apply to the Unicode content to convert it to byte content and determines if the Unicode data needs to be archived.

Syntax:

Command

Keyword

Value

Developer notes

WRITE

FILE

value

Required. File path.

HOST

host:port

Conditional. Only required when writing to an FTP server.

USER

value

Conditional. Only required when writing to an FTP server.

PASSWORD

value

Conditional. Only required when writing to an FTP server.

NAMEFMT

0

Conditional. Only required when reading from an FTP server.

0 indicates an IBM i path name format library/file.member is to be used.

Note: no default value.

1

1 indicates a Windows path name format /directory/directory/file is to be used.

DATALINK

*PORT

Conditional. Only required when writing to an FTP server.

*PASV

Default.

MODE

*ASCII

Conditional. Only required when writing to an FTP server.

*BINARY

Default.

CONTENT

*CSV

Default. Write content as CSV data.

*TSV

Write content as TSV data.

*SV

Write content as separated by a value as specified in the SEPARATOR keyword.

SEPARATOR


Optional. See SEPARATOR.

ENCODING


Optional. See ENCODING.

SVQUOTE


Optional. See SVQUOTE.

SVHEAD


Optional. See SVHEAD.

SVEXCLUDE


Optional. See SVEXCLUDE.

SVLABEL


Optional. See SVLABEL.

SVTABLE


Optional. See SVTABLE.

SVCOLUMN


Optional. See SVCOLUMN.

APPEND

*YES

Optional. Append to existing file.

*NO

Default.

NUMBERFORMAT


Optional. See NUMBERFORMAT.

ARCHIVE


Optional. See ARCHIVE.

Example

    WRITE FILE(/folder/file.csv) #WRKLST(field,field,field)

  WRITE FILE(/folder/file.csv) SVTABLE(TBLORDER) SVCOLUMN(TBLORDER) SVLABEL(23) SVHEAD(ORDER)