devxlogo

Max file size PB can open

Max file size PB can open

Question:
I need to develop a program interfaced with a Sybase database. First I have to open a huge ASCII file (size ranges from 20 to 100 MB) to read and convert it to a preformatted ASCII file for the database.

Can PB open such a large ASCII file if my PC has 32 MB of memory? If so, how?

Answer:
The size of the file makes no difference to PowerBuilder, because it reads only 32K chunks at a time. Obviously if you read the whole file in 32Kchunks and tried to store them in memory as one continuous block, you’dhave problems.

Assuming your data has some kind of structure to it, you can read thedata in 32K chunks and process as much of the first chunk as possible,then append the next chunk to the end of what’s left of the chunk, andcontinue until you process the whole file.

The following code will read a large file into a blob variable. I suggest that instead of concatenating the chunks into the blob, youperform only the processing you need to do.

integer fnum, loops, ilong flen, bytes_read, new_posblob b, tot_b// Set a wait cursorSetPointer(HourGlass!)// Get the file length, and open the fileflen = FileLength(sle_filename.Text)fnum = FileOpen(sle_filename.Text,  &	StreamMode!, Read!, LockRead!)// Determine how many times to call FileRead IF flen > 32765 THEN   IF Mod(flen, 32765) = 0 THEN      loops = flen/32765   ELSE      loops = (flen/32765) + 1   END IFELSE   loops = 1END IF// Read the filenew_pos = 1FOR i = 1 to loops   bytes_read = FileRead(fnum, b)   // Here you perform your processing on the current chunk   tot_b = tot_b + bNEXTFileClose(fnum)
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist