Monday, August 7, 2017

ALV Grid Color Line with Bold Text

In the ALV Grid display report we can colour one particular line (condition based) and also we can BOLD text. In the following example we are showing PO list with quantity calculation list. We have Sub Total line (colour = yellow & BOLD text) and Similar kind of Grand Total line. Here we have the output table structure as follows.

TYPES: BEGIN OF ty_out,
         ebeln TYPE char15,
         ebelp TYPE char5,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         menge TYPE ekpo-menge,
         meins TYPE ekpo-meins,
         color TYPE char4,
         bold  TYPE lvc_t_styl,
       END OF ty_out.

Here we have a field of colour of 4 character types & BOLD field of table lvc_t_styl type. This table is a sorted internal table and we insert style field with value ‘00000121’. Here we are using the function - REUSE_ALV_GRID_DISPLAY_LVC and Field catalogue type is lvc_t_fcat & Layout type is lvc_s_layo.

REPORT zsr_test NO STANDARD PAGE HEADING.

TABLES: ekko.
TYPE-POOLS: slis.
DATA: wa_fcat   TYPE lvc_s_fcat,
      it_fcat   TYPE lvc_t_fcat,
      wa_layout TYPE lvc_s_layo,
      wa_top    TYPE slis_listheader,
      it_top    TYPE slis_t_listheader.

TYPES: BEGIN OF ty_ekko,
         ebeln TYPE ekko-ebeln,
         aedat TYPE ekko-aedat,
       END OF ty_ekko.
DATA: wa_ekko TYPE ty_ekko,
      it_ekko TYPE TABLE OF ty_ekko.

TYPES: BEGIN OF ty_ekpo,
         ebeln TYPE ekpo-ebeln,
         ebelp TYPE ekpo-ebelp,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         menge TYPE ekpo-menge,
         meins TYPE ekpo-meins,
       END OF ty_ekpo.
DATA: wa_ekpo TYPE ty_ekpo,
      it_ekpo TYPE TABLE OF ty_ekpo.

TYPES: BEGIN OF ty_out,
         ebeln TYPE char15,
         ebelp TYPE char5,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         menge TYPE ekpo-menge,
         meins TYPE ekpo-meins,
         color TYPE char4,
         bold  TYPE lvc_t_styl,
       END OF ty_out.
DATA: wa_out TYPE ty_out,
      it_out TYPE TABLE OF ty_out.

INITIALIZATION.
  SELECT-OPTIONS s_aedat FOR ekko-aedat.

START-OF-SELECTION.
  PERFORM get_ekko.
  PERFORM get_ekpo.

END-OF-SELECTION.
  PERFORM prepare_output.
  PERFORM field_catalog.
  PERFORM alv_grid_display.

TOP-OF-PAGE.
  PERFORM top_of_page.
