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:



61 comments:

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

    ReplyDelete
  2. 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

    ReplyDelete

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

    ReplyDelete
  4. This article is really contains lot more information. sapvideos

    ReplyDelete

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

    ReplyDelete

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

    ReplyDelete

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

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

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

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

    ReplyDelete

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

    ReplyDelete

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

    ReplyDelete

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

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

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

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

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

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

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

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

    ReplyDelete

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

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

    ReplyDelete

  23. Thanks for the detailed info about SAP. sap video training

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

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

    ReplyDelete


  26. Thanks for the detailed info about SAP. sap training videos

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

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

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

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

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

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

    ReplyDelete

  33. Thanks for Nice and Informative Post on Sap videos

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

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

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

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

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

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

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

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

    ReplyDelete
  42. 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

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

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

    ReplyDelete
  45. 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

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

    ReplyDelete
  47. 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

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

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

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

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

    ReplyDelete
  52. 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...

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

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

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

    ReplyDelete
  56. "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
    "

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

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

    ReplyDelete

Note: Only a member of this blog may post a comment.