Problem with Routines
Moderators: chulett, rschirm, roy
Problem with Routines
Thanks Arnd and Vignesh
I need some help in writing routines.
In my transformer stage i am using so many built in
functions to find out the number of years, number of months and no of days between two given input dates.Since this becomes so complicated i want to write a routine to do this.
But i am nor very clear about writing routines.Do we have to add any spl header files and if so where can we get those header files from.Can i apply the same logic what ever i applied in my transformer stage in the routine.
Sometimes when i complie my routine i get an error "Array never dimensioned", How can i rectify the same.
Waiting for ur Response!!
Regards
SumA
I need some help in writing routines.
In my transformer stage i am using so many built in
functions to find out the number of years, number of months and no of days between two given input dates.Since this becomes so complicated i want to write a routine to do this.
But i am nor very clear about writing routines.Do we have to add any spl header files and if so where can we get those header files from.Can i apply the same logic what ever i applied in my transformer stage in the routine.
Sometimes when i complie my routine i get an error "Array never dimensioned", How can i rectify the same.
Waiting for ur Response!!
Regards
SumA
-
- Charter Member
- Posts: 199
- Joined: Tue Jan 18, 2005 2:50 am
- Location: India
use
deffun RoutineName(A1,A2) calling "DSU.RoutineName" for each of the routine.
For example: Say I have a routine 'GetFileSize' with arguments "FileName"and"FilePath", which gives me file size when i Pass input Argument.
Now if I have to use this function in some other Routine then before using this routine to get desired value. I need to explicitly define/tell DS that its a routinefunction and it accepts two values as paramater.
so, it would be as
deffun GetFileSize(A1,A2) calling "DSU.GetFileSize"
.....
.....
LvGetFileSize=GetFileSize(FileName,FilePath)
deffun RoutineName(A1,A2) calling "DSU.RoutineName" for each of the routine.
For example: Say I have a routine 'GetFileSize' with arguments "FileName"and"FilePath", which gives me file size when i Pass input Argument.
Now if I have to use this function in some other Routine then before using this routine to get desired value. I need to explicitly define/tell DS that its a routinefunction and it accepts two values as paramater.
so, it would be as
deffun GetFileSize(A1,A2) calling "DSU.GetFileSize"
.....
.....
LvGetFileSize=GetFileSize(FileName,FilePath)
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
You may get the 'arraysize' error if you use / call other routines but do not declare the function interface prior to your call.
Use the routine below to get the date diff. If you have performance issues, you can change the compulations into the 'Case' statement to avoid unnecesary computations.
********************************************************************************
* Date Version Author *
* 15/02/2005 1.0 Sai *
* *
* Purpose : Identify Days, Months and Years between 2 given dates *
* Working : Accepts from and to date in DataStage's internal integer date *
* format with the date diff type required. DateDiffType can be *
* D - Days Between *
* M - Months Between *
* Y - Years Between *
* Otherwise all 3 above concatenated with semi-colon ';' *
* If any of date is NULL or Blanks, it returns NULL *
* If FromDate is greater than to date, the values are interchanged *
********************************************************************************
If IsNULL(FromDt) Or Trim(FromDt) = '' OR IsNULL(ToDt) Or Trim(ToDt) = '' Then
Ans = @NULL
Return (Ans)
End
If ToDt >= FromDt Then
ToDate = ToDt
FromDate = FromDt
End
Else
ToDate = FromDt
FromDate = ToDt
End
DaysBetween = ToDate - FromDate
ToDate_YYYYMMDD = Ereplace(OConv(ToDate, 'D-YMD[4,2,2]'), '-', '')
FromDate_YYYYMMDD = Ereplace(OConv(FromDate, 'D-YMD[4,2,2]'), '-', '')
memVal = ToDate_YYYYMMDD - FromDate_YYYYMMDD
memVal = Fmt(memVal, "8'0'R")
YearsBetween = memVal[1, 4]
memVal = YearsBetween * 12 + ToDate_YYYYMMDD[5, 2] - FromDate_YYYYMMDD[5, 2]
If ToDate_YYYYMMDD[7, 2] < FromDate_YYYYMMDD[7, 2] Then
memVal = memVal - 1
End
MonthsBetween = memVal
Begin Case
Case DiffType = 'D'
Ans = DaysBetween
Case DiffType = 'M'
Ans = MonthsBetween
Case DiffType = 'Y'
Ans = YearsBetween
Case @TRUE
Ans = DaysBetween : ';' : MonthsBetween : ';' : YearsBetween
Use the routine below to get the date diff. If you have performance issues, you can change the compulations into the 'Case' statement to avoid unnecesary computations.
********************************************************************************
* Date Version Author *
* 15/02/2005 1.0 Sai *
* *
* Purpose : Identify Days, Months and Years between 2 given dates *
* Working : Accepts from and to date in DataStage's internal integer date *
* format with the date diff type required. DateDiffType can be *
* D - Days Between *
* M - Months Between *
* Y - Years Between *
* Otherwise all 3 above concatenated with semi-colon ';' *
* If any of date is NULL or Blanks, it returns NULL *
* If FromDate is greater than to date, the values are interchanged *
********************************************************************************
If IsNULL(FromDt) Or Trim(FromDt) = '' OR IsNULL(ToDt) Or Trim(ToDt) = '' Then
Ans = @NULL
Return (Ans)
End
If ToDt >= FromDt Then
ToDate = ToDt
FromDate = FromDt
End
Else
ToDate = FromDt
FromDate = ToDt
End
DaysBetween = ToDate - FromDate
ToDate_YYYYMMDD = Ereplace(OConv(ToDate, 'D-YMD[4,2,2]'), '-', '')
FromDate_YYYYMMDD = Ereplace(OConv(FromDate, 'D-YMD[4,2,2]'), '-', '')
memVal = ToDate_YYYYMMDD - FromDate_YYYYMMDD
memVal = Fmt(memVal, "8'0'R")
YearsBetween = memVal[1, 4]
memVal = YearsBetween * 12 + ToDate_YYYYMMDD[5, 2] - FromDate_YYYYMMDD[5, 2]
If ToDate_YYYYMMDD[7, 2] < FromDate_YYYYMMDD[7, 2] Then
memVal = memVal - 1
End
MonthsBetween = memVal
Begin Case
Case DiffType = 'D'
Ans = DaysBetween
Case DiffType = 'M'
Ans = MonthsBetween
Case DiffType = 'Y'
Ans = YearsBetween
Case @TRUE
Ans = DaysBetween : ';' : MonthsBetween : ';' : YearsBetween
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
"Array not dimensioned" usually results from a DEFFUN declaration being omitted.
DEFFUN alters the compiler that the name followed by a left parenthesis is a reference to a function. Without DEFFUN the compiler interprets a name followed by a left parenthesis as a reference to a dimensioned array element.
DEFFUN alters the compiler that the name followed by a left parenthesis is a reference to a function. Without DEFFUN the compiler interprets a name followed by a left parenthesis as a reference to a dimensioned array element.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Thanks a lot for all your responses!!
But i am using many inbult Functions like MONTH.TAG,TAG.TO.YEAR, DateCurrentDateTime
in my routine.In that case how should i define my routine.
As said if i use DSU.MONTH.TAG i get the following error
Unable to open the operating system file "DSU_BP.O/DSX.TAG.TO.YEAR".
Also from the sample code for ConvertTag they have used the following
Deffun WeekTag(A) Calling "DSX.WEEKTAG"
What does DSU and DSX stand for.
Thanks Sainath, I will defnitely try with your logic also.
Thanks
SumA
But i am using many inbult Functions like MONTH.TAG,TAG.TO.YEAR, DateCurrentDateTime
in my routine.In that case how should i define my routine.
As said if i use DSU.MONTH.TAG i get the following error
Unable to open the operating system file "DSU_BP.O/DSX.TAG.TO.YEAR".
Also from the sample code for ConvertTag they have used the following
Deffun WeekTag(A) Calling "DSX.WEEKTAG"
What does DSU and DSX stand for.
Thanks Sainath, I will defnitely try with your logic also.
Thanks
SumA
Hi Suma,
Why do you want to use built-in transforms? It is better to use IConv and OConv as used in Sainath's routine. These built-in transforms can be used in a job's transformer rather in your routine.
In simple terms,
DSU - User defined routine
DSX - Built-in Datastage routine
HTH
--Rich
Pleasure in job brings perfection in work
Why do you want to use built-in transforms? It is better to use IConv and OConv as used in Sainath's routine. These built-in transforms can be used in a job's transformer rather in your routine.
In simple terms,
DSU - User defined routine
DSX - Built-in Datastage routine
HTH
--Rich
Pleasure in job brings perfection in work
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Two points.
1. You can not invoke Transforms in Routines. The best you can do is to copy/paste the Transform definition expression into your code.
2. All of the supplied routines have their DEFFUN declarations in a header file. You can include this within your Routine as follows, ahead of any executable statement.
1. You can not invoke Transforms in Routines. The best you can do is to copy/paste the Transform definition expression into your code.
2. All of the supplied routines have their DEFFUN declarations in a header file. You can include this within your Routine as follows, ahead of any executable statement.
Code: Select all
$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Beat you to it...Sainath.Srinivasan wrote:Use the routine below to get the date diff. If you have performance issues, you can change the compulations into the 'Case' statement to avoid unnecesary computations.
viewtopic.php?t=85788
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom