User Defined Routine with Built-in Transforms

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
gdean
Participant
Posts: 24
Joined: Mon Feb 09, 2004 9:09 pm

User Defined Routine with Built-in Transforms

Post by gdean »

Hi,

I am trying to develop a routine to get the last day of the month in the format yymmdd. For this I'm using the built-in transform "MONTH.LAST". The main prupose is to provide the output of the routine as a job parameter in a sequencer job. The code for the routine is as follows:

Code: Select all

DEFFUN MONTH.LAST(Arg1) Calling "DSU.MONTH.LAST" 

NewDate = Oconv(MONTH.LAST(Arg1),"D2-")
Ans = Substrings(NewDate,7,2):Substrings(NewDate,1,2):Substrings(NewDate,4,2)
I am able to compile the routine successfully. But when I test it with the input for eg.2004-06 I get the output <ERROR>

I have successfully tried using the same statement from a transformer stage. Can someone help me with this problem?

Thank you in advance,
Gregg
nag0143
Premium Member
Premium Member
Posts: 159
Joined: Fri Nov 14, 2003 1:05 am

Post by nag0143 »

Greg,

Since Month.Last is not a userdefined routine i think you should use DSX.MONTH.LAST instead of DSU.MONTH.LAST



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

Post by ray.wurlod »

Transforms can not be called.

When you compile them into DataStage expressions, they are replaced by the expression that defines them. For example, the defining expression for the MONTH.LAST Transform (which you can determine by inspection of the Transform's properties) is ConvertMonth(%Arg1%, "L")

The next tricky thing is to determine how the routines called by built-in Transforms are Cataloged, because this is how you need to specify them in a DEFFUN declaration. In general, they are Cataloged with names beginning with "DSX." and with the function name in capitals and words therein separated by dot characters. Thus, for example, ConvertMonth is cataloged as DSX.CONVERT.MONTH.

This means that the "CALLING" clause of your DEFFUN declaration must use this name. For example:

Code: Select all

DEFFUN ConvertMonth(Arg1, Arg2) CALLING "DSX.CONVERT.MONTH"
So, your code now needs to look something like the following.

Code: Select all

DEFFUN ConvertMonth(X1, X2) CALLING "DSX.CONVERT.MONTH"

NewDate = Oconv(ConvertMonth(Arg1, "L"), "D-YMD[2,2,2]")
Note, too, that you can avoid the substringing of the result by specifically stating the required date format for the Oconv() function.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post by ketfos »

hi,
Why do we need the
DEFFUN function in this case?
You get the same results in the routine without
DEFFUN ConvertMonth(X1, X2) CALLING "DSX.CONVERT.MONTH"
this statement?

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

Post by ray.wurlod »

Because ConvertMonth is not an instrinsic function in the DataStage BASIC language. It's a regular routine. You can view its source code in the Routines branch of the Repository.

It's cataloged under DSX rather than DSU because DSX is for routines that support supplied Transforms, while DSU is for user-written (that is, written by you, me, and third-party providers, not by Ascential).

Do you claim to "get the same results" in a Routine, or in a Job Control routine? There are differences depending on what header files have been included in the former. When I tried to use ConvertMonth without a DEFFUN declaration in a Routine, I got a compile-time error "Array 'ConvertMonth' never dimensioned.", which is what I expected to get. The DEFFUN declaration is to alert the compiler to the fact that a token followed by a left parenthesis is not a reference to a dimensioned array.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
gdean
Participant
Posts: 24
Joined: Mon Feb 09, 2004 9:09 pm

Post by gdean »

Thank you very much Ray. I got it working now and I have also replaced the substringing with a single Oconv. Really appreciate your timing and deep insights into the topics posted.

-Gregg
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post by ketfos »

Thanks Ray,
You are correct and I apologize for the same.

Ketfos
Post Reply