Column Converter
Table Copy can be customized with user logic to convert columns.
Such logic must be coded in a column converter class which must implement the HPE.Ianus.Scripting.IColumnConverter
interface.
namespace HPE.Ianus.Scripting
{
public interface IColumnConverter
{
void Initialize(Environment env, Task task, DBFieldPair pair);
object Convert(object sourceValue);
}
}
Therefore it must implement the method Convert
, that takes care of converting the source column and return the conversion result.
The method Compare
receives the following input parameters:
Parameter | Description |
---|---|
sourceValue | Source value to be converted |
Once data is compared, the method must return an object
value as result of the conversion.
The converter class can be coded in C# when embedded as script, and in any .NET language (including COBOL if available) when provided as DLL.
Warning
Ianus provides data to the Convert
method exactly as it reads from the ADO resultset and uses the returned value according to ADO mechanisms.
Therefore it must return data in a format compatible with the target column. So if the target columns is CHAR, must return a String; if the target is VARBINARY a byte[], etc.
Example 1
public class StringConvertToUppercase : IColumnConverter
{
public void Initialize(HPE.Ianus.Environment env, HPE.Ianus.Task task, DBFieldPair pair)
{
}
public object Convert(object sourceValue)
{
return sourceValue.ToString().ToUpper();
}
}
Example 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HPE.Ianus;
using HPE.Ianus.Log;
using HPE.Ianus.File;
using HPE.Ianus.Scripting;
namespace ColumnConverters
{
public class LayedOutDbcsSbcsConverter : IColumnConverter
{
Record container = null;
EbcdicCharField sbcs01 = null;
EbcdicCharField sbcs02 = null;
DbcsEbcdicField dbcs01 = null;
DbcsEbcdicField dbcs02 = null;
DbFieldPair pair=null;
public void Initialize(HPE.Ianus.Environment env, HPE.Ianus.Task task, DBFieldPair pair)
{
this.pair=pair;
}
public object Convert(object sourceValue)
{
AbstractField f;
container = new Record((byte[])sourceValue);
f = sbcs01 = new EbcdicCharField("SBCS01", container, 0, 6, pair.SourceBitDataCodepage);
f = dbcs01 = new DbcsEbcdicField("DBCS01", container, f.Offset + f.Length, 78, pair.SourceBitDataCodepage, DbcsErrorAction.ThrowException);
f = sbcs02 = new EbcdicCharField("SBCS02", container, f.Offset + f.Length, 1, pair.SourceBitDataCodepage);
f = dbcs02 = new DbcsEbcdicField("DBCS02", container, f.Offset + f.Length, 80, pair.SourceBitDataCodepage, DbcsErrorAction.ThrowException);
string rc = (string)sbcs01.Value +
(string)dbcs01.Value +
(string)sbcs02.Value +
(string)dbcs01.Value;
return rc;
}
}
}