Page 1 of 1

Error Compiling the Routine

Posted: Tue Aug 23, 2005 4:20 pm
by pnchowdary
Hi Guys,

I wrote the following routine which takes Identifier1,Identifier2,Identifier3 values as input and compares them with the values that are already been stored in a sequential file using an earlier routine.

Code: Select all

Common /StoreVal/ Initialize,LastValue,SeqFile,Flag1,Flag2,Flag3 

Equate RoutineName To 'GetStoredValue' 

    Open "StoreFile" TO SeqFile Else 
* Open failed. Create the sequence file. 
         Ans='UNABLE TO OPEN FILE'
    End 

* Attempt to read the named record from the file. 
    Readu LastValue From SeqFile, Identifier1 Then
          If LastValue = 'N' Then
                 Flag1="YES"
              End
          Else
                 Flag1="NO"
              End                ; * End of first If Statement

    Readu LastValue From SeqFile, Identifier2 Then
          If LastValue = '0' Then
                 Flag2="YES"
              End 
          Else 
                 Flag2="NO"
              End                ; * End of Second If Statement


    Readu LastValue From SeqFile, Identifier3 Then
          If LastValue = '0' Then
                 Flag3="YES"
              End
          Else
                 Flag3="NO"
              End                ; * End of Third If Statement

    If (Flag1 = 'YES' And Flag2 = 'YES' And Flag3 = 'YES') Then   
                Ans="YES"
             End
    Else  
                Ans="NO"
             End                ; * End of Final If Statement                  

Close SeqFile 
End                             ; * End of the Routine
I am getting the below error while compiling this routine.

Code: Select all

Compiling: Source = 'DSU_BP/DSU.GetStoredValue', Object = 'DSU_BP.O/DSU.GetStoredValue'
****
0047    
        ^
End of File unexpected, Was expecting: Array Name, Variable name, 
New variable name, ';', Statement label, "ABORT", "ABORTE", "ABORTM", 
"BEGIN", "BREAK", "CALL", "CHAIN", "CLEAR", "CLEARCOM" etc....

1 Errors detected, No Object Code Produced.
I believe its a small syntax error, but I am not able to find it. Could someone help me please?

Posted: Tue Aug 23, 2005 5:36 pm
by ray.wurlod
Click on the Format button in your original code, so as to show "proper" indenting. You may have omitted an End statement for example. Indeed, each of your ReadU statements lacks an End statement to terminate the block of statements begun by the keyword THEN. Machine formatting will highlight this; the RETURN(Ans) statement should line up directly under the FUNCTION statement if everything is correct.

Some other observations.
  • You attempt to read records even if you fail to open the file. This may generate run-time errors. The Read statements need to be within the scope of the Open statement's THEN clause.

    Since you're not updating the file, you don't need ReadU. Either change these to Read, or make sure that you explicitly release the locks that you set.

    Variables Flag1, Flag2 and Flag3 are not set in your routine if the Read fails. If you're relying on the fact that they are declared to be in COMMON to have them initialized to 0, you ought to include a comment to this effect.

    You are opening and closing the file for every record processed. Much more efficient would be to open the file only if it is not already open (this will work because the file variable is in COMMON).

Posted: Wed Aug 24, 2005 7:57 am
by pnchowdary
Thank you very very much ray :D :D . Your reply was really very helpfull. It is now compiling properly. I also included all the changes that you mentioned in your observation. You really rock 8)