Search code examples
mainframepl-i

PL/I & not printing on tab stop


I have the following PL/I code:

    declare 1 u union,
      2 c character(1),
      2 ci fixed binary(4) unsigned;

    ci = data_mem(data_ptr);
    put list (c);

What this does, is it takes an integer and outputs that as if it was an ascii/ebcdic value. So it shows characters. Sofar this works. The problem now is that each character is printed at an 24 spaces interval, as if 3 TABs are inserted. I tried converting c to a string first and then applying trim() but that did not help.

Any ideas?


Solution

  • This is the default PUT LIST behavior for a PRINT-attribute file. From the IBM Enterprise PL/I for z/OS Language Reference, under Stream-oriented Data Transmission -> LIST -> PUT list-directed (emphasis mine):

    The values of the data-list items are converted to character representations (except for graphics) and transmitted to the data stream. A blank separates successive data values transmitted. For PRINT files, items are separated according to program tab settings (see “PRINT attribute”).

    The next manual section discusses the PRINT attribute. Here we have

    Data values transmitted by list- and data-directed data transmission are automatically aligned on the left margin and on implementation-defined preset tab positions.

    Since you omitted FILE, your PUT is going to the default FILE(SYSPRINT). SYSPRINT is defined implicitly as FILE ENVIRONMENT(F RECSIZE(121)) OUTPUT PRINT STREAM (see Input and Output -> FILE Attribute -> File constant in the Language Reference, and Defining and Using Consecutive Data Sets -> Using PRINT files with stream I/O in the Programmer's Guide). IIRC, the defaults are every 24, which gives 5 tabs per line, compatible with the old 120-byte printers common in the early days of PL/I F in the late 1960s. This is modifiable by declaring a PLITABS structure (described in the previously mentioned manual section).

    LIST- and DATA-directed I/O are intended to be quick & dirty I/O interfaces with little regard for formatting on output (but are very forgiving on input). EDIT is better for formatting output, but it does show a lot of its FORTRAN roots for input and output. Personally, for traditional reports using formatted output, and for record input, I would work with record I/O, which is analogous to standard COBOL I/O.