Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

CL_SALV_TABLE - Exception Column Text Change

$
0
0

This document helps in understanding the code to be implemented for displaying report using CL_SALV_TABLE for showing TRAFFIC LIGHTS

 

  1. Generally when displaying TRAFFIC LIGHTS, we use set_exception_column() method. When used this method, column text is displayed as ‘EXCEPTION’ for TRAFFIC LIGHTS column.
  2. Using the below code we set our custom text for the same column i.e in place of EXCEPTION for TRAFFIC LIGHTS column we can use our custom code.

 

 

**&---------------------------------------------------------------------*

**& Report ZMDR_SALV_TEST

**&

**&---------------------------------------------------------------------*

 

REPORT zmdr_salv_test.

TYPES: BEGIN OF ty_alv,

             lights(1) TYPE c, "Exception, Holding the value of the lights

             text(20) TYPE c,  "some text

            END OF ty_alv.

DATA: gs_alv TYPE ty_alv,

            gt_alv TYPE TABLE OF ty_alv,

           gr_alv TYPE REF TO cl_salv_table,

           gr_columns TYPE REF TO cl_salv_columns_table,

           gr_column TYPE REF TO cl_salv_column_table.

 

START-OF-SELECTION.

 

  gs_alv-lights = '1'.    "Color red

  gs_alv-text = 'RED SIGNAL'.

  APPEND gs_alv TO gt_alv.

 

  gs_alv-lights = '2'.    "Color yellow

  gs_alv-text = 'YELLOW SIGNAL'.

  APPEND gs_alv TO gt_alv.

 

  gs_alv-lights = '3'.    "Color green

  gs_alv-text = 'GREEN SIGNAL'.

  APPEND gs_alv TO gt_alv.

 

  CALL METHOD cl_salv_table=>factory

    IMPORTING

      r_salv_table = gr_alv

    CHANGING

      t_table      = gt_alv.

 

  gr_columns = gr_alv->get_columns( ).

gr_columns->set_exception_column( value = 'LIGHTS' ).

 

  TRY.

      gr_column ?= gr_columns->get_column( 'LIGHTS' ).

gr_column->set_medium_text( 'STATUS' ).

gr_column->set_long_text( 'STATUS' ).

gr_column->set_short_text( 'STATUS' ).

    CATCH cx_salv_not_found. "#EC NO_HANDLER

  ENDTRY.

 

 

  TRY.

      gr_column ?= gr_columns->get_column( 'TEXT' ).

gr_column->set_medium_text( 'TEXT' ).

gr_column->set_long_text( 'TEXT' ).

gr_column->set_short_text( 'TEXT' ).

    CATCH cx_salv_not_found. "#EC NO_HANDLER

  ENDTRY.

 

 

  CALL METHOD gr_alv->display.

 

Output looks like below:

 

 

 

Use the below code for changing the text of  ‘EXCEPTION’  to custom text(here I used ‘STATUS’)

 

REPORT  zmdr_salv_test.
*
TYPES: BEGIN OF ty_alv,
lights(4) TYPE c, "Exception, Holding the value of the lights
text(20) TYPE c"some text
END OF ty_alv.

DATA: gs_alv TYPE ty_alv,
gt_alv TYPE TABLE OF ty_alv,
gr_alv TYPE REF TO cl_salv_table,
gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table.

TYPE-POOLS : icon.

START-OF-SELECTION.

WRITE icon_red_light TO gs_alv-lights.
*Commented below line

*  gs_alv-lights = '1'.    "Color red
gs_alv-text = 'RED SIGNAL'.
APPEND gs_alv TO gt_alv.

WRITE icon_yellow_light TO gs_alv-lights.

*Commented below line

*  gs_alv-lights = '2'.    "Color yellow
gs_alv-text = 'YELLOW SIGNAL'.
APPEND gs_alv TO gt_alv.

WRITE icon_green_light TO gs_alv-lights.

*Commented below line

 

*  gs_alv-lights = '3'.    "Color green
gs_alv-text = 'GREEN SIGNAL'.
APPEND gs_alv TO gt_alv.

CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = gr_alv
CHANGING
t_table      = gt_alv.

gr_columns = gr_alv->get_columns( ).

*Commented below line

*gr_columns->set_exception_column( value = 'LIGHTS' ).

TRY.
gr_column ?= gr_columns->get_column( 'LIGHTS' ).
gr_column->set_medium_text( 'STATUS' ).
gr_column->set_long_text( 'STATUS' ).
gr_column->set_short_text( 'STATUS' ).
CATCH cx_salv_not_found.                            "#EC NO_HANDLER
ENDTRY.

TRY.
gr_column ?= gr_columns->get_column( 'TEXT' ).
gr_column->set_medium_text( 'TEXT' ).
gr_column->set_long_text( 'TEXT' ).
gr_column->set_short_text( 'TEXT' ).
CATCH cx_salv_not_found.                            "#EC NO_HANDLER
ENDTRY.


CALL METHOD gr_alv->display.

 

 

 

Output looks like below:


 

Hope this helps you.

 

 

Regards,

Mohammed Rafi


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>