Function returns a value but cannot be stored in other variable

I need help to store the value returned from the function to one variable and then use that variable.

PREVIOUS_DATE_FUNCTION()
{

date '+%m %d %Y' | 
{ 
read MONTH DAY YEAR
DAY=`expr "$DAY" - 1` 
case "$DAY" in 
        0) 
           MONTH=`expr "$MONTH" - 1` 
                case "$MONTH" in 
                        0) 
                           MONTH=12 
                           YEAR=`expr "$YEAR" - 1` 
                        ;; 
                esac 
        DAY=`cal $MONTH $YEAR | grep . | fmt -1 | tail -1` 
esac 
    PREVIOUS_TEMP_DATE=$YEAR-$MONTH-$DAY
    echo $PREVIOUS_TEMP_DATE
}

}
  
PREVIOUSDATE="`PREVIOUS_DATE_FUNCTION`"
    
 tempfile=FILENAME_$PREVIOUSDATE 

output should be tempfile=FILENAME_26-06-2012 but it is coming null for $PREVIOUSDATE
tempfile=FILENAME_

This is a duplicate post of: How to store value from a function and use it?

I guess you didn't like the answers there? At any rate, you still haven't said what system/shell you are using. Your code worked for me on ksh on Solaris but I think theres a more effecienct way to accomplish this. What is "grep ." supposed to do (I guess remove blank lines)?:

$ cat x
#!/bin/ksh

PREVIOUS_DATE_FUNCTION()
{

date '+%m %d %Y' |
{
read MONTH DAY YEAR
DAY=`expr "$DAY" - 1`
case "$DAY" in
0)
MONTH=`expr "$MONTH" - 1`
case "$MONTH" in
0)
MONTH=12
YEAR=`expr "$YEAR" - 1`
;;
esac
DAY=`cal $MONTH $YEAR | grep . | fmt -1 | tail -1`
esac
PREVIOUS_TEMP_DATE=$YEAR-$MONTH-$DAY
echo $PREVIOUS_TEMP_DATE
}

}

PREVIOUSDATE="`PREVIOUS_DATE_FUNCTION`"

tempfile=FILENAME_$PREVIOUSDATE


echo $PREVIOUSDATE
echo $tempfile
$ x
2012-06-26
FILENAME_2012-06-26
$