Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

color alv list display

hi all,

i have field value in and out based on the requirement if in s there s color to be red and if out s

there i s color green. in alv list display plz guide me

thanking you

Tags:
replied

Hello Santosh

A fancy report demonstrating the possibilities of ALV colouring is ZUS_SDN_ALV_CELL_STYLE_2.

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_ALV_STYLE_LIST
*&
*&---------------------------------------------------------------------*
*& Thread: color alv list display
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1072435"></a>
*&
*& Thread: Hiliting the Specific rows in ALV grid
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1062831"></a>
*&
*& Thread: Reg... coloring of rows
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1041516"></a>
*&
*& Thread: Painting cell in alv with objects
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1029759"></a>
*&
*& Thread: styles
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="830498"></a>
*&
*& Thread: Is it possible to assign color to manually modified record in tabcontrol?
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="878289"></a>
*&---------------------------------------------------------------------*
*& The report generates style values and shows their effect in ALV grid.
*&---------------------------------------------------------------------*


REPORT  zus_sdn_alv_cell_style_2.


TYPE-POOLS: abap.


TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1.
TYPES: celltab TYPE lvc_t_styl. " cell style
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.



TYPES: BEGIN OF ty_s_outtab2.
INCLUDE TYPE lvc_s_styl.
TYPES: celltab TYPE lvc_t_styl. " cell style
TYPES: END OF ty_s_outtab2.
TYPES: ty_t_outtab2 TYPE STANDARD TABLE OF ty_s_outtab2
WITH DEFAULT KEY.

DATA:
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
gt_fcat TYPE lvc_t_fcat.

DATA:
gt_outtab TYPE ty_t_outtab,
gt_outtab2  TYPE ty_t_outtab2.


parameters:
  p_rows    type i default 200.


START-OF-SELECTION.

  SELECT * FROM knb1 UP TO 100 ROWS
  INTO CORRESPONDING FIELDS OF TABLE gt_outtab
  WHERE bukrs = '1000'.

  PERFORM set_layout_and_variant.
  PERFORM set_cell_style.

**  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
**    EXPORTING
**      i_structure_name = 'KNB1'
**      i_grid_title     = 'Cell Styles'
**      is_layout_lvc    = gs_layout
**      i_save           = 'A'
**      is_variant       = gs_variant
**    TABLES
**      t_outtab         = gt_outtab
**    EXCEPTIONS
**      program_error    = 1
**      OTHERS           = 2.
**  IF sy-subrc = 0.
**  ENDIF.


  PERFORM fill_outtab2.
**  PERFORM fill_fieldcatalog_2.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_structure_name = 'LVC_S_STYL'
      i_grid_title     = 'Cell Styles'
      is_layout_lvc    = gs_layout
      i_save           = 'A'
      is_variant       = gs_variant
*      IT_FIELDCAT_LVC  = gt_fcat
    TABLES
      t_outtab         = gt_outtab2
    EXCEPTIONS
      program_error    = 1
      OTHERS           = 2.
  IF sy-subrc = 0.
  ENDIF.

END-OF-SELECTION.


*&---------------------------------------------------------------------
*& Form SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------

FORM set_layout_and_variant .

  CLEAR: gs_layout,
  gs_variant.

  gs_layout-cwidth_opt = abap_true.
  gs_layout-stylefname = 'CELLTAB'.

  gs_variant-report = syst-repid.
  gs_variant-handle = 'STYL'.

ENDFORM. " SET_LAYOUT_AND_VARIANT


*&---------------------------------------------------------------------*
*&      Form  set_cell_style
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM set_cell_style .

