The purpose of this document is to provide an option of “word wrap” to ALV functionality. Other options may be possible; however, they only work around and doesn’t provide end user the flexibility to view the texts in single instance. Few of the other alternatives are listed below –
· You can make the column text as link and show truncated text so that even if the whole text in a column is not seen, the user can see the entire text on mouse over.
· You can implement functionality where in on clicking on the required cell, a popup comes with the entire text.
However, in the above alternatives, incase end user needs to take print out of the report output, he will miss out the truncated texts. Sample code :
REPORT ZVV_TEST.
TYPE-POOLS: SLIS.TYPES: BEGIN OF TY_DATA,
EMP TYPE CHAR10,
EMP_NAME TYPE CHAR100,
EMP_NAME1 TYPE CHAR20,
END OF TY_DATA.TYPES: BEGIN OF TY_WRD,
EMP TYPE CHAR20,
END OF TY_WRD.
data C_LEN TYPE I VALUE 20.
DATA: REPORT_ID LIKE SY-REPID,
IT_SENTENCE TYPE TABLE OF TY_WRD,
WA_WORD TYPE TY_WRD,
V_REPID TYPE SYST-REPID,
V_TABIX TYPE SYST-TABIX.DATA: WS_TITLE TYPE LVC_TITLE VALUE 'An ALV Report'.DATA: IT_EVT TYPE SLIS_T_EVENT,
IT_FLD TYPE SLIS_T_FIELDCAT_ALV,
WA_FLD TYPE SLIS_FIELDCAT_ALV,
WA_EVT TYPE SLIS_ALV_EVENT,
WA_LAY TYPE SLIS_LAYOUT_ALV.DATA: WATAB TYPE TY_DATA,
I_DATA TYPE STANDARD TABLE OF TY_DATA,
COUNT TYPE I VALUE 0.
* Number of records
DO 4 TIMES.
COUNT = COUNT + 1.
CASE COUNT.
WHEN 1.
WATAB-EMP = '10'.
WATAB-EMP_NAME = 'Purpose of this tutorial is to provide an easy and quick reference which may be used as a guide'.
APPEND WATAB TO I_DATA.
CLEAR WATAB.
WHEN 2.
WATAB-EMP = '20'.
WATAB-EMP_NAME = 'Coding is done for ALV List Display'.
APPEND WATAB TO I_DATA.
CLEAR WATAB.
WHEN 3.
WATAB-EMP = '30'.
WATAB-EMP_NAME = 'Same functionality can be implemented for ALV Grid Display also'.
APPEND WATAB TO I_DATA.
CLEAR WATAB.
ENDCASE.
ENDDO.REPORT_ID = SY-REPID. CLEAR WA_FLD.
WA_FLD-FIELDNAME = 'EMP'.
WA_FLD-REF_TABNAME = 'I_DATA'.
WA_FLD-SELTEXT_L = 'EMP. ID'.
WA_FLD-REF_FIELDNAME = 'EMP'.
APPEND WA_FLD TO IT_FLD. CLEAR WA_FLD.
WA_FLD-FIELDNAME = 'EMP_NAME1'.
WA_FLD-INTTYPE = 'CHAR'.
WA_FLD-OUTPUTLEN = 20.
WA_FLD-INTLEN = 20.
WA_FLD-SELTEXT_L = 'EMP. NAME'.
WA_FLD-DDICTXT = 'L'.
APPEND WA_FLD TO IT_FLD.
* Word Wrap the text in multiple lines
LOOP AT I_DATA INTO WATAB.
V_TABIX = SY-TABIX.
CLEAR: IT_SENTENCE[].
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
TEXTLINE = WATAB-EMP_NAME
OUTPUTLEN = C_LEN
TABLES
OUT_LINES = IT_SENTENCE
EXCEPTIONS
OUTPUTLEN_TOO_LARGE = 1
OTHERS = 2
.
IF SY-SUBRC eq 0.
IF NOT IT_SENTENCE IS INITIAL.
READ TABLE IT_SENTENCE INTO WA_WORD INDEX 1.
WATAB-EMP_NAME1 = WA_WORD-EMP.
MODIFY I_DATA FROM WATAB INDEX V_TABIX.
ENDIF.
ENDIF.
ENDLOOP.
* 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.WA_LAY-EDIT = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = REPORT_ID
IS_LAYOUT = WA_LAY
IT_FIELDCAT = IT_FLD
IT_EVENTS = IT_EVT
TABLES
T_OUTTAB = I_DATA
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.IF SY-SUBRC <> 0.
* Exceptions will be handled as per requirement
ENDIF.
*---------------------------------------------------------------------*
* FORM AFTER_LINE_OUTPUT *
*---------------------------------------------------------------------*
FORM AFTER_LINE_OUTPUT USING RS_LINEINFO TYPE SLIS_LINEINFO.
CLEAR: IT_SENTENCE, WATAB.
READ TABLE I_DATA INTO WATAB INDEX RS_LINEINFO-TABINDEX.
CHECK SY-SUBRC = 0. CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
TEXTLINE = WATAB-EMP_NAME
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,
12 SY-VLINE,
13 WA_WORD-EMP,
33 SY-VLINE.
ENDLOOP.
ENDFORM. "after_line_output
No comments:
Post a Comment