Wednesday, November 2, 2016

How to Color row in ALV report



REPORT  ZROWCOLOR.

TABLES:     vbak.

TYPE-poolsslis.                                 "ALV Declarations
TYPESBEGIN OF t_vbak,
  vbeln TYPE vbak-vbeln,
  erdat TYPE vbak-erdat,
  netwr TYPE vbak-netwr,
 CELLCOLOR TYPE LVC_T_SCOL,
END OF t_vbak.

DATAit_vbak TYPE STANDARD TABLE OF t_vbak INITIAL SIZE 0,
      wa_vbak TYPE t_vbak.

*ALV data declarations
DATAfieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_tab_group TYPE slis_t_sp_group_alv,
      gd_layout    TYPE slis_layout_alv,
      gd_repid     LIKE sy-repid,
      gt_events     TYPE slis_t_event,
      gd_prntparams TYPE slis_print_alv.

START-OF-SELECTION.

PERFORM fill_data.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM set_cell_colours.
PERFORM display_alv_report.

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
FORM build_fieldcatalog.

  fieldcatalog-fieldname   'VBELN'.
  fieldcatalog-seltext_m   'Sales Order'.
  fieldcatalog-col_pos     0.
  fieldcatalog-outputlen   10.
  fieldcatalog-emphasize   'X'.
  fieldcatalog-KEY         'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   'ERDAT'.
  fieldcatalog-seltext_m   'Created Date  '.
  fieldcatalog-col_pos     1.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   'NETWR'.
  fieldcatalog-seltext_m   'Document Value'.
  fieldcatalog-col_pos     2.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

ENDFORM.                    " BUILD_FIELDCATALOG

*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
FORM build_layout.
  gd_layout-no_input          'X'.
  gd_layout-colwidth_optimize 'X'.
  gd_layout-totals_text       'Totals'(201).
  gd_LAYOUT-coltab_fieldname 'CELLCOLOR'.  "CTAB_FNAME
ENDFORM.                    " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
FORM display_alv_report.
  gd_repid sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_callback_program      gd_repid
    i_callback_top_of_page   'TOP-OF-PAGE'  "see FORM
    is_layout               gd_layout
    it_fieldcat             fieldcatalog[]
    i_save                  'X'

  TABLES
    t_outtab                it_vbak
  EXCEPTIONS
    program_error           1
    OTHERS                  2.
  IF sy-subrc <> 0.

  ENDIF.
ENDFORM.                    " DISPLAY_ALV_REPORT

*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form vbak table and populate itab it_vbak
*----------------------------------------------------------------------*
FORM fill_data.

  SELECT vbeln erdat netwr
  UP TO 10 ROWS
  FROM vbak
  INTO CORRESPONDING FIELDS OF TABLE it_vbak.
ENDFORM.                    " DATA_RETRIEVAL


