cancel
Showing results for 
Search instead for 
Did you mean: 

UDFcode for year's Quarter and months' name

Former Member
0 Kudos

Hi Experts

I need a UDF code for the following function :

This function takes input as a date (string) in mmddyyyy format

for eg 02112009 and has to calculate

a) which quarter of the year the file belongs to for eg. is the date is for 11th month then the date belongs to 4th quarter

b) and has to give the 3 months name of that quarter for e.g October , November , December

basically has to fill the Line below in the file with inputs

" This file belongs to XXX and has months m1 , m2 and m3 in this quarter "

where xxx is the quarter calculated in the function

and m1 m2 and m3 are the months' names

kindly help

Thanks

Dev

Accepted Solutions (1)

Accepted Solutions (1)

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

there is no calculation necessary in this one

just check the month's number and create a small if:

if month >= 03 then 1st etc

and put the names of the month ...

that's all

there is no special logic in that and I can be written in java in 5 mins...

Regards,

Michal Krawczyk

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

you could also do it without UDF.

Use Substring (starting position 2 and length 2) of your input string.

Then use FixValues with:

01 -> this file belongs to 1 quarter and has months Jan , Feb and Mar in this quarter

02 -> this file belongs to 1 quarter and has months Jan , Feb and Mar in this quarter

..

04 -> this file belongs to 2 quarter and has months...

But alwas be careful with substring-function and empty or too short values (null pointer ex).

Regards

Patrick

Former Member
0 Kudos

Hi,

u can achieve this playing with inbuilt functions also,

But an Udf will be useful is u have lot of suck elements to map..

map the source field to UDF and output of UDF to where exactly u want to populate the values,

Input: input

So the udf code will be,

-


String temp = null;

if(Integer.parseInt(input.substring(2,4))<=3)

{

temp ="This file belongs to" + 4 +"and has months" +"JAN , FEB, MAR in this quarter ";

}

else if (Integer.parseInt(input.substring(2,4))<=6)

{

temp ="This file belongs to" + 1 + "and has months" +"APR , MAY, JUN in this quarter ";

}

else if (Integer.parseInt(input.substring(2,4))<=9)

{

temp ="This file belongs to" + 2 + "and has months" + "JUL , AUG, SEP in this quarter ";

}

else if (Integer.parseInt(input.substring(2,4))<=12)

{

temp = "This file belongs to" + 3 + "and has months" +"OCT , NOV, DEC in this quarter ");

}

return temp;

-


If still any prblm.. do post

Babu

Edited by: hlbabu123 on Mar 12, 2010 7:02 PM