* define local data
  CONSTANTS:
  lc_style_bold TYPE int4 VALUE '00000121',
  lc_style_red TYPE int4 VALUE '00000087',
  lc_style_cursive TYPE int4 VALUE '00008700',
  lc_style_underline_faint TYPE int4 VALUE '00008787',
  lc_style_underline TYPE int4 VALUE '00008707',
  lc_style_underline_red TYPE int4 VALUE '00008007'.

  DATA:
  ls_outtab TYPE ty_s_outtab,
  ls_style TYPE lvc_s_styl,
  lt_celltab TYPE lvc_t_styl.


  CLEAR: ls_style.
  ls_style-fieldname = 'BUKRS'.
  ls_style-style = '00000011'.    " make contents invisible
  INSERT ls_style INTO TABLE lt_celltab.

**  CLEAR: ls_style.
**  ls_style-fieldname = 'BUKRS'.
**  ls_style-style = lc_style_bold.
**  INSERT ls_style INTO TABLE lt_celltab.
***
**  CLEAR: ls_style.
**  ls_style-fieldname = 'KUNNR'.
**  ls_style-style = lc_style_red.
**  INSERT ls_style INTO TABLE lt_celltab.
***
**  CLEAR: ls_style.
**  ls_style-fieldname = 'ERDAT'.
**  ls_style-style = lc_style_cursive.
**  INSERT ls_style INTO TABLE lt_celltab.
***
**  CLEAR: ls_style.
**  ls_style-fieldname = 'ERNAM'.
**  ls_style-style = lc_style_underline.
**  INSERT ls_style INTO TABLE lt_celltab.




  ls_outtab-celltab = lt_celltab.
  MODIFY gt_outtab FROM ls_outtab
  TRANSPORTING celltab
  WHERE ( bukrs = '1000' ).

ENDFORM. " SET_CELL_STYLE
*&---------------------------------------------------------------------*
*&      Form  FILL_OUTTAB2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_outtab2 .
* define local data
  DATA: ls_outtab2  TYPE ty_s_outtab2,
        ld_num8(8)  TYPE n,
        ld_idx      TYPE i,
        ld_fname    TYPE fieldname,
        ld_perc     type i,
        ld_text(50) type c.

  DATA:
  ls_style TYPE lvc_s_styl,
  lt_celltab TYPE lvc_t_styl.

  FIELD-SYMBOLS: <ld_style>  TYPE lvc_style.

  ld_num8 = 0.


  DO p_rows TIMES.
    write syst-index to ld_text no-zero.
    condense ld_text NO-GAPS.
    ld_perc = ( syst-index * 100 ) / p_rows.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
      EXPORTING
        PERCENTAGE       = ld_perc
        text             = ld_text.


    CLEAR: ls_style,
       ls_outtab2.
    REFRESH: lt_celltab.

    ls_outtab2-maxlen = syst-index.
    MOVE ld_num8 TO ls_outtab2-style.
    ls_style-style = ls_outtab2-style.

    INSERT ls_style INTO TABLE lt_celltab.
    ls_outtab2-celltab = lt_celltab.

    APPEND ls_outtab2 TO gt_outtab2.

    ADD 1 TO ld_num8.
  ENDDO.




ENDFORM.                    " FILL_OUTTAB2
*&---------------------------------------------------------------------*
*&      Form  FILL_FIELDCATALOG_2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_fieldcatalog_2 .
* define local data
  DATA: ls_fcat TYPE lvc_s_fcat,
        lt_fcat TYPE lvc_t_fcat.

  DATA: ld_fname  TYPE fieldname.


  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'LVC_S_STYL'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = lt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  DELETE lt_fcat WHERE ( fieldname NE 'STYLE' ).

  READ TABLE lt_fcat INTO ls_fcat INDEX 1.

  DO 16 TIMES.
    ls_fcat-fieldname = 'STYLE'.
    ls_fcat-col_pos = syst-index.

    WRITE syst-index TO ld_fname NO-ZERO.
    CONDENSE ld_fname NO-GAPS.
    CONCATENATE ls_fcat-fieldname ld_fname INTO ls_fcat-fieldname.

    APPEND ls_fcat TO gt_fcat.
  ENDDO.

ENDFORM.                    " FILL_FIELDCATALOG_2

Regards

Uwe

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question