Adding columns in transformer (Numeric)

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Here is a function for adding intervals. They are expected to be in HH:MM or HH:MM:SS or HH:MM:SS.ssss format. It makes great use of the typeless environment available in server routines. Adapt as required.

Code: Select all

FUNCTION AddInterval(aInterval1, aInterval2)
$COPYRIGHT "Copyright (c) 2006 Ray Wurlod.  All rights reserved.  May be re-used with this notice intact."
      PRECISION 14

      Ans = @NULL

      If UnAssigned(aInterval1) Or UnAssigned(aInterval2) Then Return(Ans)
      If IsNull(aInterval1) Or IsNull(aInterval2) Then Return(Ans)

      If ((aInterval1 Matches "0N':'2N':'2N" Or aInterval1 Matches "0N':'2N" Or aInterval1 Matches "0N':'2N':'2N'.'1N0N") And (aInterval2 Matches "0N':'2N':'2N" Or aInterval2 Matches "0N':'2N" Or aInterval2 Matches "0N':'2N':'2N'.'1N0N"))
      Then

         vInterval1 = Field(aInterval1, ".", 1, 1)
         vInterval2 = Field(aInterval2, ".", 1, 1)

         vFracSeconds1 = "0." : Field(aInterval1, ".", 2, 1)
         vFracSeconds2 = "0." : Field(aInterval2, ".", 2, 1)

         Hours1 = Field(vInterval1, ":", 1, 1)
         Minutes1 = Field(vInterval1, ":", 2, 1)
         Seconds1 = Field(vInterval1, ":", 3, 1)
         Hours2 = Field(vInterval2, ":", 1, 1)
         Minutes2 = Field(vInterval2, ":", 2, 1)
         Seconds2 = Field(vInterval2, ":", 3, 1)

         IntervalSeconds = Hours1 * 3600 + Minutes1 * 60 + Seconds1 + Hours2 * 3600 + Minutes2 * 60 + Seconds2 + vFracSeconds1 + vFracSeconds2
         FracSeconds = Field(vFracSeconds1 + vFracSeconds2, ".", 2, 1)

         IntervalHours = Int(IntervalSeconds / 3600)
         IntervalSeconds = Mod(IntervalSeconds, 3600)
         IntervalMinutes = Int(IntervalSeconds / 60)
         IntervalSeconds = Int(Mod(IntervalSeconds, 60))

         Ans = (IntervalHours + 0) : ":" : Fmt(IntervalMinutes, "2'0'R") : ":" : Fmt(IntervalSeconds, "2'0'R")
         If FracSeconds Then Ans := "." : FracSeconds

      End

RETURN(Ans)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

It worked at last. Probably I was missing/adding DOTs.

Thanks everyone.

Appreciate your help as always.
Post Reply