Shell script variables

hi everyone,
i'm writing shell script on hp-ux server that run by root user then (inside the script) su to database user and appl user..the reason for this script is to run some commands involve all users root and database and appl..anyway, variables when root in control is ok but when su, the variables are readable but NOT changeable..also when i define variables after su it is NOT readable and NOT changeable

Example:

1 #!/sbin/sh
2 APPLFP=`ps -ef |grep applvis| grep -v grep |grep "FNDLIBR"| wc -l`
3 FMIN_COUN=0
4 FMIN_COUN=$(($FMIN_COUN + 1))
5 su - applvis <<EOF
6 FMIN_COUN=$(($FMIN_COUN + 1))
7 if [ $FMIN_COUN -eq 0 ]; then
8 echo "ZERO"
9 else
10 echo "NOT ZERO"
11 fi
12 INSU=5
13 echo "+++++++++++++++++++++"
14 echo $APPLFP $FMIN_COUN $INSU
15 echo "+++++++++++++++++++++"
16 EOF

OUTPUT if FMIN_COUN (line 3) = 0:
NOT ZERO
+++++++++++++++++++++
45 1
+++++++++++++++++++++
the FMIN_COUN should be 2 NOt 1 cause i changed it after su at line 6

OUTPUT if FMIN_COUN (line 3) = -1:
ZERO
+++++++++++++++++++++
45 0
+++++++++++++++++++++

any thoughts and/or rules for this?...thank you

The parameter substition is taking place in the calling shell before the "su -" command executes. You are just providing a typeahead of complete commands to the "su -".

Hard to guess what the script is intended to achive because the arithmetic will be exactly the same regardlesss of the "su".

I expect that you need to put the commands in a script and mention that script in a "-c" parameter to "su".