Open a File for Reading Using SQR

Your rating: None Average: 2.6 (11 votes)

Here is some SQR code that will open a file for reading:

Begin-Procedure Open-File
#debug show 'Entering Open-File'
!file name and where it is located.
Let $new_file = $PATHNAME || 'your_file_name.txt'
Show '$new_file = ' $new_file
!check if the filel exists before trying to open it
Let #estatus = exists($new_file)
If #estatus = 0
Show 'Log File ' $new_file ' exists. Will be opened for reading.'
!opening file for reading
Open $new_file As 1 For-Reading Record=3000
Status=#FileStat
!couldn't open file if #FileStat is not zero
If #FileStat != 0
Move 'N' To $file_open
Show 'Error Opening Input File' $new_file
Show 'Program Terminating.'
Let $errmsg = 'Error Opening Input File' || $new_file
Move $errmsg to $prcs_message_parm1
Let #Prcs_Run_Status = #prcs_run_status_unsuccessful
Do Update-Prcs-Run-Status
Stop
Else
Move 'Y' To $file_open
Show 'File ' $new_file ' opened successfully.'
!you normally want to read the file once you opened it.
!So, I'm calling Read-Input-File procedure to do
!just that.
Do Read-Input-File
End-If
Else
Show 'File ' $new_file ' does not exist. Can not open file for reading.'
Let $errmsg = 'Error Opening Input File' || $new_file
Move $errmsg to $prcs_message_parm1
Let #Prcs_Run_Status = #prcs_run_status_unsuccessful
Do Update-Prcs-Run-Status
Stop
End-If
#debug show 'Leaving Open-File'
End-Procedure Open-File

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.
Guest's picture
Guest (not verified)
Can we change the font for single variable in sqr?

Hi
can we change the font for single variable in sqr?
thanks in advance,

Lepa's picture
User offline. Last seen 1 year 5 weeks ago. Offline
Joined: 06/23/2008
Posts: 591
Re: Can we change the font for single variable in sqr?

Yes you can, use the point-size after your print command as such:

print 'printing something ' (+2,1) point-size=8

Please start a forum topic if you need more assistance!

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Guest's picture
Guest (not verified)
Re: Open a File for Reading Using SQR

Hi,

Thanks for your code. I am having one problem:
My file exits and confirmed by
exists($new_file)

but when we try to open the file using :
Open $new_file As 1 For-Reading Record=3000

I get "access denied message"
Any clue? what's causing the problem

Thanks!
Saini

Lepa's picture
User offline. Last seen 1 year 5 weeks ago. Offline
Joined: 06/23/2008
Posts: 591
Re: Open a File for Reading Using SQR

Does the user id running the program has the right permission to access the file? Can you try setting the permission on the file to 777 and try again?

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Guest's picture
Guest
Re: Open a File for Reading Using SQR

What does that "record=3000" mean?
i read in the book that it is somehow related to record length. Is it so?