Page 1 of 1

User Defined Routine with Built-in Transforms

Posted: Mon Jun 21, 2004 10:03 am
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

Posted: Mon Jun 21, 2004 10:56 am
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

Posted: Mon Jun 21, 2004 4:51 pm
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.

Posted: Mon Jun 21, 2004 5:41 pm
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

Posted: Mon Jun 21, 2004 9:29 pm
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.

Posted: Tue Jun 22, 2004 7:15 am
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

Posted: Tue Jun 22, 2004 10:05 am
by ketfos
Thanks Ray,
You are correct and I apologize for the same.

Ketfos