Printing formatted data

print

Print formatted data

printh

Print formatted and aligned data


SYNTAX

print[h] item [ ,|; item] …

Print a line of formatted items. The printh command pads the print item to the size of the corresponding heading or data, whichever is larger.


Detailed syntax

print[h] item [ ,|; item] …

(where item is one of the following:)

1

field_id [: [format] [: flags]]

2

[field_id [: [format] [: flags]]]

3

*field_id [: [format] [: flags]]

4

[*field_id [: [format] [: flags]]]

5

expression [: [format] [: flags]]

6

[expression [: [format] [: flags]]]



Suppressing a print item

If an entire print object (item) is enclosed in square brackets [ ] (as in 2, 4, and 6 in the syntax examples above), the printing of the item is suppressed and an equivalent number of spaces are printed instead. This facilitates the alignment of continuation lines and total lines. If consecutive print objects are to be suppressed in this way, each must be enclosed in its own square bracket set - multiple items may not be enclosed in a single bracket set.


Printing a field heading

If a field_id is preceded by an asterisk *, as in syntax examples 3 and 4, the field heading is printed in place of the data. The field heading is specified as part of the field’s definition, defaulting to the field_id if omitted. It is often useful to print a line of field headings as part of the !heading statements, to serve as column headings for the associated data fields.


Format

A format may, optionally, be specified. It may be a constant or an expression.

Field

The format will be used in place of the field’s standard format, which can be specified in the field’s definition, defaulting to the standard format for the field type and size.

Field heading

Formats are never applied to field headings, and it is therefore not meaningful to supply one.

Expression

If no format is specified, a suitable default format for the value produced by the expression is used. Expressions involving fields do not inherit a field format.

EXAMPLES

print Sales.total: "####0.00"
print (sc_field1 * sc_field2): "00000.00"
print Stock.Alphadate:tmp.DateFormat

Flags

Optionally, a flag list may be provided. The flags may be a constant or an expression. They are separated from the format by a colon. If no format has been specified, two consecutive colons must precede the flags.

The flags which may be used are:

c

Centre within the print column width

s

Remove leading spaces when printing

t

Remove trailing spaces when printing

l

Fold to lower case

u

Fold to upper case

n

Align to the right (alphanumeric fields). Alpha fields are normally aligned to the left. This flag is especially appropriate when an alpha field contains numeric data, but can be used to right align any print value.

If the text in the field contains trailing spaces, the result will be a ragged right edge unless all values have the same number of trailing spaces. To move the trailing spaces to leading spaces, use the right() function. See Example 2 below.

Any other flags are ignored.

Field

Flags assigned in a print[h] command do not override any other flags specified in the field’s definition. Any such flags are still respected.

Field heading

Any of these flags may be applied to a field heading if required.

Expression

If no flags are specified, no flags are applied.

EXAMPLES

  1. Remove both leading and trailing spaces:

    print Inv.Comment: :"st"
    
  2. Move trailing spaces before aligning to the right:

    print right(Cust.Surname): :"n"
    

Note that if the flag string is a constant it must be enclosed in quotes, though this is not necessary when specifying flags in a !temp declaration. This is because expressions may be used when assigning flags in the print[h] command.

Formats and flags are fully documented under Data fields.


Spacing between items

Objects in a print list must be separated by either a comma or a semicolon. These two separators may be combined in a single print list.

The comma separator causes the program to refer to the Sculptor system variable sys.Gap and print this number of spaces. The default value for sys.Gap is 2. The spaces are converted to a tab position, in order to ensure correct alignment if a proportional font is being used.

The semicolon separator causes no spaces to be printed. The next item is printed immediately after the previous one.

The end of the print list generates a new line unless terminated by a comma or semicolon, in which case the appropriate number of spaces are printed before continuing with the next print item, on the same line.


The printh command

The printh command pads the print item with trailing spaces, to the size of the field heading or data, whichever is the larger. If the item is a field, printh allows for the size of the field heading if this is wider than the data. If the item is a field heading, printh allows for the width of the data value if this is wider than the heading. Any spaces printed are converted to a tab position, in order to ensure correct alignment if a proportional font is being used.

EXAMPLES

!temp Field1,"ALPHA FIELD", a3
!temp Field2, "NUMBER",u4,"#########0"
!temp Field3,"FIELD 3", a1

      print Field1, Field2, Field3

Three characters are printed for Field1, followed by a comma separator (sys.Gap, defaulting to two spaces); then Field2 is printed with the format specified; then the single character Field3 is printed.


print *Field1, *Field2, *Field3

Prints “ALPHA FIELD NUMBER FIELD3 ”. The headings are printed exactly as specified. This does not allow for the largest possible value of Field2, which may occupy 10 spaces.


printh Field1, Field2, Field3

Prints the value of Field1, padded with eight spaces to make up the width of this field’s heading (ALPHA FIELD). Then prints the value of Field2, with no padding because the data width is greater than the heading width. Then prints Field3, padded with 6 spaces to allow for the field heading.


printh *Field1, *Field2, *Field3

Prints “ALPHA FIELD NUMBER FIELD3”. This time the heading of Field2 is padded to allow for the maximum size of the field data.


NOTES

  • The print[h] command, used alone with no object list, prints a blank line. This is the equivalent of:

    print lns(1);
    


Field statistic and total functions

The following functions may be used to print statistics and totals for an individual field. They may also be used outside print[h] commands.

average()

Prints the current average value for the specified field.

max()

Prints the current maximum value for the specified field.

min()

Prints the current minimum value for the specified field.

total()

Prints the current total value for the specified field.

count()

Prints the current number of rows processed.

The function values are updated at the end of each cycle. If used in an !on ending section, they return values for that section only. They are therefore particularly useful for printing subtotals and other block analysis figures. Otherwise they return values for the whole of the report so far. Note that since the functions are updated at the end of a cycle, they do not include the record currently being processed if they are called during the main report logic.


Other useful functions

setfont()

Sets the current font in a report.

getprintxy()

Retrieves the current print position in device units. This and setprintxy() enable draw functions to be easily mixed with print[h] commands.

setprintxy()

Sets the current print position in device units.


RELATED TOPICS

Reports