CHANGE TEXT ALIGNMENT OF COLUMN IN Object Oriented ALV ( OO ALV )
In this SAP ABAP tutorial I will show you how to change the alignment of text of particular column or columns in Object Oriented ALV ( OO ALV ) .
Programmatically now you can change the text alignment on three possibilities :
1.Left aligned.
2.Centered.
3.Right aligned.
N.B : By default numericals values are right aligned and words are left aligned.Now , we can change this
according to our own taste.
In order to do this we need to call the SET_ALIGNMENT method of class CL_SALV_COLUMN .
Please refer to the following source codes :
*******************************************************************
*& Author : Roushan Kumar
*& Data : 15/06/2014
*& Description : Change text alignment in OO ALV
*******************************************************************
REPORT ztestr_alv_14.
TYPES : BEGIN OF gy_vbap,
vbeln TYPE vbeln_va,
posnr TYPE posnr_va,
matnr TYPE matnr,
END OF gy_vbap.
DATA : gt_vbap TYPE STANDARD TABLE OF gy_vbap INITIAL SIZE 1.
DATA : lo_alv TYPE REF TO cl_salv_table.REFRESH : gt_vbap[].
START-OF-SELECTION.
SELECT vbeln posnr matnr
FROM vbap
INTO TABLE gt_vbap
UP TO 10 ROWS.
IF sy-subrc IS INITIAL.
SORT gt_vbap BY vbeln posnr matnr .
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = gt_vbap.
CATCH cx_salv_msg .
ENDTRY.
*-- Change text alignment logic starts
DATA : lo_columns TYPE REF TO cl_salv_columns_table.
lo_columns = lo_alv->get_columns( ).
lo_columns->set_optimize( 'X' ).
DATA : lo_column TYPE REF TO cl_salv_column_table.
lo_column ?= lo_columns->get_column( 'POSNR' ).
CALL METHOD lo_column->set_alignment
EXPORTING
value = if_salv_c_alignment=>left.
*-- Change text alignment logic end
lo_alv->display( ).
*& Author : Roushan Kumar
*& Data : 15/06/2014
*& Description : Change text alignment in OO ALV
*******************************************************************
REPORT ztestr_alv_14.
TYPES : BEGIN OF gy_vbap,
vbeln TYPE vbeln_va,
posnr TYPE posnr_va,
matnr TYPE matnr,
END OF gy_vbap.
DATA : gt_vbap TYPE STANDARD TABLE OF gy_vbap INITIAL SIZE 1.
DATA : lo_alv TYPE REF TO cl_salv_table.REFRESH : gt_vbap[].
START-OF-SELECTION.
SELECT vbeln posnr matnr
FROM vbap
INTO TABLE gt_vbap
UP TO 10 ROWS.
IF sy-subrc IS INITIAL.
SORT gt_vbap BY vbeln posnr matnr .
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = gt_vbap.
CATCH cx_salv_msg .
ENDTRY.
*-- Change text alignment logic starts
DATA : lo_columns TYPE REF TO cl_salv_columns_table.
lo_columns = lo_alv->get_columns( ).
lo_columns->set_optimize( 'X' ).
DATA : lo_column TYPE REF TO cl_salv_column_table.
lo_column ?= lo_columns->get_column( 'POSNR' ).
CALL METHOD lo_column->set_alignment
EXPORTING
value = if_salv_c_alignment=>left.
*-- Change text alignment logic end
lo_alv->display( ).
OUTPUT :
excellent post, congratulations!
ReplyDelete