TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Murray Lesser
from: David Noon
date: 1996-07-24 21:59:08
subject: PL/I Problems 1/

On Tuesday, 96/07/23, David Noon wrote to Murray Lesser about "PL/I
Problems         1/" as follows:

DN> ML>How do I read an ASCII text file
DN>   >(produced, say, by a text editor) as a set of fixed-length records?
DN> record size, open it with TYPE(DDM) /* check the DDM attribute - I'm

Hi Murray,

Unless your datasets are on a mainframe that should be TYPE(FIXED),
not TYPE(DDM), above.

The above methods [FILEREAD() or READ] will allow you to process all
the CR and LF characters, since RECORD processing transmits pure
binary patterns between RAM and peripherals and doesn't elide the
CR/LF pairs, nor does it recognise them as record terminators when
TYPE(FIXED) is used instead of TYPE(TEXT) or TYPE(CRLF). So this really
reads the file as binary bytes in chunks of a fixed length. It's what
you asked for, but it mightn't be what you want.

After thinking further about the question, I speculated that
you really wanted to ask:

How does one read a text file and treat all records (really just lines
of text) as equal length?

One can do this very simply using STREAM processing. If we want every
record to be, say, 132 bytes long, even if the source line is shorter,
the following should achieve that:

    DCL  Input_rec     CHAR(132),
         Input_file    STREAM INPUT;
      .
      .
    OPEN FILE(Input_file) TITLE('.....');
    ON ENDFILE(Input_file) GO TO Thats_yer_lot;
      .
      .
    DO LOOP;
         GET FILE(Input_file) EDIT
         (Input_rec)
         (L);
         .
         .
         .
    END;
 Thats_yer_lot:
    CLOSE FILE(Input_file);

Any short records are widened to the length of Input_rec by adding
trailing blanks; any oversized ones are truncated unless you have the
STRINGSIZE condition enabled, so be careful.

Of course, if you want to do all the fiddly stuff with CR/LF pairs
exposed, refer to my previous reply with the correction noted at the
top of this one.

Regards

Dave


 * KWQ/2 1.2i * Windows NT: Vapourware of the desperate and scared.
--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4)
SEEN-BY: 50/99 270/101 620/243 625/100 711/401 409 410 413 430 808 809 934
SEEN-BY: 711/955 712/407 515 624 628 713/888 800/1
@PATH: 440/4 141/209 270/101 712/515 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.