Help needed with Shell script

Hi all,
I need to modify the below highlighted piece to perform the below task. Please let me know as i am not able to figure out a way to do this.

[ "_${FILENAME%%%*}" = "_$FILENAME" ] || FILENAME=$(date +"$FILENAME")
if [ "_$SWITCH1" != _0 -a "_$SWITCH2" = _0 -a -z "$FILENAME" ]; then
  do_log FATAL "FILENAME needs to be set if SWITCH2=0"
  exit 1
fi
FILENAME=${FILENAME:-${tmpname##*/}}
FILENAME=${FILENAME%.txt}.txt

In the above code, I need to check the following:
If the filename starts with "xy_test", just keep the filename as it is and the assign the same to the filename
i.e. FILENAME should be xy_test.dt.yyyymmdd
but if not (i.e. if the filename is different from "xy_test") i need to assign the filename to be "12345.abc.yyyymmdd"
i.e. FILENAME should be 12345.abc.yyyymmdd

Not sure how to do this...any suggestions please!!!
Thanks in Advance!!

If using bash:

[[ "$FILENAME" == xy_test* ]] && FILENAME=${FILENAME}.yyyymmdd || FILENAME=12345.abc.yyyymmdd

for ksh:

[ "${FILENAME%${FILENAME#xy_test}}" = "xy_test" ] && FILENAME=${FILENAME}.yyyymmdd || FILENAME=12345.abc.yyyymmdd

I am sorry to ask this but how/where should i use this in my code.

Thanks for responding!!

The code supplied does what you asked ie:
If the filename starts with "xy_test" then append .yyyymmdd
otherwise assign the filename to be "12345.abc.yyyymmdd"
So you should put the line where you want this to happen, I'd assume this should be between the two bolded line above, as the last line is appending .txt to the end of the file if it's not already there.

What I have supplied is probably not what you are after, but as you didn't supply any examples of input and expected output or sufficient details. All I could do was supply exactly what you described.

For example I suspect that the string yyyymmdd is a date (perhaps today's date or the last modification date of the file or something), but without any further info you get the literal string yyyymmdd.