WRITE statements in Extract-Phase Column Logic
TABLE OF CONTENTS
- How do I use WRITE Statements in ECL?
- Syntax
- Rules for the syntax
- Examples: IF with WRITE in Extract Column Logic
How do I use WRITE Statements in ECL?
WRITE statements are optional in your Extract-Phase Column Logic text. If there are no WRITE statements in ECL, then there must be a WRITE statement either from the default Extract-Phase Record Logic, or provided in the overriding Extract-Phase Record Logic.
A default WRITE (in Extract-Phase Record Logic) still occurs if you provide WRITE statements in your Extract-Phase Column Logic text.
A WRITE statement in your Extract-Phase Column Logic text allows the following:
- Writing records to logical files of your choice.
- Performing a procedure or user-exit routine on input records.
- Writing only some of the columns.
- Writing multiple output records for each record read.
- A combination of the above.
Here are some example cases of a WRITE in Extract-Phase Column Logic:
- Write a full copy of the selected input record to a view output file
(SOURCE=INPUT, DEST=FILE=LogicalFile). - Write all columns up to that point to a named logical file. The file must be a view output file
(SOURCE=DATA, DEST=FILE=LogicalFile) - Write all columns up to that point to an extract work file that can be processed in the format phase
(SOURCE=VIEW, DEST=EXTRACT=number).
The default extract work file number is defined on the Extract Phase tab of the view. The ddname of the extract file is of the form EXTRnnn where nnn is the work file number. - Pass output records to a procedure or user-exit routine
(USEREXIT=User_Exit_name or PROCEDURE=Executable_name).
It is the EXTRACT work files that are processed in the format phase. All other records written in the above choices are written to view output files and not processed any further after the extract phase.
These WRITE options provide great flexibility in view processing.

Syntax
►───WRITE(───┬──────────┬─,─┬───────────────┬─,─┬────────┬─)───────────────►◄
└─<Source>─┘ └─<Destination>─┘ └─<Exit>─┘
The source, destination and exit are all optional and can be specified in any order, however it is recommended that source and destination are specified explicitly.
If no source is specified, then it will default based on the output format selected on the View Properties tab.
If no destination is specified, then it will default to DEFAULT.
<Source> ►─►SOURCE=──┬──INPUT──┬────────────────────────────────────────────►◄
├──DATA───┤
└──VIEW───┘
┌──DEFAULT─────────────────────────────────┐
<Destination> ►─┬─►DEST=────────┬────┼──EXT=───────┬─<Extract Work File Number>─┼─►◄
└─►DESTINATION=─┘ └──EXTRACT=───┘
└──FILE= {<Logical file>,<Physical file>}──┘
<Exit> ►─┬─►PROC=──────┬─────┬────{<Procedure>}────────────┬───────────────►◄
└─►PROCEDURE=─┘ └──( {<Procedure>},<String>)──┘
└─►USEREXIT=────────┬──{<UserExit>}───────────────┬───────────────►◄
└──( {<UserExit>},<String>)───┘
SOURCE is related to the output format, specifically if complete records, or columns are being written, and if the output file is to be processed in the format phase. It will dictate which function code is generated in the XLT.
INPUT means the source records are written (after filtering). This results in a WRIN generated in the XLT.
DATA means write the column data up to this column. This results in a WRDT generated in the XLT.
VIEW means write the column data, up to this column, to an extract file to be passed to the format phase. The extract file has additional information written at the start of each record, for example the sort key for use in the format phase. This results in a WRXT being generated in the XLT.
The DEFAULT output destination for Extract-Phase only Views is the ddname Fnnnnnnn where nnnnnnn is the view ID. For example, if the view ID is 12183 the default ddname for Extract-Phase only Views is F0012183.
<Extract Work File Number> is a number between 0 and 999, referring to the the Work File Number in the DD name EXTRnnn. This will typically be specified with SOURCE=VIEW.
<Logical file>, <Physical file>, <Procedure> and <UserExit> are all the names of the components as defined in the Workbench. The Logical file and Physical file can refer to a Disk file, a Pipe or a Token.
If a Procedure or UserExit is defined, the data (as defined by the SOURCE parameter) is passed a record at a time to the UserExit or Procedure for processing, then the result can be written to a file defined by FILE or EXTRACT. <String> is optional and is passed as a PARM to the Procedure or UserExit.
Rules for the syntax
You can use a WRITE statements in Extract Column Logic and Extract Record Logic
You can have as many WRITE statements as required in your logic text.
See also topic: Rules for all Logic Text
Examples: IF with WRITE in Extract Column Logic
| Example logic text | Meaning |
|---|---|
| WRITE(SOURCE=DATA, DEST={output_file_LF.output_file_PF1}) |
Write data defined by the columns, up to this column, to physical file output_file_PF1 in logical file output_file_LF. |
| WRITE(SOURCE=VIEW,DEST=EXT=001) | Write column data, up to the current column, to extract file 001. This includes the extract file record prefix required for format-phase processing. |
| IF (ISNOTNULL({field3}) THEN WRITE SOURCE=INPUT, DEST=FILE= {LogicalFile3,PhysicalFile1}) ENDIF |
If field3 is not nulls then write the record to PhysicalFile1 in LogicalFile3. In this case the the source record is written, and not the view column data. |
| IF {Field_Code} = “01” THEN WRITE(SOURCE=DATA, DESTINATION=FILE={output_file_LF.output_file_PF_1}) ELSE IF {Field_Code} = “02” THEN WRITE(SOURCE=DATA, DESTINATION=FILE={output_file_LF.output_file_PF_2}) ELSE WRITE(SOURCE=DATA, DESTINATION=FILE={output_file_LF.output_file_PF_3}) ENDIF ENDIF |
Write data defined by the columns, up to the current column, to different physical files depending on the code in ‘Field_Code’. |
| WRITE(SOURCE=INPUT, USEREXIT={write-Exit1}, DEST=FILE={output_file_LF.output_file_PF1}) |
Pass a source record to user exit ‘write-Exit1’, then write the result to output_file_PF1. |