*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
FORM top-OF-PAGE.
*ALV Header declarations
  DATAt_header TYPE slis_t_listheader,
        wa_header TYPE slis_listheader,
        t_line LIKE wa_header-info,
        ld_lines TYPE I,
        ld_linesc(10TYPE C.

* Title
  wa_header-typ  'H'.
  wa_header-info 'Sales Order Report'.
  APPEND wa_header TO t_header.
  CLEAR wa_header.

* Date
  wa_header-typ  'S'.
  wa_header-KEY 'Date: '.
  CONCATENATE  sy-datum+6(2'.'
  sy-datum+4(2'.'
  sy-datum(4INTO wa_header-info.   "todays date
  APPEND wa_header TO t_header.
  CLEARwa_header.

* Total No. of Records Selected
  DESCRIBE TABLE it_vbak LINES ld_lines.
  ld_linesc ld_lines.
  CONCATENATE 'Total No. of Records Selected: ' ld_linesc
  INTO t_line SEPARATED BY space.
  wa_header-typ  'A'.
  wa_header-info t_line.
  APPEND wa_header TO t_header.
  CLEARwa_headert_line.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
  EXPORTING
    it_list_commentary t_header.
ENDFORM.                    "top-of-page


*&---------------------------------------------------------------------*
*&      Form  SET_CELL_COLOURS
*&---------------------------------------------------------------------*
*       Set colour of individual ALV cell, field
*----------------------------------------------------------------------*
FORM SET_CELL_COLOURS .
  DATAWA_CELLCOLOR TYPE LVC_S_SCOL.
  DATAld_index TYPE SY-TABIX.

  LOOP AT IT_VBAK INTO wa_vbak.
    LD_INDEX SY-TABIX.

    WA_CELLCOLOR-FNAME 'VBELN'.
    WA_CELLCOLOR-COLOR-COL sy-tabix.
    WA_CELLCOLOR-COLOR-INT '1'.  "1 = Intensified on, 0 = Intensified off
    WA_CELLCOLOR-COLOR-INV '0'.  "1 = text colour, 0 = background colour
    APPEND WA_CELLCOLOR TO wa_vbak-CELLCOLOR.
    MODIFY it_vbak FROM wa_vbak INDEX ld_index TRANSPORTING CELLCOLOR.

    IF wa_vbak-netwr GT 0.
      WA_CELLCOLOR-FNAME 'NETWR'.
      WA_CELLCOLOR-COLOR-COL 4.
      WA_CELLCOLOR-COLOR-INT '0'.
      WA_CELLCOLOR-COLOR-INV '0'.
      APPEND WA_CELLCOLOR TO wa_vbak-CELLCOLOR.
      MODIFY it_vbak FROM wa_vbak INDEX ld_index TRANSPORTING CELLCOLOR.
    ENDIF.


    WA_CELLCOLOR-FNAME 'ERDAT'.
    WA_CELLCOLOR-COLOR-COL 6.
    WA_CELLCOLOR-COLOR-INT '0'.
    WA_CELLCOLOR-COLOR-INV '1'.
    APPEND WA_CELLCOLOR TO wa_vbak-CELLCOLOR.
    MODIFY it_vbak FROM wa_vbak INDEX ld_index TRANSPORTING CELLCOLOR.
  ENDLOOP.

ENDFORM.


outputs:

55 comments:

  1. You made some decent factors there. I looked on the internet for the difficulty and found most individuals will associate with along with your website.Keep update more excellent posts.

    Sap Training in Chennai | Sap Abap Training in Chennai | Sap SD Training in Chennai

    ReplyDelete

  2. thank you for sharing such a unique content.please provide latest updates .one of the recommanded blog

    http://www.suntrainings.com/sapabap.html

    ReplyDelete
  3. Thanks for your comments.. And will try to keep uploading new contents.

    ReplyDelete
  4. I am planning to join sap abap with them after reading your blog.
    Hope the best will turn out.
    Call them at 8122241286 in chennai.
    www.thecreatingexperts.com

    ReplyDelete
  5. We provide sap abap technical course, call us to know more about us and join with us.
    Call them at 8122241286 in chennai.
    www.thecreatingexperts.com

    ReplyDelete
  6. Thanks for the great information in your blog on It was so nice article sap video tutorials

    ReplyDelete

  7. Well it Was Very Good Information. Thanks for sharing this Information. sap video tutorials

    ReplyDelete


  8. Thank you for giving this best information. It’s a very nice topic sap video tutorials

    ReplyDelete
  9. Thank you sir.I get a lot of great information from this blog on sap video

    ReplyDelete

  10. Thanks for the great information in your blog on It was so nice article Thank you for valuable informationsap video tutorials

    ReplyDelete
  11. Thank you sir.It was so nice article Thank you for valuable information sap video

    ReplyDelete
  12. Thank you for giving this best information. It’s a very nice topic.sap video

    ReplyDelete
  13. I am very greatful to you that you share very informative post with us sap video tutorials

    ReplyDelete
  14. Thank you sir.I am very greatful to you that you share very informative post with us sap video tutorials

    ReplyDelete
  15. Thank you for giving this best information. It’s a very nice topic. sap video tutorials

    ReplyDelete
  16. Thank you sir.Thanks for Nice and Informative Post on sap video

    ReplyDelete
  17. It was so nice article Thank you for valuable information sap video

    ReplyDelete

  18. Thank you for giving this best information. It’s a very nice topic sap video tutorials

    ReplyDelete
  19. Thank you. It is such a wonderful post. it has great information it is very useful for sap video tutorial.

    ReplyDelete
  20. This article is really contains lot more information about This Topic on. sap video tutorials

    ReplyDelete
  21. Good post! Thanks for sharing this Information.The information you Provided is much useful on sap video

    ReplyDelete

  22. Well, I found this information really useful. Thanks a ton for this.
    sap video tutorials

    ReplyDelete

  23. Well, I found this information really useful. Thanks a ton for this. sap video tutorials

    ReplyDelete
  24. Thanks for providing this information. sap video tutorials

    ReplyDelete

  25. I am very greatful to you that you share very informative post with us. sap video tutorials

    ReplyDelete


  26. Thanks for the detailed info about SAP. sap video tutorials

    ReplyDelete
  27. SAP ABAP training is provided in CHENNAI.

    THE CREATING EXPERTS is one of the leading trainer in SAP who provides real time training

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    contact 8122241286

    ReplyDelete
  28. Thank you. sir, Really I like your post on. sap video

    ReplyDelete
  29. Thank you for Wonderful information.

    SAP ABAP training in CHENNAI BY THE CREATING EXPERTS

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    CONTACT 8122241286

    ReplyDelete
  30. Thank you for Wonderful information.

    SAP ABAP training in CHENNAI BY THE CREATING EXPERTS

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    CONTACT 8122241286

    ReplyDelete
  31. Fabulous..!!! The information you Provided is much useful. sapvideos

    ReplyDelete
  32. I get a lot of great information from this blog on. sap video tutorials

    ReplyDelete

  33. Thank you for Sharing Great Information. sap video tutorials

    ReplyDelete

  34. it has great information it is very useful Post. sap video

    ReplyDelete

  35. Thank you for giving this best information. It’s a very nice topic. sap tutorial videos

    ReplyDelete

  36. I get a lot of great information from this blog on. sap video

    ReplyDelete
  37. it has great information it is very useful Post. sap video

    ReplyDelete
  38. I get a lot of great information from this blog. sap videos tutorials

    ReplyDelete
  39. Thank you. sir, Really I like your post on. sap video

    ReplyDelete
  40. Fabulous..!!! The information you Provided is much useful. sap videos tutorials

    ReplyDelete
  41. Thanks for sharing this Information,
    Got to learn new things from your Blog on Sap fiori.
    SAP ABAP Consultant India

    ReplyDelete

  42. Well, I found this information really useful. Thanks a ton for this. sap tutorial videos

    ReplyDelete
  43. Thankyou for Sharing Great Information. It is Very Helpful Information on sap training videos.

    ReplyDelete
  44. It was so nice article.I was really satisified by seeing this article sapvideos.

    ReplyDelete

Drop Down lists in the selection parameters

PROGRAM ztest.   TYPE-POOLS : vrm.   DATA : name TYPE vrm_id,        list TYPE vrm_values,        value LIKE LINE OF list. ...