*&---------------------------------------------------------------------*
*&      Form  GET_EKKO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_ekko .

  SELECT ebeln aedat FROM ekko
    INTO TABLE it_ekko
    WHERE aedat IN s_aedat.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  GET_EKPO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_ekpo .

  IF it_ekko IS NOT INITIAL.
    SELECT ebeln ebelp matnr werks menge meins
      FROM ekpo INTO TABLE it_ekpo
      FOR ALL ENTRIES IN it_ekko
      WHERE ebeln = it_ekko-ebeln
        AND matnr NE ' '.

    IF sy-subrc = 0.
      SORT it_ekpo BY ebeln ebelp.
    ENDIF.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  PREPARE_OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM prepare_output .

  DATA: lw_bold TYPE lvc_s_styl,
        lt_bold TYPE lvc_t_styl.

  IF it_ekpo IS NOT INITIAL.
    LOOP AT it_ekpo INTO wa_ekpo.
      wa_out-ebeln = wa_ekpo-ebeln.
      wa_out-ebelp = wa_ekpo-ebelp.
      wa_out-matnr = wa_ekpo-matnr.
      SHIFT wa_out-matnr LEFT DELETING LEADING '0'.
      wa_out-werks = wa_ekpo-werks.
      wa_out-menge = wa_ekpo-menge.
      wa_out-meins = wa_ekpo-meins.
      APPEND wa_out TO it_out.
      CLEAR: wa_out.

      AT END OF ebeln.
        SUM.
        wa_out-ebeln = 'Sub Total'.
        wa_out-menge = wa_ekpo-menge.
        wa_out-color = 'C200'.
        lw_bold-style = '00000121'.
        INSERT lw_bold INTO lt_bold INDEX 1.
        wa_out-bold = lt_bold.
        FREE lt_bold.

        APPEND wa_out TO it_out.
        CLEAR: wa_out, lw_bold, wa_ekpo.
      ENDAT.

      AT LAST.
        SUM.
        wa_out-ebeln = 'Grand Total'.
        wa_out-menge = wa_ekpo-menge.
        wa_out-color = 'C210'.
        lw_bold-style = '00000121'.
        INSERT lw_bold INTO lt_bold INDEX 1.
        wa_out-bold = lt_bold.
        FREE lt_bold.

        APPEND wa_out TO it_out.
        CLEAR: wa_out, lw_bold, wa_ekpo.
      ENDAT.
    ENDLOOP.
  ENDIF.

  FREE it_ekpo.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FIELD_CATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM field_catalog .

  DATA: lv_col TYPE VALUE 0.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'EBELN'.
  wa_fcat-reptext   = 'Purchase Order'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'EBELP'.
  wa_fcat-reptext   = 'Item'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'MATNR'.
  wa_fcat-reptext   = 'Material'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'WERKS'.
  wa_fcat-reptext   = 'Plant'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'MENGE'.
  wa_fcat-reptext   = 'Quantity'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'MEINS'.
  wa_fcat-reptext   = 'Unit'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  wa_layout-zebra      = 'X'.
  wa_layout-cwidth_opt = 'X'.
  wa_layout-info_fname = 'COLOR'.
  wa_layout-stylefname = 'BOLD'.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  ALV_GRID_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_grid_display .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program     = sy-repid
      i_callback_top_of_page = 'TOP_OF_PAGE'
      is_layout_lvc          = wa_layout
      it_fieldcat_lvc        = it_fcat
    TABLES
      t_outtab               = it_out
    EXCEPTIONS
      program_error          = 1
      OTHERS                 2.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top_of_page .

  REFRESH it_top.

  wa_top-typ  = 'H'.
  wa_top-info = 'Purchasing List'.
  APPEND wa_top TO it_top.
  CLEAR wa_top.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = it_top.

ENDFORM.


Output is:



63 comments:

Alexa Scott said...

Nice Post...Thanks For useful information
http://saponlineguides.blogspot.in/

camelliacanan said...

Thanks for sharing the valuable information here. So i think i got some useful information with this content. Thank you and please keep update like this informative details.

SAP Training in Chennai

SAP ABAP Training in Chennai

Anonymous said...


Thank you. sir, Really I like your post on sap training videos

Unknown said...

This article is really contains lot more information. sapvideos

Anonymous said...


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

Anonymous said...


Thank you. sir, Really I like your post on. sap training videos

Unknown said...


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

Unknown said...

I get a lot of great information from this blog. sap training videos

Anonymous said...

Thanks for sharing this informative blog..Your blog is really useful for me. sapvideos

Unknown said...

The information you have given here is truly helpful to me..sap video tutorials

Unknown said...


it has great information it is very useful Post. sap videos

Anonymous said...


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

Anonymous said...


Thank you for Sharing Great Information. It is Very Helpful Information on.sapvideos

Unknown said...

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

Unknown said...

Thanks for sharing this informative blog..Your blog is really useful for me. sap video training

Anonymous said...

It was so nice article Thank you for valuable information. sap videos

Unknown said...

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

Unknown said...

Fabulous..!!! The information you Provided is much useful. sap videos online

Anonymous said...

Well it Was Very Good Information. Thanks for sharing this Information..Sap videos

Anonymous said...

It was so nice article.I was really satisfied by seeing this article. sap videos

Unknown said...


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

Unknown said...

I get a lot of great information from this blog on. sap training videos

Anonymous said...


Thanks for the detailed info about SAP. sap video training

Unknown said...

Thanks for sharing this informative blog..Your blog is really useful for me. sapvideos

Anonymous said...

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

Anonymous said...



Thanks for the detailed info about SAP. sap training videos

Anonymous said...

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

Anonymous said...

Thanks for sharing this informative blog..Your blog is really useful for me. sap training videos

