Determining the last date of previous month

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
SonShe
Premium Member
Premium Member
Posts: 65
Joined: Mon Aug 09, 2004 1:48 pm

Determining the last date of previous month

Post by SonShe »

I would like to determine the last date of the previous month in a routine that I later pass as paramter to a job. For example, today I should get 07-31-2005.

I will appreciate your help.

Thanks.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

You need to get the iconv() of the first of the month then subtract one. Next oconv() it back.
Mamu Kim
SonShe
Premium Member
Premium Member
Posts: 65
Joined: Mon Aug 09, 2004 1:48 pm

Post by SonShe »

Kim,

Thanks for the reply. I still can't figure out how to get the first date of the month. However I know how I can do that in a transformer using the following code:
DATE.TAG(MONTH.FIRST((MONTH.TAG(@DATE))) - 1)

So I just pasted the same line in the routine which looks as below but gives me compile error. Please help me understand what is going on here.

Thanks.

Code in the routine:

$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

CurrDate = DATE.TAG(MONTH.FIRST((MONTH.TAG(@DATE))) - 1)

Ans = CurrDate

Compile error:

Compiling: Source = 'DSU_BP/DSU.pqpCreateCtrlFile', Object = 'DSU_BP.O/DSU.pqpCreateCtrlFile'
**************************************
Array 'DATE.TAG' never dimensioned.
Array 'MONTH.FIRST' never dimensioned.
Array 'MONTH.TAG' never dimensioned.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

You need to search for DEFFUN to call these functions. First of the month is easy. You need to oconv(@DATE, "D4-") then substring it to get year and month then put it back together.

Code: Select all

Today = oconv(@DATE, "D4-")
ThisYear = field(Today, "-", 3)
ThisMonth = field(Today, "-", 1)
FirstOfMonth = ThisMonth : "-01-" : ThisYear
EndOfLastMonth = oconv(iconv(FirstOfMonth, "D4-") - 1, "D4-")
Mamu Kim
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

DATE.TAG, MONTH.FIRST and MONTH.LAST are Transforms and can't be loaded into routines directly. You can, however, load their defining expressions. You may still need to include JOBCONTROL.H. Or, refining Kim's routine into a single expression:

Code: Select all

Oconv(Iconv(Oconv(@DATE, "D-YM[4,2]"):"-01", "DYMD") - 1, "D-YMD[4,2,2]")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
SonShe
Premium Member
Premium Member
Posts: 65
Joined: Mon Aug 09, 2004 1:48 pm

Post by SonShe »

Thank you Kim and Ray. Ray when you mentioned "You can, however, load their defining expressions", what does this mean? Can you please expand on this?

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

Post by ray.wurlod »

Open the Transform properties from Manager. On the Detail tab is the defining expression for the Transform. It's that which you can copy/paste.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
SonShe
Premium Member
Premium Member
Posts: 65
Joined: Mon Aug 09, 2004 1:48 pm

Post by SonShe »

Thank you Ray.
Post Reply