WRITE

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.

 

                                                           Required

 

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

 

                                                        Conditional

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

 

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

 

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

 

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

                                  0

                                  1

 

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

                                  *PORT

 

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

                                  *ASCII

 

                                                           Optional

 

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

                                  *TSV

                                  *SV

 

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

                                  *COMMA

                                  *SEMICOLON

                                  *TAB

                                  *TILDE

 

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

                                  value

 

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

                                  *TEXT

                                  *ALL

 

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

 

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

 

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

 

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

 

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

 

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

                                  *NO

 

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

                                  *DEFAULT

                                  *CLIENT

                                  *USERAGENT

                                  value

 

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

 

 

Keywords

FILE

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.

HOST

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.

USER

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

PASSWORD

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.

NAMEFMT

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.

DATALINK

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.

MODE

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.

CONTENT

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.

SEPARATOR

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

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

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

SVQUOTE

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.

SVHEAD

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

Refer to SVHEAD for more information.

SVEXCLUDE

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.

SVTABLE

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

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

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.

NUMBERFORMAT

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. 

ARCHIVE

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

Refer to ARCHIVE for more information.

Examples

RDML

 

DEF_LIST NAME(#WRKLIST) FIELDS(#LINENUM #PARTNUM #PARTDSC #PARTAMT #PARTQTY) TYPE(*WORKING)

 

USE BUILTIN(JSM_COMMAND) WITH_ARGS('WRITE FILE(order.csv) SERVICE_LIST(LINENUM,PARTNUM,PARTDSC,PARTAMT,PARTQTY)') TO_GET(#JSMSTS #JSMMSG #WRKLIST)

 

or

 

USE BUILTIN(JSM_COMMAND) WITH_ARGS('WRITE FILE(order.csv) SEPARATOR(*TILDE) SERVICE_LIST(LINENUM,PARTNUM,PARTDSC,PARTAMT,PARTQTY)') TO_GET(#JSMSTS #JSMMSG #WRKLIST)

 

or

 

USE BUILTIN(JSM_COMMAND) WITH_ARGS('WRITE FILE(order.csv) SVHEAD(*COLUMN) SVTABLE(ORD) SVCOLUMN(ORDER) SVLABEL(23)') TO_GET(#JSMSTS #JSMMSG)

 

RDMLX

 

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)