Page 1 of 1

Very simple code...I thought

Posted: Fri Sep 19, 2003 8:41 am
by JDionne
I am trying to write a very simeple bit of code as follows
quote:
Harmitem = Arg1
Ans = ''
If Harmitem = '116' then Found = @True else Found = @False
If Found Then Ans = 'R'
End

when i compile the job i get the following errors
quote:
Compiling: Source = 'DSU_BP/DSU.JOCImportRedefinedReefer', Object = 'DSU_BP.O/DSU.JOCImportRedefinedReefer'

0007 RETURN(Ans)

^
WARNING: Text found after final END statement


Compilation Complete.


There isnt even any blank spaces after the end statment
what is wrong here?

Posted: Fri Sep 19, 2003 9:07 am
by mhester
Remove the END statement and it will compile. The END statment is confusing the compiler since this is a function.

Regards,

Michael Hester

Posted: Fri Sep 19, 2003 9:43 am
by JDionne
Thanx Worked like a charm
Jim

quote:Originally posted by mhester
[br]Remove the END statement and it will compile. The END statment is confusing the compiler since this is a function.

Regards,

Michael Hester

Posted: Fri Sep 19, 2003 8:19 pm
by ray.wurlod
IF, most of the I/O statements and a number of other statements can be in "single-line format" or "multi-line format". The rule that governs it can be stated as follows:

If the clause-introducing keyword (for example ON ERROR, LOCKED, THEN or ELSE) is the final word on the line in which it appears, then a corresponding END statement is mandatory.
If the clause-introducing keyword is not the final word on the line in which it appears, then a corresponding END statement is prohibited.

So your code could have been written as:
Harmitem = Arg1
Ans = ''
If Harmitem = '116' then Found = @True else Found = @False
If Found Then
Ans = 'R'
End
In this example, the first IF statement is in "single-line format" while the second IF statement is in "multi-line format" (even though there is only one statement controlled by the IF condition).
Your code could more efficiently have been written as:
Ans = (If Harmitem = "116" Then "R" Else "")


Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518