HP 3000 Manuals

FORMATTED OUTPUT [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

FORMATTED OUTPUT 

This section explains the format specifiers available to produce
formatted output.  These are available with the DISP USING, PRINT USING,
and IMAGE Statements.  The DISP USING and PRINT USING statements are
formatted output statements; they specify the output format to be used in
printing data.  A DISP USING or PRINT USING statement can specify output
to format directly in a format string or indirectly by referencing an
image statement.

The format string or IMAGE statement describes the output format exactly,
specifying the following:

 *  Type of output.
 *  Spacing.
 *  Position of the following, if appropriate:
     *  Plus or minus signs.
     *  Radix indicators.
     *  Exponents.
     *  Dollar signs.
     *  Blanks.
     *  Control characters.

Format String 

The format string specifies the output format for the output items in the
display list of a DISP USING or PRINT USING statement.  It is also used
in an IMAGE statement.

Syntax 

format_string 

Parameters 

format_string    format_string (if it belongs to an IMAGE statement) or
                 its value (if format_string itself is the image of a
                 PRINT or DISP statement) has the following syntax:

                 format_spec [, format_spec]...

                 [num_expr] (format_spec[, format_spec]...)

format_spec      One of the format specifiers described in "Format
                 Specifiers" in the following section.

num_expr         Repeat factor.  Rounded to a short integer, n.  The
                 format_string n(format_spec_list) is equivalent to n 
                 adjacent copies of format_spec_list (see examples).

Examples 

The format strings of lines 100 and 200 are equivalent.  In line 200,
three is the repeat factor represented by num_expr, above.

     100 DISP USING "DDD,XX,DDD,XX,DDD,XX"; A,B,C
     200 PRINT USING "3 (DDD,XX)"; A,B,C
     300 DISP USING "DDDDD,XX,ZZZ.DD"; P,Q

Format Specifiers 

The format_spec in a format string or IMAGE statement is one of the
specifiers listed in Table 6-11.  Each numeric, nonliteral string, or
compact specifier corresponds to one output item in the display list of a
DISP USING or PRINT USING statement.  A space, dollar, control character,
or literal string specifier does not correspond to an item in the display
list.  Instead, it directs the DISP USING or PRINT USING statement to
print or suppress characters.

Table 6-11 lists the format specifiers, tells what they specify and how
they are symbolized, and whether they can contain repeat factors.

          Table 6-11.  Format Specifiers 

-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
|       Specifier       |       Specifies       |     Symbolized by     |  Can Contain Repeat   |
|                       |                       |                       |        Factor         |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| Numeric               | One numeric output    | D,Z,*,.,R,S, M,C,P,E  | Yes                   |
|                       | item.                 |                       |                       |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| String literal        | That the literal be   | Quoted string         | No                    |
|                       | printed exactly.      | literal.              |                       |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| String                | One string output     | A                     | Yes                   |
|                       | item.                 |                       |                       |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| Compact               | One numeric or string | K                     | No                    |
|                       | output item.          |                       |                       |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| Space                 | One or more spaces.   | X                     | Yes                   |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| Dollar                | Dollar sign.          | $                     | Yes                   |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| Control Character     | That control          | #,+,-,@,/             | No                    |
|                       | characters be printed |                       |                       |
|                       | or suppressed.        |                       |                       |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------

Starting with the leftmost output item in the display list and starting
at the beginning of the format string or IMAGE statement, HP Business
BASIC/XL matches each output item to the next numeric, nonliteral string,
or compact specifier.  For example, in the statement

     100 DISP USING "2X,DD,3X,5A"; 12,"HELLO"

2X and 3X are space specifiers, the numeric specifier DD corresponds to
the value 12 and the string specifier 5A corresponds to the value
"HELLO".

If the specifiers outnumber the output items, HP Business BASIC/XL
ignores the extra specifiers.  For example, in the sequence

     200 PRINT USING 210; A,B
     210 IMAGE Z,X,D,2X,ZZ,3X,DD

the numeric specifier Z corresponds to the variable A, X is a space
specifier, the numeric specifier B corresponds to the variable B, and the
specifiers 2X,ZZ,3X, and DD are ignored.

If the output items outnumber the specifiers, HP Business BASIC/XL reuses
the format string or IMAGE statement.  For example, in the statement

     300 DISP USING "5A,X,2D,X"; "HELLO",12,"HOWDY",34

the string specifier 5A corresponds to "HELLO" and "HOWDY" and the
numeric specifier 2D corresponds to 12 and 34.

An error occurs if a numeric specifier corresponds to a string value or
if a string specifier corresponds to a numeric value.  For example, the
statement

     400 PRINT USING "DDZ.DD"; "GOOD-BYE!"

causes an error, since DDZ.DD is a numeric specifier and "GOOD-BYE!"is a
string.

Numeric Specifiers 

A numeric specifier specifies the output format for a numeric value.  It
can contain digit symbols, radix symbols, sign symbols, digit-separator
symbols, an exponent symbol, and repeat factors (numeric expressions).
Each symbol represents one printed character.

Syntax 

              fraction_part 
             [                 ]
integer_part [{E fraction_part}]
             [{fraction_part E}]

Parameters 

                       {{D} }
                 [S]   {{Z} }
integer_part     [M][n]{{*} }
                       {{C} }
                       {K...}

                 {.}            [S]
fraction_part    {R}[[n]D[D]...][M][n]D[D]...

n                Repeat factor; a numeric expression.  The symbol that
                 follows it is repeated n times; for example, 5D is
                 equivalent to DDDDD.

See the sections "Digit Symbols" and "Digit-Separator Symbols" for
restrictions on combinations of the symbols D, Z, *, C, and P that the
above syntax specifiers do not reflect.

Table 6-12 summarizes the types of symbols that a numeric specifier can
contain, what each type specifies, and the individual symbols of each
type and their differences.

          Table 6-12.  Numeric Specifier Symbols 

--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
|  Symbol  |    Symbol Type    |     A symbol of this type      |   This symbol specifies that   |
|          |                   |           specifies            |                                |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
| D        | Digit             | One digit position.            | Each leading zero is replaced  |
|          |                   |                                | with a blank.                  |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
| Z        | Digit             | One digit position.            | Leading zeros are printed.     |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
| *        | Digit             | One digit position.            | Each leading zero is replaced  |
|          |                   |                                | with an asterisk (*).          |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
| .        | Radix             | Position of radix; which       | Radix is a period (.).         |
|          |                   | separates integer and          |                                |
|          |                   | fractional parts of a number.  |                                |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
| R        | Radix             | Position of radix.             | Radix is a comma (,).          |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
| S        | Sign              | Position of sign symbol (+ or  | + is printed if number is      |
|          |                   | -).                            | positive; - is printed if      |
|          |                   |                                | number is negative.            |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
| M        | Sign              | Position of sign symbol.       | Blank is printed if number is  |
|          |                   |                                | positive; - is printed if      |
|          |                   |                                | number is negative.            |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
| C        | Digit-separator   | Position of digit-separator    | Digit-separator is comma (U.S. |
|          |                   | symbol (comma or period) that  | notation).                     |
|          |                   | separates groups of digits (as |                                |
|          |                   | in 1,000,000).                 |                                |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
| P        | Digit-separator   | Position of digit-separator    | Digit-separator is period      |
|          |                   | symbol.                        | (European notation).           |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------
|          |                   |                                |                                |
| E        | Exponent          | Scientific notation and the    | Not applicable.                |
|          |                   | position of the symbol E in    |                                |
|          |                   | that notation.                 |                                |
|          |                   |                                |                                |
--------------------------------------------------------------------------------------------------

Digit Symbols.  Each of the three digit symbols, D,Z, and *, specifies
one digit position.  The DISP USING or PRINT USING statement prints one
digit of the output value for each digit symbol in the format specifier.

The digit symbols vary in that:

D                Replaces each leading zero with a blank (" ").

Z                Prints leading zeros.

*                Replaces each leading zero with an asterisk (*).

A repeat factor can precede a digit symbol.

Examples 

     20 DISP USING 50; 5,5,5
     30 DISP USING 60; 25,367,5448
     40 DISP USING 60; 12345,12345,12345
     50 IMAGE ZZZZZ,XX,DDDDD,XX,*****
     60 IMAGE 5Z,2X,5D,2X,5*
     99 END

The above program prints:

     00005      5  ****5
     00025    367  *5448
     12345  12345  12345

Lines 50 and 60 are equivalent (line 60 uses repeat factors).  Each of
the specifiers XX and 2X specifies two spaces (see "Edit Specifiers",
later in this chapter, for more information).  Notice that the specifiers
5Z, 5D, and 5* output a five-digit value the same way (because the value
has no leading zeros).

The digits in the integer part of a number can be represented by any
digit symbol; however, all of the digits must be represented by the same
digit symbol, with one exception.  The digit in the one's place can be
represented by Z, regardless of the symbol that represents the other
digits.  For example, DDD.DD, ZZZ.DD, ***.DD, DDZ.DD, and **Z.DD are
legal.  DZD.DD, Z**.DD, and *DZ.DD are illegal.  Each digit in the
fractional part of a number must be represented by D.

Examples 

     100 A=123.45
     110 B=67.8
     120 C=90
     130 D=0.2
     140 E=0.76
     150 PRINT USING 200; A,A,A,A,A
     160 PRINT USING 200; B,B,B,B,B
     170 PRINT USING 200; C,C,C,C,C
     180 PRINT USING 200; D,D,D,D,D
     190 PRINT USING 200; E,E,E,E,E
     200 IMAGE DDD.DD,2X, ZZZ.DD,2X, ***.DD,2X, DDZ.DD,2X, **Z.DD
     999 END

The above program prints:

     123.45  123.45  123.45  123.45  123.45
      67.80  067.80  *67.80   67.80  *67.80
      90.00  090.00  *90.00   90.00  *90.00
        .20  000.20  ***.20    0.20  **0.20
        .76  000.76  ***.76    0.76  **0.76

If a numeric output format specifies x digits to the right of the radix,
and the output value is precise to more than x digits, the DISP USING or
PRINT USING statement prints the output value, rounded to x decimal
places.  Rounding the output does not actually change the value.

If a numeric output format specifies x digits to the right of the radix,
and the output value is precise to fewer than x digits, the DISP USING or
PRINT USING statement prints zeros in place of the missing digits.

Examples 

     100 X=1.2938
     110 Y=3.7465
     120 Z=4.99
     130 DISP USING 160; X,X,X,X
     140 DISP USING 160; Y,Y,Y,Y
     150 DISP USING 160; Z,Z,Z,Z
     160 IMAGE D.DDDD,2X, D.DDD,2X, D.DD,2X, D.D
     170 DISP USING "D.DDDD,2X,D.DDDD,2X,D.DD"; X,Y,Z
     999 END

The above program prints:

     1.2938  1.294  1.29  1.3
     3.7465  3.747  3.75  4.0
     4.9900  4.990  4.99  5.0
     1.2938  3.7465  4.99

Radix Symbols.  The radix symbols, (period (.)  and R), specify the
character that separates the integer and fractional parts of a number.
It can be either a decimal point or a comma.  In a numeric specifier, a
period (.)  specifies a decimal point and an R specifies a comma.  A
numeric specifier can have at most one radix symbol.

Examples 

     DISP USING "DD.DD,2X,DDRDD"; 12.34, 12.34

The above statement prints:

     12.34 12,34

Sign Symbols.  The sign symbols, (S and M), specify the sign character.
A numeric specifier can have at most one sign symbol.

The sign symbols vary in that:

S       Prints a plus (+) if the output value is positive, and a minus
        (-) if it is negative.

M       Prints a blank if the output value is positive, and a minus if it
        is negative.

Examples 

     100 IMAGE SDD,2X,SDD
     200 IMAGE MDD,2X,MDD
     300 DISP USING 100; 10,-10
     400 DISP USING 200; 10,-10
     999 END

The above program prints:

     +10  -10
      10  -10

The sign can be printed between digits.

Examples 

     650 PRINT USING "2(DSD,2X,DMD,2X)"; -12,-34,56,78

The above statement prints:

     1-2  3-4  5+6  7 8

Digit-Separator Symbols.  The digit-separator symbols, (C and P), specify
the character that separates groups of digits as the commas do in
"1,000,000".  The symbol C specifies a comma; the symbol P, a period.

Before printing a digit-separator symbol, the DISP USING or PRINT USING
statement prints at least one digit of the output value.  That digit can
be a leading zero, if leading zeros are printed.

Examples 

     100 W=1234567
     110 X=800342
     120 Y=1234
     130 Z=150
     140 PRINT USING 300; W,W,W
     150 PRINT USING 400; W,W,W
     160 PRINT USING 300; X,X,X
     170 PRINT USING 400; X,X,X
     180 PRINT USING 300; Y,Y,Y
     190 PRINT USING 400; Y,Y,Y
     200 PRINT USING 300; Z,Z,Z
     210 PRINT USING 400; Z,Z,Z
     300 IMAGE 7Z,2X,ZC3ZC3Z,2X,ZP3ZP3Z
     400 IMAGE 7D,2X,DC3DC3D,2X,DP3DP3D
     500 PRINT USING "DCDDD.DD,2X,DCDDDPZZ"; 123456,123456
     600 PRINT USING "DDCDDCDD"; 123456
     999 END

The above program prints:

     1234567  1,234,567  1.234.567
     1234567  1,234,567  1.234.567
     0800342  0,800,342  0.800.342
      800342    800,342    800.342
     0001234  0,001,234  0.001.234
        1234      1,234      1.234
     0000150  0,000,150  0.000.150
         150        150        150
     1,234.56  1,234.56
     12,34,56

Exponent Symbol.  The exponent symbol, E, specifies scientific notation.
A numeric specifier must have at least one digit symbol before the symbol
E. The DISP USING or PRINT USING statement prints the output value in the
format

{+}                                   {+}
{-} digit[digit...][.digit[digit...]]E{-} digit digit 

The exponent symbol can precede or follow the fractional part of the
numeric specifier.  The numeric specifier must contain a sign symbol if
the output value is negative.

Examples 

     100 N=123.45
     110 DISP USING "D.DDDE"; N    !1.235E+02 (rounded)
     120 DISP USING "DDDDD.E"; N   !12345.E-02
     130 DISP USING "3D.2DE"; -N   !Overflow error
     140 DISP USING "S3D.2DE"; -N  !-123.45E+00
     999 END

String Specifiers 

A string specifier specifies the output format for a string value.  The
specifier can be nonliteral or literal.  A nonliteral string specifier
contains the symbol A, which can be preceded by a repeat factor (numeric
expression).  A literal string specifier is a quoted literal.

Syntax 

Nonliteral string specifier:

[num_expr]A

Literal string specifier:

str_lit 

Parameters 

num_expr         Repeat factor.  Its value is the length of the output
                 string.  If this is not specified, the default is one.

str_lit          Literal string specifier.  It must be enclosed in quotes
                 and it can only appear in an IMAGE statement (not in a
                 format string).  It does not correspond to an item in
                 the display list; the DISP USING or PRINT USING
                 statement prints str_lit itself.

A nonliteral string specifier specifies the output format for a string
value in the display list.  It can appear in either an IMAGE statement or
a format string.

Examples 

Legal: 

     500 PRINT USING 310
     510 IMAGE 30X,"Title"

Illegal: 

     600 PRINT USING "30X,"Title""

If num_expr has the value n and the corresponding output item is a string
of length s, then:

If               DISP USING or PRINT USING statement prints 

n=s              Entire string

n<s              First n characters of the string

n>s              Entire string, followed by n-s blanks

Examples 

      99 S$="GOODBYE"
     100 DISP USING "7A"; S$     !Format length = output string length.
     110 DISP USING "4A"; S$     !Format length < output string length.
     120 DISP USING "8A"; S$     !Format length > output string length.
     130 DISP USING 140; S$
     140 IMAGE 7A,"TO YOU"       !image contains literal.
     150 DISP USING "4AX3A"; S$  !Insert blank in printed string.

Where "Å" represents a blank, the above program prints:

     GOODBYE
     GOOD
     GOODBYEÅ 
     GOODBYETO YOU
     GOOD BYE

Standard Format Specifier 

A standard format specifier represents one string or numeric value of any
size.  It consists of one symbol, K. If K represents a string value, the
DISP USING or PRINT USING statement prints the entire string.  If K
represents a numeric value, the statement prints the value in the
standard format, without leading or trailing blanks.

Syntax 

K

Examples 

      10 X=123
      20 Y=.4567
      30 Z=-1.234E+47
      40 A$="cat"
      50 B$="bird"
     100 PRINT USING "K"; X
     110 PRINT USING "K"; Y
     120 PRINT USING "K"; Z
     130 PRINT USING "K,K,K"; X,Y,Z
     140 PRINT USING "K"; A$
     150 PRINT USING "K,K"; A$,B$
     160 PRINT USING "K,K,K,K,K"; X,A$,Y,B$,Z
     999 END

The above program prints:

     123
     .4567
     -1.234E+47
     123.4567-1.234E+47
     cat
     catbird
     123cat.4567bird-1.234E+47

Space Specifiers 

A space specifier specifies one or more spaces.

Syntax 

[num_expr1]X[X]...

Parameters 

num_expr1        Repeat factor.  Its value is rounded to a short integer.

The specifier nX is equivalent to a sequence of nX symbols.  The DISP
USING or PRINT USING statement prints one space for every X.

Examples 

     110 DISP USING "3D,XXX,3D,XXX,3D"; 123,456,789
     120 DISP USING "3D,3X,3D,3X,3D"; 123,456,789
     999 END

The above program prints:

     123   456   789
     123   456   789

Dollar Specifier 

A dollar specifier specifies a dollar sign ($) and consists of one
symbol, $.  When the symbol $ precedes a numeric specifier, the DISP
USING or PRINT USING statement prints a dollar sign ($) before printing
the value that corresponds to the numeric specifier.  The statement
prints the dollar sign immediately before the first printed digit of the
output value.

Syntax 

$

Examples 

     10 A=1234
     20 DISP USING "$DCDDD.DD"; A
     30 DISP USING "$DDDCDDD.DD"; A
     40 DISP USING "$DDDCDDZ.DD"; A
     50 DISP USING "$ZZZCZZZ.DD"; A
     99 END

The above program prints:

     $1,234.00
     $  1,234.00
     $  1,234.00
     $1,234.00
     $001,234.00

Control Character Specifiers 

A control character specifier specifies that one or more control
characters for carriage return, line feed, or form feed be printed or
suppressed.  It consists of one symbol:  #, +, -, @, or /.

Table 6-13 lists the control character specifiers, their positions in the
image, (the item that is output) and their effect on the DISP USING or
PRINT USING statement.

          Table 6-13.  Control Character Specifiers 

-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
|     Specifier     |         Position in Image          |          Effect on Output          |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| #                 | First format_spec                  | Suppresses carriage return and     |
|                   |                                    | line feed that would otherwise be  |
|                   |                                    | printed after display list values. |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| +                 | First format_spec                  | Suppresses line feed that would    |
|                   |                                    | otherwise be printed after display |
|                   |                                    | list values.                       |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| -                 | First format_spec                  | Suppresses carriage return that    |
|                   |                                    | would otherwise be printed after   |
|                   |                                    | display list values.               |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| @                 | Any format_spec.  Can also replace | Prints formfeed.                   |
|                   | comma.                             |                                    |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| /                 | Any format_spec.  Can also replace | Formfeed followed by line feed.    |
|                   | comma except that two @s must be   |                                    |
|                   | separated by a comma.              |                                    |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------

Examples 

     10 A$="ABC"
     20 DISP USING "3A"; A$
     30 DISP USING "K"; "xyz"
     40 DISP USING "#,3A"; A$  !Suppress carriage return & line feed
     50 DISP USING "K"; "xyz"
     60 DISP USING "-,3A"; A$  !Suppress carriage return only
     70 DISP USING "K"; "xyz"
     99 END

The above program prints:

     ABC
     xyz
     ABCxyz
     ABC
        xyz

The sequence:

     100 DISP USING "+,3A"; A$
     110 DISP USING "K"; "xyz"

prints ABC, followed by a carriage return character but not a line feed
character.  When the output file is printed on a line printer, xyz is
printed over ABC.

The statement:

     200 DISP USING "DD,@,DD@DD@,@DD"; 12,13,14,15

prints 12, a form feed character, 13, a form feed character, 14, two form
feed characters, 15.  When the output file is printed on a line printer,
12 is printed on the current page, 13 on the next page, 14 on the next,
and 15 two pages after 14.

The statement:

     300 DISP USING "Z,/,ZZ/ZZZ//ZZZZ/,//ZZZZZ"; 1,2,3,4,5

prints:

        1
        02
        003

        0004

        00005



MPE/iX 5.0 Documentation