Files (plain text) 
Author Message
 Files (plain text)

How do I use files (plain text) in PL/I?

If possible please sendme a souce code.

Sat, 06 Nov 1999 03:00:00 GMT  
 Files (plain text)

On Tuesday, 97/05/20, "Alejandro Acosta A." wrote to All about "Files
(plain text)" as follows:

A> How do I use files (plain text) in PL/I?

On which platform?

Plain text files mean different things on different systems.

I shall assume you are using OS/2 or Windows NT and you mean files
whose records are terminated by CR/LF. [This might also be valid for
X-platform systems and their LF-delimited files. I don't know.] The
following run of code is roughly what is needed to read through a file
containing text records of up to 1024 bytes (plus CR/LF) each.

   DCL  Input_rec      CHAR(1024) VAR,
        Input_file     FILE RECORD INPUT INT;

   ON ENDFILE(Input_file)
      GO TO End_of_file;

      READ FILE(Input_file) INTO(Input_rec);
      /* Process input record */

   CLOSE FILE(Input_file);

If you are using an IBM mainframe then the TITLE() options will be a
little different. In fact, you specify just the DDNAME in quotes under
OS/390 (MVS/ESA, MVS/XA, etc., etc.), but each record will passed
through as characters even if it holds binary or packed decimal stuff.
A more specific question is needed to cover the details.

If you want to convert text input into computational forms, such as
packed decimal or binary, then STREAM transmission might be more

   DCL  (Height,Radius,Volume) BIN FLOAT(53),
        Pi             BIN FLOAT(53)
        Input_file     FILE RECORD INPUT INT,
        SYSPRINT       PRINT;

   ON ENDFILE(Input_file)
      GO TO End_of_file;

      /* Read height and radius */
      GET FILE(Input_file) LIST(Height,Radius);
      /* Calculate volume */
      Volume = Height*Pi*Radius*Radius;
      /* Print results */
      ('Height = ',Height,'Radius = ',Radius,'Volume = ',Volume)

   CLOSE FILE(Input_file),
 END Cylinder;

The above program might even compile and run (but not on a
mainframe!), although I typed it directly into my mail reader so allow
for typos.

The I/O facilities of PL/I are huge, and you are just scratching the


<Team PL/I>

 * KWQ/2 1.2i * "Aim low boys! They're a-ridin' Shetlands!"
Please remove the '$' in the from line before reply via email.
Anti-UCE filter in operation.

Sat, 06 Nov 1999 03:00:00 GMT  
 Files (plain text)

Declare the file to be STREAM and use

            READ FILE (<filename>) INTO <char varying string>;

The LENGTH function will then know the length of the line just read, and
you can parse the works from the text line using INDEX and SUBSTR.

        TOKEN = SUBSTR (LINE, 1, INDEX (LINE ,' ')-1);

for example will set TOKEN to the first word in the line. Stream I/O
(GET and PUT) doesn't work for this, because GET is looking for quoted
strings, not lines of text. In the above example, TOKEN and LINE are
both CHAR(<max length>) VARYING strings. To complete the example, dispose
of the first word by doing:

        LINE = SUBSTR (LINE, INDEX (LINE, ' ')+1);

This assigns everything AFTER the first blank back to LINE, so the next
token can be isolated.
Jay McFadyen
Development Tools and Infrastructure, C2PSD, Ford Motor Company

(313) 33-73359

Sat, 06 Nov 1999 03:00:00 GMT  
 [ 3 post ] 

 Relevant Pages 

1. Printing Plain Text Files

2. Reading plain text file database tables

3. GUI for manipulation of plain text input files

4. APL2001 (plain text version)

5. convert plain text into HTML CDATA - spaces

6. convert plain text into HTML CDATA

7. plain text to/from HTML CDATA

8. Comments, Please: a script to parse plain text lyrics to HTML

9. awk scrips parsing html-table to plain text

10. printing plain text

11. RTF (get plain Text)

12. Help! ( Off topic ) - plain text


Powered by phpBB® Forum Software