You are on page 1of 4

Introduction

Sometimes, there is a requirement to set an ALV Column to “wrap word” so that the text gets moved to
the second line if there is too much text for the Column Width. ALV doesn’t provide the functionality to
wrap the texts. That’s why column that has long texts are not get displayed in single instance.

Purpose

The purpose of this document is to provide an option of “wrap word” to ALV functionality.

Technical Steps to be followed

        Multiple columns can also be wrapped as per requirement.

      Identify the length to which the column needs to be wrapped and define a field of same length.
Different columns can be wrapped to different length, and hence logic needs to be modified
accordingly.

        For ALV output, data records internal table is defined to populate output. In order to implement
wrap functionality, we need to declare another internal table with the desired wrapped length.
This internal table will contain wrapped texts for the column. Internal table will need to have first
column as identifier to match each record of parent internal table.

         Standard Function Module RKD_WORD_WRAP is used to wrap the desired text.

 REUSE_ALV_EVENTS_GET is called to get the list of all active events for particular ALV
report output.
 Populate appropriate FORM name for the event AFTER_LINE_OUTPUT.
 Call function module REUSE_ALV_LIST_DISPLAY to populate report output. ALV List is
used for demonstration.
 Implement AFTER_LINE_OUTPUT event among other events for the ALV.

Sample code

REPORT ztest_wordwrap.

TYPE-POOLS slis.
CONSTANTS : c_len TYPE i VALUE 20.

TYPES : BEGIN OF ty_t100 ,


sprsl TYPE t100-sprsl ,
arbgb TYPE t100-arbgb ,
msgnr TYPE t100-msgnr ,
text TYPE t100-text ,
fline TYPE t100-text ,
END OF ty_t100 .

TYPES : BEGIN OF ty_wrd,


text TYPE char20 ,
END OF ty_wrd .

DATA : it_t100 TYPE TABLE OF ty_t100 ,


it_sentence TYPE TABLE OF ty_wrd ,
wa_t100 TYPE ty_t100 ,
wa_word TYPE ty_wrd ,
v_repid TYPE syst-repid ,
v_tabix TYPE syst-tabix .
DATA : it_fld TYPE slis_t_fieldcat_alv ,
it_evt TYPE slis_t_event ,
wa_fld TYPE slis_fieldcat_alv ,
wa_evt TYPE slis_alv_event .

INITIALIZATION .
v_repid = sy-repid .

START-OF-SELECTION .
*Get data
SELECT * INTO TABLE it_t100
FROM t100
WHERE sprsl = 'EN'
AND arbgb = '00' .

LOOP AT it_t100 INTO wa_t100 .


v_tabix = sy-tabix .
CLEAR : it_sentence .

CALL FUNCTION 'RKD_WORD_WRAP'


EXPORTING
textline = wa_t100-text
outputlen = c_len
TABLES
out_lines = it_sentence.
IF NOT it_sentence IS INITIAL .
READ TABLE it_sentence INTO wa_word INDEX 1 .
wa_t100-fline = wa_word-text .
MODIFY it_t100 FROM wa_t100 INDEX v_tabix .
ENDIF.
ENDLOOP.

*Prepare fieldcatelog
CLEAR wa_fld .
wa_fld-fieldname = 'SPRSL' .
wa_fld-ref_tabname = 'T100' .
wa_fld-ref_fieldname = 'SPRSL' .
APPEND wa_fld TO it_fld . CLEAR wa_fld.

wa_fld-fieldname = 'ARBGB' .
wa_fld-ref_tabname = 'T100' .
wa_fld-ref_fieldname = 'ARBGB' .
APPEND wa_fld TO it_fld . CLEAR wa_fld.

wa_fld-fieldname = 'MSGNR' .
wa_fld-ref_tabname = 'T100' .
wa_fld-ref_fieldname = 'MSGNR' .
APPEND wa_fld TO it_fld . CLEAR wa_fld .

wa_fld-fieldname = 'FLINE' .
wa_fld-inttype = 'CHAR' .
wa_fld-outputlen = 20 .
wa_fld-intlen = 20.
wa_fld-seltext_l = 'Text' .
wa_fld-ddictxt = 'L' .
APPEND wa_fld TO it_fld .

*Get event we will handle BEFORE and AFTER line output

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'


IMPORTING
et_events = it_evt.

READ TABLE it_evt INTO wa_evt WITH KEY name = slis_ev_after_line_output .


wa_evt-form = slis_ev_after_line_output .
MODIFY it_evt FROM wa_evt INDEX sy-tabix .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'


EXPORTING
i_callback_program = v_repid
it_fieldcat = it_fld
it_events = it_evt
TABLES
t_outtab = it_t100.

*--------------------------------------------------------------------------------

*FORM AFTER_LINE_OUTPUT *

*--------------------------------------------------------------------------------

FORM after_line_output USING rs_lineinfo TYPE slis_lineinfo .


CLEAR : it_sentence ,wa_t100 .
READ TABLE it_t100 INTO wa_t100 INDEX rs_lineinfo-tabindex .

CHECK sy-subrc = 0 .

CALL FUNCTION 'RKD_WORD_WRAP'


EXPORTING
textline = wa_t100-text
outputlen = c_len
TABLES
out_lines = it_sentence.

DESCRIBE TABLE it_sentence LINES v_tabix .

CHECK v_tabix > 1 .


LOOP AT it_sentence INTO wa_word FROM 2 .
WRITE: / sy-vline ,
10 sy-vline ,
31 sy-vline ,
37 sy-vline ,
38 wa_word-text ,
58 sy-vline .
ENDLOOP.
ENDFORM . "after_line_output

Output of “wrap word” in ALV List output

You might also like