WRITE Statements in Extract Record Logic
TABLE OF CONTENTS
- How do I use WRITE Statements in ERL?
- Default WRITE Statements
- Syntax
- Rules for the syntax
- Examples: IF with WRITE in Extract Record Logic
How do I use WRITE Statements in ERL?
The Extract-Phase Record Logic can be used to override the default WRITE statement that is generated in the Extract-Phase Record Logic of a view. The default WRITE statement is generated depending on the Default Output Format selected on the View Properties tab.
See Default WRITE Statements.
There must be at least one WRITE statement in either the Extract-Phase Record Logic or the Extract-Phase Column Logic. So if the Extract-Phase Record Logic does not contain a WRITE statement, therefore eliminating the default WRITE, there must be at least one WRITE statement in a Column.
A WRITE statement in your ERL logic text allows the following:
- Writing records to logical files of your choice.
- Performing a Procedure or UserExit Routine on input records.
- Writing multiple output records for each record read.
- A combination of the above.
Here are some example cases of a WRITE in Extract-Phase Record Logic:
- Write a full copy of the selected input record to a view output file
(SOURCE=INPUT, DEST=FILE=LogicalFile). - Write to a named logical file. The file must be a view output file
(SOURCE=DATA, DEST=FILE=LogicalFile) - Write to an extract work file that can be processed in the format phase
(SOURCE=VIEW, DEST=EXTRACT).
The 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).
Only the EXTRACT files 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.
Default WRITE Statements
For a Format-Phase Output view the default WRITE statement will be: WRITE(SOURCE=VIEW,DEST=EXT=nnn) where nnn is the extract work file number.
For an Extract-Phase Output view with output columns, the default WRITE statement will be: WRITE(SOURCE=DATA,DEST=DEFAULT)
For an Extract-Phase Output view with source-record layout, the default WRITE statement will be: WRITE(SOURCE=INPUT,DEST=DEFAULT)
Syntax
►───WRITE(───┬──────────┬─,─┬───────────────┬─,─┬────────┬─)───────────────►◄
└─<Source>─┘ └─<Destination>─┘ └─<Exit>─┘
The source, destination and exit are all optional and can be specified in any order.
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 based on the output format selected on the View Properties tab.
See Default WRITE Statements.
<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. This results in a WRDT generated in the XLT after the column processing.
VIEW means write the column data 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 after the column processing.
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 Record Logic
| Example logic text | Meaning |
|---|---|
| WRITE(SOURCE=DATA, DEST={output_file_LF.output_file_PF1}) |
Write data defined by the columns, to physical file output_file_PF1. |
| 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 to different physical files depending on the code in ‘Field_Code’. |
| WRITE(SOURCE=VIEW,DEST=EXT=001) | Write column data, including extract file record prefix, to extract file 001. |
| 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. |