Aligning numeric values on left with WRITE

Viewed 851

I'm creating a calculation table and want to align the numbers on the left under the '+'.

But somehow the first number in each column from the counter has some space before it.

How can I eliminate that space and align my table so that the left side is all in one row?

enter image description here

Code:

DATA: counter  TYPE i,
      counter2 TYPE i.

ULINE /(159).
WRITE: /1 sy-vline , '+', sy-vline.

DO 11 TIMES.
  counter = sy-index - 1 .
  WRITE:  counter, sy-vline.
ENDDO.

ULINE /(159).

DO 11 TIMES.
  counter = sy-index - 1 .
  WRITE: /1 sy-vline , counter ,  sy-vline.
  ULINE /(159).
ENDDO.
1 Answers

The spaces in front of the number are there because of the data type. Type i is an elementary data type and can have numbers from -2147483648 to 2147483647, which means it can be 11 characters long. Some data types have an output length that is variable, but that is not the case for i. You can see that if you click on it in your output, it should have a red outline 11 characters long.

But if you would rather have the spaces at the end of the number, then you can use 'CONVERSION_EXIT_ALPHA_OUTPUT'. But the "table outline" will still have to be just as big, since the number can have 11 characters.

DATA: counterc TYPE c LENGTH 11.

...

MOVE counter TO counterc.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input  = counterc
  IMPORTING
    output = counterc.

...

WRITE: ... counterc ...

Alternatively, the output of a table looks way better if you use SALV. Look here for example, to see how to output a table using SALV.

Related