ROUTINES

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

Post Reply
sainath
Premium Member
Premium Member
Posts: 138
Joined: Fri Nov 19, 2004 3:57 pm

ROUTINES

Post by sainath »

HI
i am new to datastage.I want to know how to write routine for following
situation
expiry date( in timestamp) = effective date - 1.i tried using iconv and oconv but i am not able to get result.


thanks
sai
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Sainath,

ICONV and OCONV will do what you tell them to. If I understand your question correctly, you want to write a function that returns a timestamp (I'll assume that you want YYYY-MM-DD HH:MM:SS) using either the current date.

Function MySampleRoutine(Unused)

Ans = OCONV(@DATE-1,'D-YMD[4,2,2]'):' ':OCONV(@TIME,'MTS')

Return(Ans)

(The green colored text comes from the DS function design)

This is a 1-liner which can be done directly in a transform variable or a derivation.

Is this what you were asking?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Almost but not quite. I suspect EffectiveDate is an input value, so needs to be the Routine argument. If it's an external-format date it will need an ICONV applied to it before the arithmetic. If it's a timestamp it will need decomposition into date and time components.

Code: Select all

FUNCTION ExpiryDate(EffectiveDate)

* Effective date is a Timestamp: decompose into date and time
EffDate = Field(EffectiveDate, " ", 1, 1)
EffTime = Field(EffectiveDate, " ", 2, 1)

* Convert date component into internal format
IntDate = Iconv(EffDate, "DYMD")

* Calculate date component of expiry date (business logic)
NewDate = IntDate - 1

* Convert that date into external format 
ExpDate = Oconv(NewDate, "D-YMD[4,2,2]")

* Construct timestamp to return to caller
Ans = ExpDate : " " : EffTime

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.
sainath
Premium Member
Premium Member
Posts: 138
Joined: Fri Nov 19, 2004 3:57 pm

Routine

Post by sainath »

Hi
I agree with ray that since the input date is timestamp first i have to use
ICONV then OCONV.Thank you very much for ray and Arwd for quick reply.
sai
Post Reply