1.
Later
overwriting positioning of SY-VLINE
Example of poor code:
WRITE /
AT 2 '???'.
WRITE AT 1 sy-vline.
WRITE AT 4 sy-vline.
WRITE AT 7 sy-vline.
WRITE AT
10 sy-vline.
Recommended solution:
WRITE AT 1 sy-vline.
WRITE AT 2 '?'.
WRITE AT 4 sy-vline.
WRITE AT 5 '?'.
WRITE AT 7 sy-vline.
WRITE AT 8 '?'.
WRITE AT 10 sy-vline.
2.
Output using
RIGHT-JUSTIFIED
Example of poor code:
DATA
text(10) TYPE c.
text = '???'.
WRITE text TO text
RIGHT-JUSTIFIED.
WRITE
text.
Recommended solution:
DATA
text(10) type c.
text = '???'.
WRITE text RIGHT-JUSTIFIED.
3.
Outputting the
entire content
Example of poor code:
DATA text(10) TYPE
c.
text = 'OTTOS MOPS'.
WRITE / text.
text = '??????????'.
WRITE / text.
Recommended solution:
DATA
text(10) TYPE c.
text = 'OTTOS MOPS'.
WRITE / (*) text.
text = '??????????'.
WRITE / (*) text.
4.
Scrolling
Example of poor code:
TYPES t_line(100) TYPE
c.
DATA: line TYPE
t_line,
tab TYPE
table of t_line.
PARAMETERS scrolcol TYPE i
DEFAULT 14.
line = '??????????????'.
APPEND line TO tab.
line = '??????????????'.
APPEND line TO tab.
LOOP AT tab INTO
line.
WRITE /
line+scrolcol.
ENDLOOP.
Recommended solution:
TYPES t_line(100) TYPE
c.
DATA: line TYPE
t_line,
tab TYPE
table of t_line.
PARAMETERS scrolcol TYPE i DEFAULT
14.
line = '??????????????'.
APPEND line TO tab.
line = '??????????????'.
APPEND line TO tab.
LOOP AT tab INTO line.
WRITE / line.
ENDLOOP.
SCROLL LIST TO COLUMN
scrolcol.
5. Mixing output length and buffer length
The example refers to the database table
ZCHNUMBERS in the ABAP Dictionary, which is to contain the names of the
numbers 1 to 5 in English and Korean.
Example of poor code:
SELECT *
FROM zchnumbers INTO wa ORDER BY num lang.
WRITE wa-lang TO
line(2).
WRITE sy-vline TO
line+2(1).
WRITE wa-name TO
line+3(5).
WRITE sy-vline TO
line+8(1).
WRITE wa-num TO
line+9(3) RIGHT-JUSTIFIED.
WRITE / line.
ENDSELECT.
Recommended solution:
DATA:
offset_tab TYPE abap_offset_tab.
APPEND 3
TO offset_tab.
APPEND 8 TO offset_tab.
SELECT * FROM zchnumbers INTO wa.
WRITE wa-lang TO
line(2).
WRITE sy-vline TO
line+2(1).
WRITE wa-name TO
line+3(5).
WRITE sy-vline TO
line+8(1).
WRIE wa-num TO
line+9(3) RIGHT-JUSTIFIED.
CALL METHOD
cl_abap_list_utilities=>memory_to_display
EXPORTING memory_data = line
offset_tab =
offset_tab
IMPORTING display_data =
disp_line.
WRITE / disp_line.
ENDSELECT.
6.
Misuse of system
field SY-CUCOL as buffer offset
Example of poor code:
DATA: off
type i.
AT LINE-SELECTION.
off = sy-staco + sy-cucol
– 3.
sy-lisel+off(1) = '-'.
MODIFY CURRENT
LINE.
START-OF-SELECTION.
WRITE / '?'.
WRITE at 50(14) '?????'.
SCROLL LIST TO COLUMN
20.
Recommended solution:
DATA:
f TYPE string,
mo TYPE i.
AT
LINE-SELECTION.
GET CURSOR FIELD f MEMORY OFFSET
mo.
sy-lisel+mo(1) =
'-'.
MODIFY CURRENT
LINE.
Note:
The character ? is used as a placeholder for the
representation of East Asian characters.