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.




 WRITE --------- FILE ----------- file path ---------------------->



             >-- HOST ----------- host:port ---------------------->


             >-- USER ----------- value -------------------------->


             >-- PASSWORD ------- value -------------------------->


             >-- NAMEFMT -------- none --------------------------->




             >-- DATALINK ------- *PASV -------------------------->



             >-- MODE ----------- *BINARY ------------------------>





             >-- CONTENT -------- *CSV --------------------------->




             >-- SEPARATOR ------ value -------------------------->






             >-- ENCODING ------- *DEFAULT ----------------------->



             >-- SVQUOTE -------- *NONE -------------------------->




             >-- SVHEAD --------- value -------------------------->


             >-- SVEXCLUDE ------ value -------------------------->


             >-- SVLABEL -------- value -------------------------->


             >-- SVTABLE -------- table name --------------------->


             >-- SVCOLUMN ------- value -------------------------->


             >-- APPEND --------- *YES --------------------------->



             >-- NUMBERFORMAT --- *NONE -------------------------->






             >-- ARCHIVE -------- file path ----------------------|





Nominate the path and file name.

This value can be a relative or absolute path. If the path is relative, the current working directory is the JSM instance directory.


The HOST keyword is only required when reading from a remote file system.

Nominate a FTP server to connect to. The FTP server can be specified as an IP address, nnn.nnn.nnn.nnn:port, or a domain name.

If a port number is not supplied on an IP address the default value 21 is used unless the keyword SECURE (*IMPLICIT) is used in which case the default port value is 990.


The USER keyword is only required when reading from a remote file system.


The PASSWORD keyword is only required when reading from a remote file system.

The password for the database server that corresponds to the USER keyword.


The NAMEFMT keyword is only valid when reading from a remote file system.

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

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


The DATALINK keyword is only valid when reading from a remote file system.

The possible values are *PASV (Passive) or *PORT (Port). *PASV is the default value.


The MODE keyword is only valid when reading from a remote file system.

The default value is *BINARY. Use a value of *ASCII if required.


By default the nominated file is processed as *CSV.

Alternately the content can be processed as a Tab separated variables (*TSV) or separated by a variable (*SV) as specified in the separator keyword. If processing content that includes a separator variable refer to the SEPARATOR, SVHEAD,  SVMODE, SVTABLE, SVCOLUMN, SVLABEL, NUMBERFORMAT, TRIM and TRUNCATE keywords for additional processing options.

The working list used to store the content must be defined with an appropriate number of columns to store the data.


The keyword SEPARATOR is to indicate what character is used as a separator. The separator does not need to be defined if the content is indicated as *CSV or *TSV.

If the SEPARATOR keyword is present and no CONTENT keyword is supplied CONTENT(*SV) is assumed.

Refer to SEPARATOR for more information.


ENCODING is used to specify what encoding must be applied to a byte content to convert it to a Unicode string. The default value for the ENCODING keyword is *DEFAULT.

Refer to ENCODING for more information.


APPEND is used to append content to and existing local file. The default value for the APPEND keyword is *NO.


The optional keyword SVQUOTE is used to explictly double quote values. The default value for SVQUOTE is *NONE. A value of *ALL means that all values are double quoted. A values of *TEXT means only text values are double quoted.


The optional keyword SVHEAD is used to describe the field layout of the separated value data.

Refer to SVHEAD for more information.


The optional keyword SVEXCLUDE is used to exclude fields from the working list data. The value is one or more comma-separated working list field names.

Refer to SVEXCLUDE for more information.


If the SVTABLE keyword is present the data is selected from the specified table using the current database connection. If no value is provided for SVTABLE the file data is retrieved from the working list argument.

Refer to SVTABLE for more information.


SVCOLUMN is only used in conjunction with the SVTABLE keyword. SVCOLUMN separates value services to define the relational database columns.

A look up on the service properties resource is done using the sv.column.{value}.

Refer to SVCOLUMN for more information.


SVLABEL is only used in conjunction with the SVTABLE keyword. SVLABEL is used to include the keyword value as the first column value for database table inserts or as the where constraint for database table selects.

Refer to SVLABEL for more information.


The optional keyword NUMBERFORMAT is used to handle numeric strings, where the decimal separator is not the decimal point character ".".

Refer to NUMBERFORMAT for more information. 


Use the optional keyword ARCHIVE to nominate the path and file name used to archive content.

Refer to ARCHIVE for more information.


















def_list name(#valueslst) fields(#std_num #std_obj #std_desc #std_amnt #std_qty) counter(#listcount) type(*working)


#jsmcmd := 'write file(' + #jsmfile + ') content(*sv) separator(' + #separator + ')'

use builtin(jsmx_command) with_args(#jsmhandle #jsmcmd) to_get(#jsmsts #jsmmsg #valueslst)