Page 1 of 1

open the file in the project default directory and read

Posted: Mon Feb 19, 2007 4:50 am
by parvathi
Hi all,

I am reading a file which is in Project default location and try to concate tha values.

Please see the code that i have used. correct where ever it is wrong

Code: Select all

OPEN "","JobRunInfoParms" TO v_connectionParamsDataFile 
    ON ERROR Call DSLogWarn('Failed to open file JobRunInfoParms. Error':STATUS(), c_routineName ); Return
    ELSE Call DSLogWarn('Failed to open file JobRunInfoParms. Error':STATUS(), c_routineName ); Return

openseq v_connectionParamsDataFile To ParamFileVar 
   On Error 
       Call DSLogWarn('Error opening parameters file': Status(), c_routineName ); Return
 
  Else  Call DSLogWarn('Cannot open parameters file': Status(), c_routineName) ; Return

End


Loop 
      While ReadSeq Line From ParamFileVar 
      Result := Line
      Exit
      End
Repeat
CloseSeq ParamFileVar 
is this code correct?[/code]

Posted: Mon Feb 19, 2007 5:04 am
by parvathi
when i run this code in the routine i get the following error message

Compiling: Source = 'DSU_BP/DSU.ReadParamsFile', Object = 'DSU_BP.O/DSU.ReadParamsFile'
?
0005 ON ERROR Call DSLogWarn('Failed to open file DSParams. Error':STATUS(), c_routineName ); Return

^
WARNING: no RETURN value specified, null used.

0006 ELSE Call DSLogWarn('Failed to open file DSParams. Error':STATUS(), c_routineName ); Return

^
WARNING: no RETURN value specified, null used.

0010 Call DSLogWarn('Error opening parameters file': Status(), c_routineName ); Return

^
WARNING: no RETURN value specified, null used.

^
"ELSE" unexpected, Was expecting: ';', End of Line
0017 Loop

^
WARNING: Text found after final END statement


1 Errors detected, No Object Code Produced.

can anybody please help me on this

Posted: Mon Feb 19, 2007 5:44 am
by ArndW
You are in a function, so all of your RETURN statements need to look like RETURN({some value}). You also have an exit statement in your loop that would get executed after the 1st read, and an unbalanced END in there as well.

Posted: Mon Feb 19, 2007 7:23 am
by parvathi
Is code to open the sequential file and read it from the project default directry correct?

Posted: Mon Feb 19, 2007 8:04 am
by ArndW
No.
1. You are opening up a local hashed file called "JobRunInfoParms".
2. You then try to open a sequential file, but instead of the giving path you are using the file handle from (1). This cannot work. The file is a hashed file or a sequential one, but not both.
3. Assuming you are reading the sequential file, you need to remove your "exit" and superfluous "end" statements.



Loop
While ReadSeq Line From ParamFileVar
Result := Line
Exit
End
Repeat
CloseSeq ParamFileVar

Posted: Mon Feb 19, 2007 2:14 pm
by ray.wurlod
Note also that the Else clause can be taken in an OpenSeq statement even though the file is open for writing. This indicates that the file does not yet exist; the successful open is indicated by Status() returning 0.

Search the forum for OpenSequentialFile which illustrates all the possibilities when opening a file for sequential access.

Please post a specification (in English, not in code) for what you want this routine to achieve. Without that it's impossible to fulfil your original request to indicate whether your code is correct.

Where do you intend to use this routine? If it's per-row in a job, do you really want the overhead of opening and closing the file each time? There is a better solution in this case, but we need to know exactly what you want to accomplish.

Posted: Mon Feb 19, 2007 10:17 pm
by parvathi
ArndW wrote:No.
1. You are opening up a local hashed file called "JobRunInfoParms".
2. You then try to open a sequential file,
Can any other file be opened from the loca as open a hashed file?

The only thing i want to do I am able to open a hashed file from local ?
similarly can i open any ther file like DSParams or anything and read the contents from it?

Posted: Tue Feb 20, 2007 12:23 am
by ray.wurlod
We still have no idea what you are trying to accomplish, so it's very difficult to give well-directed advice.
  • Open is for hashed files or directories with a pointer in the VOC file.

    OpenPath is for hashed files or directories generally.

    OpenSeq is for operating system files opened for sequential access.
Warning: once you can open things, you can do damage.