In today’s tutorial I want to teach you how to change the font style in your ALV list display. In this example I want to change certain columns font style into italic and bold printed.
Here’s how you do it.
1. Let’s create a new ABAP program in SE38.
2. Copy this code below:
"A sample code to change font style in ALV list
"ABAP www.freesaptutorial.com
* Include styles for ALV
INCLUDE <cl_alv_control>.
* Internla table for KNA1
DATA: t_kna1 TYPE STANDARD TABLE OF kna1.
* declate the field catalog
DATA: i_fields TYPE lvc_t_fcat.
* declare the field symbol
FIELD-SYMBOLS: <wa_fields> TYPE lvc_s_fcat.
PERFORM get_data_and_display_alv.
FORM get_data_and_display_alv.
" Begin selecting data from table customers
SELECT * FROM kna1 INTO TABLE t_kna1.
IF sy-subrc = 0.
* Get the field catalog
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'KNA1'
CHANGING
ct_fieldcat = i_fields
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3
.
IF sy-subrc = 0.
* Here we will change the font style into italic and bold
LOOP AT i_fields ASSIGNING <wa_fields>.
IF sy-tabix > 4.
<wa_fields>-style = ALV_STYLE_FONT_ITALIC.
ELSE.
<wa_fields>-style = ALV_STYLE_FONT_BOLD.
ENDIF.
ENDLOOP.
ENDIF.
* Display the ALV using selected style
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_structure_name = 'KNA1'
i_grid_title = 'Style demo'(001)
it_fieldcat_lvc = i_fields
TABLES
t_outtab = t_kna1
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDFORM.
Popularity: 3% [?]