• User's guide
  • API
Search Results for

    Show / Hide Table of Contents
    • Concepts
    • Installation
    • Configuration
      • Overview
      • License
      • Datasources
      • Configuration
      • Plug-Ins
      • Codepages
      • Environment Variables
      • Include files
      • Example
    • Jobs
      • Jobs
      • Include
      • Multi-Threaded Jobs
      • Tracking Jobs
    • Tasks
      • Overview
      • Copy Check
      • Excel
      • File Compare
      • File Copy
      • File Dump
      • File Edit
      • File Format
      • Foreach
      • Generate
      • IMS/DB Data Conversion
      • JCL Submit
      • Listcat
      • Log
      • Powershell
      • Set Environment Variable
      • Sql
      • Stored Procedure Compare
      • Table Compare
      • Table Copy
      • Table Load
      • Table Scan
      • Table Unload
      • User Script
    • Layouts
      • Overview
      • XML Definition
      • COBOL Definition
      • Field data Types
    • Extensibility
      • Extending Ianus
      • Column Comparators
      • Column Converters
      • Record Comparators
      • File Editors
      • User Script
      • Record Layout Match Class
      • Column Layout Match Class
      • User Fields
      • Codepages
      • Resources
    • Usage
      • Command Line
      • Monitors
      • Programmatically
      • Unit Testing
    • Known Issues
    • Disclaimers

    File Editor

    The File Edit allows to copy a file, filtering and changing the content according to the user's needs. The filtering and editing logic must be coded in class implementing the HPE.Ianus.Scripting.IFileEditor interface.

    namespace HPE.Ianus.Scripting
    {
        interface IFileEditor
        {
            bool Include(FileEditorData info);
            void Edit(FileEditorData info);
        }
    }
    

    The class must therefore implement the following methods:

    • Include method, to define which records will be written in the output
    • Edit method, to build the content of the record being written

    For each record read, the File Edit invokes first the Include method. The latter determines which records to include in the output file.

    If the Include method returned true, FileEdit invokes the Edit method and writes the output record, as formatted by Edit. The latter has the responsibility of building the output record.

    For convenience, the class FileEditor is provided: this class implements the IFileEditor interface with methods that include every record AS-IS. User can override the method he/she needs to implement only the methods needed.

    Both Include and Edit methods receive the following input/output parameters:

    Parameter Description
    fed FileEditorData object to access the current record and layout data

    The FileEditorData contains references to instances of the following classes:

    Class Description
    InputRecord the record as read by Ianus
    OutputRecord the record to written
    CurrentInputLayout the input record layout, for layout based operations
    CurrentOuputLayout the output record layout, for layout based operations

    The user script class can be coded in C# when embedded as script, and in any .NET language (including COBOL if available) when provided as DLL.

    Example

    <?xml version="1.0" encoding="utf-8"?>
    <job name="FILEEDIT">
        <log>******************************* %FABRIZIO% *******************************</log>
        <fileedit name="EDITBIN" source="REPOASCII" target="TMPA" mode="binary">
            <source recfmt="fixed" reclen="80">IANUS.TEST.SEQ01.ASCII.DAT</source>
            <target recfmt="ls" reclen="80">FILECOPY.01.TXT</target>
            <edit>
                <![CDATA[
            using System;
            using System.Collections.Generic;
            using HPE.Ianus;
            using HPE.Ianus.Log;
            using HPE.Ianus.File;
            using HPE.Ianus.Scripting;
    
            namespace TestScript
            {
              public class DummyFilter : HPE.Ianus.Scripting.FileEditor
              {
                //
                // includes only the record with byte at offset 6 equal to �2� or �4�
                //
                public override bool Include(FileEditorData fed)
                {
                    Record r=fed.InputRecord;
                    return (r[6]=='2' || r[6]=='4');
                }
    
                //
                // copies the input to the output then replace all 0x00 by space
                //
                public override void Edit(FileEditorData fed)
                {
                    Record r=fed.InputRecord;
                    Record o=fed.OutputRecord;
                    Buffer.BlockCopy(r.Bytes, 0, o.Bytes, 0, 8);
                    o.Length=8;
                    for (int i=0; i<o.Length; i++)
                    {
                        if (o[i]==0x00) o[i]=(byte)' ';
                    }
                }
              }
            }
            ]]>
            </edit>
        </fileedit>
        <fileedit name="EDITLAYOUT" source="REPOASCII" target="TMPA" mode="layout">
            <source recfmt="fixed" reclen="80">IANUS.TEST.SEQ01.ASCII.DAT</source>
            <target recfmt="ls" reclen="80" trim="true">FILECOPY.02.TXT</target>
            <layouts>
                <include>ZZREC01.xml</include>
                <layout name="REDEF">
                    <field name="redef-key"     length="8"  type="char"/>
                    <field name="redef-txt"		length="72" type="char"/>
                </layout>
            </layouts>
            <edit>
                <![CDATA[
            using System;
            using System.Collections.Generic;
            using HPE.Ianus;
            using HPE.Ianus.Log;
            using HPE.Ianus.File;
            using HPE.Ianus.Scripting;
    
            namespace TestScript
            {
              public class DummyFilter : HPE.Ianus.Scripting.FileEditor
              {
                
                // include only records which field COMP01 is even
                public override bool Include(FileEditorData fed)
                {
                    int val=(int)fed.CurrentInputLayout["COMP01"].Value;
                    return (val % 2) == 0;
                }
                
                // create output record using an alternative layout
                public override void Edit(FileEditorData fed)
                {
                    long val=(int)fed.CurrentInputLayout["COMP01"].Value;
                   
                    Layout lo= fed.OutputLayouts["REDEF"];
                    lo["REDEF-KEY"].Value=fed.CurrentInputLayout["CHAR01"].Value
                                              .ToString().Replace('\0', ' ').ToLower();
                    lo["REDEF-TXT"].Value="X"+fed.CurrentInputLayout["COMP01"].Value.ToString();
                }
              }
            }
          ]]>
            </edit>
        </fileedit>
    </job>
    
    In This Article
    Back to top Copyright 2021 - Hewlett-Packard Enterprise