RPGLE and Empty File

I need to determine within my free-form code if a data file is empty or not. This is not in connection to the use of a sub-file.

Answer Wiki

Thanks. We'll let you know when a new response is added.

could you not use:

Open sFileName For Input As #1
if Len(sFileName)>0 then
‘ do something
‘ do something else
End if

sFileName should be full path of the file.

Discuss This Question: 5  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • PaulRyan
    Not sure if this is a LotusScript question but here goes. Try FileLen() rather than Len(), which returns the size of the file in bytes. Whereas Len() returns the length of a string in number of chars. e.g. Dim lngFileSize As Long lngFileSize = FileLen("Fully specified path/filename as a string") Paul
    0 pointsBadges:
  • Joepbeckeringh
    You could use a file information data structure, which contains the number of records in the open feedback part (position 156 - 159; check the manual for INFDS). Alternatively you could start with a read; if it is unsuccessful the file is empty.
    0 pointsBadges:
  • AdamVan
    Seems that the previous answers will work, but I would just do a setll and a read. If not %found....file's empty.
    0 pointsBadges:
  • Jklipa
    I like the setll and read solution, assuming it is a keyed file... If it is not keyed then you might try an external call to a CL pgm and use the RTVMBRD (Retrieve Member Description) command... This command returns several variables, one of which is NBRCURRCD (Current Number of Records) Another option using a CL would be to open the file and read it in a loop and count the number of reads until eof... If you just want to know if it is empty or not then you only need to do one successful read to know it is not empty. Another CL trick would be to attempt to copy the file to a QTEMP file... The operating system gives an error you can monitor for if you try to copy an empty file. Or you could use embedded SQL in an SQLRPGLE pgm and open the file and read it and if you get an eof condition on the first read then it is empty...
    0 pointsBadges:
  • TheaGoldsby
    Regarding the suggestion to use SetLL, Read(e), then check %Found: As of V5R2, the Read op code **DOES NOT** set %Found. You could SetLL (*LoVal), Read(e), then check %EOF. Or, more efficiently, just SetLL(e) (*LoVal), then check %Found.
    0 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: