Syntax Error: 'else' is not expected

We have a ksh script to insert data into our data warehouse. There are multiple if/then/else statements, most are not embedded. In this example, there is an if/then statement, and an embedded if/then/else/fi statement. The problem occurs with the closing else. I receive an error message as follows...

load.insert.profit.cmt[141]: 0403-057 Syntax error at line 519 : `else' is not expected.

If I open the script in vi and 519j to the line, it is actually an echo statement inside my else.

I have the same if/then/else structure coded above and below line 519 with no errors.

Thanks in advance for your assistance.

Schmitty

If it is possible can you post that portion of your script containing this error... That would be helpful to assist you better.

Cheers!
Vishnu.

In "vi", if the cursor is on the first line and you type "1j" you will find yourself on line number 2, not line number one. Try that.

So your 519j is not going to put you on line 519. To get to line 519 from anywhere in the file, use "519G".

Here's the section of code that I'm having problems with (the second 'else' is what's giving me the problems for now)...

if [ $RETURNCD != 4 ]
then
echo ----
echo ---- Successful Delete of $TABNAME >> $LOGFILE
echo ----
.
.
.
EOF
RETURNCD=$?

 \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
 \# check the return code from the insert
 \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
 if [ $RETURNCD = 4 ] 
 then
      echo \+\+\+\+\+
      echo \+\+\+\+\+Error Inserting into $TABNAME >> $ERRLOG
      echo \+\+\+\+\+Error Inserting into $TABNAME >> $LOGFILE
      echo \+\+\+\+\+
      else	
           echo \----	
           echo ---- Successful Insert into $TABNAME >> $LOGFILE
           echo \----	
 fi

else
echo +++++
echo +++++Error Updating $TABNAME >> $ERRLOG
echo +++++Error Updating $TABNAME >> $LOGFILE
echo +++++
fi

echo \"Commit the INSERT to $TABNAME" >> $LOGFILE
echo ---------------------------------------------- >> $LOGFILE
db2 commit

Note: I do have the if/else statements indented in the actual code if this makes a difference.

Thanks,
Schmitty

I can't see anything problematic in the above code, other than this...

echo \"Commit the INSERT to $TABNAME" >> $LOGFILE

shouldn't be

echo "Commit the INSERT to $TABNAME" >> $LOGFILE

As for the else problem, may be there are other control constructs other than the if-then-else-fi s, which lead to some illegal nesting.

Cheers!
Vishnu.

Pull out everything but the ifs, thens and fis.

It goes like this:
if
else
fi
else
fi

You are closing the first "if", then telling it "else".

It looks like you want to make sure the results file updated OK.
Try replacing:
"fi
else"
with:
"fi
if [ "$?" -ne "0" ]; then"

Post back with any more problems...

I was putting a \ in there for a carriage return. Should I have that put in a separate line?