ジュリアンデートのレプリケーション【リアルタイムレプリケーションツールDBMoto】


AS/400でジュリアンデートを持つデータは、スクリプトを介してyyyy/MM/dd形式に変換してレプリケーションすることが可能です。

ソース:AS/400(SALDATEがジュリアンデートです)

ターゲット:Oracle(SALDATEがジュリアンデートから変換してyyyyMMdd形式にする予定のフィールドです)

●グローバルスクリプトに下記を記述します

Imports Microsoft.VisualBasic

Imports DBMotoPublic

Imports DBMotoScript

Imports DBRS.GlobalScript

Imports System.Data

 

Namespace DBRS

 

 

    Public Class GlobalScript : Inherits IGlobalScript

      Public Shared globalCounter As Integer

 

     ‘This function takes a numeric Julian date in the format YYYDDD where

     ‘YYY is the number of years since 1900 and DDD is the day of the year

     ‘and returns a VB.Net date value or Null if the original value was null

 

     ‘One adds this function to the global script and uses it in a mapping

     ‘expression.  Be sure to set the source column to Use Unmapped

 

       Public Shared Function JulianToDate(obj as Object) as Object

         ‘If the value is null return null

         If obj Is Nothing Then Return Nothing

 

         ‘If the value is non numeric return null

         If Not IsNumeric(obj) Then Return Nothing

 

         ‘Get the year value

         Dim intYears as Integer

         intYears = Int(obj/1000)

 

         ‘Get the day of the year and subtract 1 because we’ll be adding

         ‘this value to January 1

         Dim intDays as Integer

         intDays = (obj – intYears * 1000) – 1

 

         ‘Calculate the date

         Dim datDate as Date

         datDate = CDate(“1/1/” & Str(1900 + intYears)).AddDays(intDays)

 

         ‘Return the date

        Return datDate

 

      End Function

 

    End Class

 

    Public Class MappingRule : Inherits IMappingRule

 

    End Class

 

    Public Class GlobalEvents : Inherits IGlobalEvents

 

    End Class

End Namespace

マッピング画面にて、対象のフィールドでMap to Expressionを開きます。

User functionsから先ほど設定したスクリプトの関数を選択し、引数に対象フィールド名を設定します。

●リフレッシュ結果

●ミラーリング結果

正しく変換してレプリケーションできました。

関連したトピックス

コメントを残す

メールアドレスが公開されることはありません。

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください