WRITESEQ statement

Syntax

WRITESEQ expression {ON | TO} file.variable [ON ERROR 
statements] 
{THEN statements [ELSE statements] | ELSE statements}

Description

Use the WRITESEQ statement to write new lines to a file opened for sequential processing. InfoSphere® DataStage® keeps a pointer to the current position in the file while it is open for sequential processing. The OPENSEQ statement sets this pointer to the first byte of the file, and it is advanced by the READSEQ statement, READBLK statement, WRITESEQ, and WRITEBLK statements.

WRITESEQ writes the value of expression followed by a newline to the file. The data is written at the current position in the file. The pointer is set to the position following the newline. If the pointer is not at the end of the file, WRITESEQ overwrites any existing data byte by byte (including the newline), starting from the current position.

file.variable specifies a file opened for sequential access.

The value of expression is written to the file as the next line, and the THEN statements are executed. If THEN statements are not specified, program execution continues with the next statement. If the specified file cannot be accessed or does not exist, the ELSE statements are executed; any THEN statements are ignored.

If expression or file.variable evaluates to the null value, the WRITESEQ statement fails and the program terminates with a run-time error message.

After executing a WRITESEQ statement, you can use the STATUS function to determine the result of the operation:

0
The record was locked before the WRITESEQ operation.
-2
The record was unlocked before the WRITESEQ operation.

File Buffering

Normally InfoSphere DataStage uses buffering for sequential input and output operations. If you use the NOBUF statement after an OPENSEQ statement, buffering is turned off and writes resulting from the WRITESEQ statement are performed right away.

You can also use the FLUSH statement after a WRITESEQ statement to cause all buffers to be written right away.

For more information about buffering, see the FLUSH and NOBUF statements.

The ON ERROR Clause

The ON ERROR clause is optional in the WRITESEQ statement. The ON ERROR clause lets you specify an alternative for program termination when a fatal error is encountered while the WRITESEQ statement is being processed.

If a fatal error occurs, and the ON ERROR clause was not specified, or was ignored (as in the case of an active transaction), the following occurs:

  • An error message appears.
  • Any uncommitted transactions begun within the current execution environment roll back.
  • The current program terminates.
  • Processing continues with the next statement of the previous execution environment, or the program returns to the command prompt.

A fatal error can occur if any of the following occur:

  • A file is not open.
  • file.variable is the null value.
  • A distributed file contains a part file that cannot be accessed.

If the ON ERROR clause is used, the value returned by the STATUS function is the error number.

If NLS is enabled, WRITESEQ and other BASIC statements that perform I/O operations always map internal data to the external character set using the appropriate map for the output file.

Example

DATA 'NEW ITEM 1', 'NEW ITEM 2'
OPENSEQ 'FILE.E', 'RECORD1' TO FILE ELSE ABORT
READSEQ A FROM FILE ELSE STOP
*
FOR I=1 TO 2
   INPUT B
   WRITESEQ B TO FILE THEN PRINT B ELSE STOP
NEXT
*
CLOSESEQ FILE
END

This is the program output:

?NEW ITEM 1
NEW ITEM 1
?NEW ITEM 2
NEW ITEM 2