Unknown said...


Thanks for Nice and Informative Post on. sapvideos

Anonymous said...

it has great information it is very useful Post. Sap videos

Anonymous said...

I am very grateful to you that you share very informative post with ussap videos tutorials

Unknown said...

Well, I found this information really useful. Thanks a ton for this. sapvideos

Unknown said...


I get a lot of great information from this blog on. sap videos online

Anonymous said...

Fabulous..!! Thank you.The information you provided is much usful information on sap training videos.

Anonymous said...


Thanks for Nice and Informative Post on Sap videos

Anonymous said...

It was so nice article.I was really satisified by seeing this article sap hana videos.

Anonymous said...

This article is really contains lot more information. sap training videos

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for sap s4 hana training videos.

Anonymous said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap training videos free download.

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for sap training videos free download.

logistic-solutions said...

Useful Information, your blog is sharing unique information....
Thanks for sharing!!!
SAP Consulting Services in usa
sas value added reseller

Unknown said...

This is very useful information.Thanks for sharing with us it was nice SAP article

Test My internet Speed said...

Thanks for sharing this Informative content. Well explained.
SAP ABAP Training institute in Noida

Sonam Singh said...

This paragraph gives clear idea for the new viewers of blogging, Thanks you.
SAP Training in Gurgaon

Online Sap Trainers said...

Thanks for sharing great post !!
This information you provided in the blog that is unique.I love it. Keep continue..
SAP online training | Best sap institute in India
sap hana online training

logistic-solutions said...

Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
sas implementation services in north america

logistic-solutions said...

Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
sas implementation services in north america

Unknown said...

Worthful Sap Hana tutorial. Appreciate a lot for taking up the pain to write such a quality content on Sap Hana course. Just now I watched this similar -Sap Hana tutorial and I think this will enhance the knowledge of other visitors for sure. Thanks anyway.https://www.youtube.com/watch?v=PGE7A2kHw8Q

Unknown said...

thank you for sharing nyce information really very nice sap-pp online classes

Unknown said...

hi, Nice post such a valuable information and well explained.

SAP Training institute in hyderabad

All SAP Modules

Unknown said...

wow really superb you had posted one nice information through this. Definitely it will be useful for many people. So please keep update like this.sap hr abap online classes

calfre said...

Thank you for sharing this blog spa abap means advanced business application program for more details visit click here

Calfre611 said...

Thank you for sharing this blog Java means advanced business application program for more details about visit click here

srcalfre009 said...

Thanks for sharing nice information do visit us at
SAP ABAP Training in Texas>

Unknown said...

Hi, it was nice to read this Blog. Thanks for sharing a available informationSAP Basis Training in Irving

Unknown said...

This post is really nice and informative. The explanation given is really comprehensive and informative..sap-mm training

Unknown said...

These are questions I faced in one of the Interview. If u find any Solution with Coding please let me Know..

1. I have 100 records in a table, how can i simultaneously Delete the 5th, 10th, 15th, 20th......records , write a code for it

2. I have 10000 records, in that How can we sort records in Desending order and search 5005th record details....which is the best method to search it?

3. what do you mean by Update- Function Module, How it is different from Normal and Remote Enabled Function Module...

4. details about Scheduling...

Unknown said...

Awesome post presented by you..your writing style is fabulous and keep updated with your blogs
Tally ERP Training in Hyderabad

Unknown said...

Thanks for sharing this informative blog post. Nice video. easy to understand, really helpful for learning testing.
Machine Learning Training in Hyderabad

Unknown said...

This post is really nice and informative. The explanation given is really comprehensive and informative..sap hr abap training

Unknown said...

"Are you need Server access for SAP All modules Contact now and know the Unbelievable offers on Server Access for SAP All modules.
Grab the Special Offers and Discounts. One time payment available it gets more benefits.
Visit Us: www.visionsap.com
Phone No's Calling: +16032623609, Whatsapp: +91 7382121738
Mail ID: info@visionsap.com
#SAPoffers #SAPServerOffers #Specialoffers #Specialdiscounts #Limitedoffer #Hurryup
"

jm said...

I need the SAP Server access can you help me please?

Shivani said...

Great Post. The information provided is of great use as I got to learn new things. Keep Blogging.
SAP ABAP TRAINING IN HYDERABAD"