• 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

    User Fields

    The behaviour of file copy and comparison operations can be customized providing User Field classes. The purpose of the latter is to define a field type that implements the desired logic to convert and compare the specific fields.

    Using User Fields it is possible to:

    • change the actual content of a field at conversion time. For example, convert a text field to uppercase, or change a date field format
    • compare the field on totally arbitrary rules, so to match the change operated

    Such logic must be coded in a User Field class which must extend the class HPE.File.AbstractUserField, by:

    • providing the type declaration attribute FieldType
    • implementing the Value property
    • implementing the Compare method

    Once the User Field class is coded and compiled, can be added to the Ianus configuration and used in the layout definitions:

    • in XML, using the new type in the field declaration
    • in COBOL, overriding the field type with a copybook tag

    Type declaration

    The type name to be used in the layout definition, is assigned by the FieldType attribute of the class.

    For example, the following code assigns the type name lowercasechar to the class:

        [FieldType("lowercasechar")]
        public class LowerCaseCharField : AbstractUserField
        {
            public LowerCaseCharField(string name, Record container, 
                                      long offset, long size, 
                                      Codepage codepage, EncodingType encoding) 
                                      : base(name, container, offset, size, codepage, encoding)
            {
            }
    

    The type name defined in the class, can be then referenced in the layout definition.

    In the example below, the field CHAR01 is defined as lowercasechar, therefore it will be treated using the provided user field defined above:

    	<layout type="cobol" format="free">
    	01  FILE01-REC-COBOL.
    	    03  FILLER.
                @ianus*type=lowercasechar
    			05  CHAR01      PIC X(8).
    			05  CHAR02      PIC X(16).
    			05  CHAR03      PIC X(16).
    		03  ZONED-FIELDS.
    		    05  ZONED01     PIC 9(8).
    			05  ZONED02     PIC 9(8).
    		03  LAST-HH         PIC X(24) VALUE HIGH-VALUES.
    			</layout>
    

    The Value Property

    The class must implement the Value property, to get/set the value in data buffer. The logic must consider the source encoding of data.

    Example:

        public override object Value
        {
            get
            {
                byte[] v = new byte[Length];
                for (int i = 0; i < Length; i++)
                {
                    v[i]= IsEbcdic ? Codepage.EbcdicToAscii[this[i]] : this[i];
                }
                return Encoding.ASCII.GetString(v).ToLower();
            }
            set
            {
                string s = value.ToString().ToLower().PadRight((int)Length);
                byte[] v = Encoding.ASCII.GetBytes(s);
                for (int i = 0; i < Length; i++)
                {
                    this[i] = IsEbcdic ? Codepage.AsciiToEbcdic[v[i]] : v[i];
                }
            }
        }
    

    The Compare method

    The class must implement the logic to compare the field value with another value of another field.

    The method can leverage the object returned by the Value property, in which case it does not need to consider the encoding (because the Value does)

    The method Compare receives the following input parameters:

    Parameter Description
    field The field object to compare to

    Once data is compared, the method should return an integer value indicating the comparison result:

    Return code Meaning
    <0 The current field is less than other field(left < right)
    0 Fields are equal (left=right)
    >0 The other field is greater than current field (left > right)

    Example:

    public override int Compare(AbstractField field)
        {
            return string.Compare((string)Value, (string)field.Value, true);
        }
    

    Installation

    The User Field classes can be coded in C# as well as any .NET language (including COBOL if available).

    They can only be provided as DLL.

    In This Article
    Back to top Copyright 2021 - Hewlett-Packard Enterprise