COLUMN operator specifies the position of the value which follows this operator on the 4GL screen (DISPLAY) or in the report (PRINT).
When no form is open, width of a value displayed by PRINT and DISPLAY depends on its declared data type (unless the CLIPPED or USING keywords are used).
data type |
default display width (measured in characters) |
is specified in the variable declaration (e.g., |
|
10 |
|
between 2 and 25 depending on the variable declaration |
|
(2 + m) where m is the precision specified in the variable declaration |
|
14 |
|
11 |
|
between 3 and 25 depending on the variable declaration |
|
(3 + m) where m is the precision specified in the variable declaration |
|
14 |
|
6 |
|
maximum length specified in the variable declaration |
COLUMN allows a 4gl developer to control the location of items within a line in a REPORT program block or in a DISPLAY statement. It is especially useful when you need to output tabular data.
COLUMN operator has one operand. This is a right operand that can be an integer expression or
a literal integer:
LET pos = 10
PRINT COLUMN pos, "I start at column 10"
DISPLAY COLUMN 10, "I start at column 10"
The operand tells Lycia where to position a value relative to the left margin of the 4gl screen or the current 4gl report.
In reports, the operand cannot be greater than the arithmetic difference between the margins = (right margin – left margin) for explicitly specified or default values in the OUTPUT section of the REPORT definition.
If the printing position in the current line is already beyond the specified value of the operand, the COLUMN operator has no effect.
With DISPLAY statements, COLUMN specifies the distance between the first character of the displayed value and the first character position of the 4gl screen.
When you include the COLUMN operator in a DISPLAY statement, you must specify a literal integer as the left-offset, rather than an integer expression.
In this example program, strings are displayed with increasing indents:
MAIN
DEFINE pos INTEGER
DISPLAY "1234567890123456789012345678901234567890"
DISPLAY COLUMN 10, "I start at column 10"
LET pos = 20
DISPLAY COLUMN pos,"I start at column 20"
DISPLAY COLUMN 30, "I start at column 30"
CALL fgl_getkey()
END MAIN
When you use the PRINT statement in the FORMAT section of a report, items are printed out one after another and are separated by blank spaces.
COLUMN operator overrides this default positioning. It moves the current character position to the right on the current line of the report page.
The required position is calculated as a number of characters between the left side of the report page (excluding the left margin) and the current character position. If the left margin for the report is not specified in the OUTPUT section or in START REPORT, the required position is calculated starting from the left side of the page or screen.
The default position is this:
COLUMN 1
It means that the cursor is positioned at the first character of the current line.
The operand of the COLUMN operator cannot be greater than the total width of the report page (excluding the left margin width).
If the operand of the COLUMN operator is smaller than the current character position, this operator is ignored.
This example program produces an output similar to the DISPLAY output show above:
MAIN
START REPORT rep1 TO SCREEN
OUTPUT TO REPORT rep1()
FINISH REPORT rep1
END MAIN
REPORT rep1()
DEFINE
pos INTEGER
OUTPUT LEFT MARGIN 0
FORMAT
ON EVERY ROW
PRINT "1234567890123456789012345678901234567890"
PRINT "Start at column 1"
PRINT COLUMN 10, "Start at column 10"
LET pos = 20
PRINT COLUMN pos, "Start at column 20"
PRINT COLUMN 30, "Start at column 30"
LET pos = 40
PRINT COLUMN pos, "Start at column 40"
END REPORT
COLUMN operator can be sometimes confused with the SPACE operator. But if sometimes these two operators can produce the same effect, they are different:
Here COLUMN and SPACE will produce the same output:
PRINT 2 SPACE, "345", 1 SPACE, "78", 1 SPACE, "10"
PRINT COLUMN 2, "345", COLUMN 6, "78", COLUMN 9, "10"
But these outputs will be completely different:
PRINT 5 SPACE, "345", 5 SPACE, "78", 5 SPACE, "10"
PRINT COLUMN 2, "345", COLUMN 10, "78", COLUMN 25, "10"