Color on subtotal using ALV

Hi folks,
Is there any possibility put color using ALV (reuse alv grid display) on subtotals and also put the status beside the subtotal by ' * '  or  ' +'.
Thanks in advance
Rao

Subtotals are already coloured(Yellow)? Do you need any other color?
For altering sub total texts, Refer this link:
http://help.sap.com/saphelp_erp2004/helpdata/en/ee/c8e056d52611d2b468006094192fe3/frameset.htm
Regards,
Ravi

Similar Messages

  • Color on subtotal in alv

    Is there any possibility to display color on subtotals as it generated dynamically in alv.
    FM used : reuse_alv_grid_display..
    1. i am calculating the threshold quantity of shipped quantities for 12 months
    and populating it for customer material combination.
    2. for every customer material combination it displays the threshold quantity
    3. I am populating the shipped quantity by month wise for that customer and material combination
    4. Requirement is to check the shipped quantity and threshold quantity for the
    customer material combination , if the monthly shipped quantity is greater than
    threshold quantity then color is to be displayed on that subtotals as the end user
    identify easily.
    Can u Please reply logic to check this .
    Thanks in advance.
    Rao

    Hai,
    <b>See the below program for ALV color:</b>
    TYPE-POOLS: SLIS.
    PARAMETERS:
      P_ROW     TYPE I,
      P_COLUMN  TYPE I.
    DATA:
      FIELDCAT         TYPE SLIS_T_FIELDCAT_ALV,
      FIELDCAT_LN      LIKE LINE OF FIELDCAT,
      SORTCAT          TYPE SLIS_T_SORTINFO_ALV,
      SORTCAT_LN       LIKE LINE OF SORTCAT,
      EVENTCAT         TYPE SLIS_T_EVENT,
      EVENTCAT_LN      LIKE LINE OF EVENTCAT.
    DATA:
      COL_POS TYPE I.
    ******Declare Data Areas for List Viewer (End)**************
    ******Declare Internal Table to Store Selected Data (Begin)*
    DATA:
      BEGIN OF ISPFLI OCCURS 0,
        CHECK      TYPE SLIS_FIELDNAME,
        R_COLOR(3) TYPE C,
        CELL       TYPE SLIS_T_SPECIALCOL_ALV,
        CARRID     LIKE SPFLI-CARRID,
        CONNID     LIKE SPFLI-CONNID,
        COUNTRYFR  LIKE SPFLI-COUNTRYFR,
      END OF ISPFLI.
    DATA:
      WA LIKE LINE OF ISPFLI,
      W_LINES TYPE I.
    DATA:
      FS_CELL LIKE LINE OF ISPFLI-CELL.
    DATA:
      LAYOUT1 TYPE SLIS_LAYOUT_ALV.
    ******Declare Internal Table to Store Selected Data (End)***
    *******Select Data into Internal Table (Begin) ***************
    SELECT CARRID CONNID COUNTRYFR
             INTO CORRESPONDING FIELDS OF TABLE ISPFLI
             FROM SPFLI.
    DESCRIBE TABLE ISPFLI LINES W_LINES.
    IF P_ROW IS INITIAL AND
      P_COLUMN IS INITIAL .
      MESSAGE 'Enter atlest one number' TYPE 'I'.
      STOP.
    ELSEIF P_ROW GT W_LINES.
      MESSAGE 'Row with the row number is not there' TYPE 'I'.
      STOP.
    ENDIF.
    IF P_COLUMN IS NOT INITIAL AND
       P_COLUMN GT 3.
       MESSAGE 'Field with the column number is not there' TYPE 'I'.
       STOP.
    ENDIF.
    Select Data into Internal Table (End) ****************
    Build Field Catalogs (Begin)**************************
    IF P_ROW IS NOT INITIAL AND P_COLUMN IS INITIAL.
      PERFORM BUILD_FIELDCAT.
      PERFORM BUILD_FIELDCAT2.
      PERFORM BUILD_FIELDCAT4.
      PERFORM BUILD_LAYOUT1.
      PERFORM ROW_COLOR.
    ELSEIF P_COLUMN IS NOT INITIAL
      AND  P_ROW IS NOT INITIAL.
      PERFORM BUILD_FIELDCAT.
      PERFORM BUILD_FIELDCAT2.
      PERFORM BUILD_FIELDCAT4.
      PERFORM BUILD_LAYOUT1.
      PERFORM CELL_COLOR.
    ELSE.
      PERFORM BUILD_FIELDCAT.
      PERFORM BUILD_FIELDCAT2.
      PERFORM BUILD_FIELDCAT3.
      PERFORM BUILD_LAYOUT1.
    ENDIF.
    PERFORM ROW_COLOR.
    PERFORM CELL_COLOR.
    PERFORM BUILD_FIELDCAT.
    PERFORM BUILD_FIELDCAT2.
    PERFORM BUILD_FIELDCAT3.
    PERFORM BUILD_LAYOUT1.
    PERFORM ROW_COLOR.
    PERFORM CELL_COLOR.
    PERFORM ROW_COLOR.
    PERFORM CELL_COLOR.
    PERFORM BUILD_SORTCAT.
    PERFORM BUILD_SORTCAT2.
    ******Build Field Catalogs (End)*****************************
    ******Build Event Catalog (Begin)****************************
    PERFORM BUILD_EVENTCAT.
    ******Build Event Catalog (End)******************************
    ******Start List Viewer (Begin)******************************
    PERFORM START_LIST_VIEWER.
    ******Start List Viewer (End)********************************
    ********FORM ROUTINES (Begin)********************************
    FORM ROW_COLOR.
      CLEAR WA.
      READ TABLE ISPFLI INDEX P_ROW INTO WA.
      WA-R_COLOR = 'C61'.
      MODIFY ISPFLI FROM WA INDEX P_ROW.
      CLEAR WA.
    ENDFORM.
    FORM CELL_COLOR.
      CLEAR WA.
      CLEAR FS_CELL.
      FS_CELL-FIELDNAME = 'CONNID'.
      FS_CELL-COLOR-COL = P_COLUMN."4.
      FS_CELL-COLOR-INT = 0.
      FS_CELL-COLOR-INV = 1.
    READ TABLE ISPFLI INDEX P_ROW INTO WA.
      APPEND FS_CELL TO WA-CELL.
      MODIFY ISPFLI FROM WA INDEX P_ROW TRANSPORTING CELL.
      CLEAR WA.
      CLEAR FS_CELL.
    ENDFORM.
        Color table-FIELDNAME = field name of the cell to be colored
        Color table-COLOR-COL = color number (1 - 9)
        Color table-COLOR-INT = bold (0 = off, 1 = on)
        Color table-COLOR-INV = inverse (0 = off, 1 = on)
        Color table-NOKEYCOL  = ignore key coloring ('X' = yes, ' ' = no)
    FORM BUILD_FIELDCAT.
      CLEAR FIELDCAT_LN.
    ADD 1 TO COL_POS.
      FIELDCAT_LN-REF_TABNAME = 'SPFLI'.
      FIELDCAT_LN-FIELDNAME = 'CARRID'.
    FIELDCAT_LN-REF_FIELDNAME = SPACE.
      FIELDCAT_LN-OUTPUTLEN = 20.
      FIELDCAT_LN-KEY = 'X'.
      FIELDCAT_LN-NO_OUT = 'X'."SPACE.
    FIELDCAT_LN-DO_SUM = SPACE.
      FIELDCAT_LN-COL_POS = 2.
      FIELDCAT_LN-NO_OUT = SPACE.
    FIELDCAT_LN-QFIELDNAME = SPACE.
      FIELDCAT_LN-HOTSPOT = 'X'.
      APPEND FIELDCAT_LN TO FIELDCAT.
    ENDFORM.                    "BUILD_FIELDCAT
    *&      Form  BUILD_FIELDCAT2
          text
    FORM BUILD_FIELDCAT2.
      CLEAR FIELDCAT_LN.
    ADD 1 TO COL_POS.
      FIELDCAT_LN-REF_TABNAME = 'SPFLI'.
      FIELDCAT_LN-FIELDNAME = 'CONNID'.
    FIELDCAT_LN-REF_FIELDNAME = SPACE.
      FIELDCAT_LN-OUTPUTLEN = 20.
      FIELDCAT_LN-KEY = 'X'.
    FIELDCAT_LN-DO_SUM = SPACE.
      FIELDCAT_LN-COL_POS = 1.
      FIELDCAT_LN-NO_OUT = SPACE .
    FIELDCAT_LN-QFIELDNAME = SPACE.
      FIELDCAT_LN-HOTSPOT = SPACE.
      APPEND FIELDCAT_LN TO FIELDCAT.
    ENDFORM.                    "BUILD_FIELDCAT2
    *&      Form  BUILD_FIELDCAT3
          text
    FORM BUILD_FIELDCAT3.
      CLEAR FIELDCAT_LN.
    ADD 1 TO COL_POS.
      FIELDCAT_LN-REF_TABNAME = 'SPFLI'.
      FIELDCAT_LN-FIELDNAME = 'COUNTRYFR'.
    FIELDCAT_LN-REF_FIELDNAME = SPACE.
      FIELDCAT_LN-OUTPUTLEN = 20.
      FIELDCAT_LN-EMPHASIZE = 'C310'.
    FIELDCAT_LN-EMPHASIZE = 'X'.
    FIELDCAT_LN-EMPHASIZE = SPACE.
    FIELDCAT_LN-KEY = SPACE.
    FIELDCAT_LN-DO_SUM = 'X'.
      FIELDCAT_LN-COL_POS = 3.
      FIELDCAT_LN-NO_OUT = SPACE.
    FIELDCAT_LN-QFIELDNAME = SPACE.
    FIELDCAT_LN-HOTSPOT = SPACE.
      APPEND FIELDCAT_LN TO FIELDCAT.
    ENDFORM.                    "BUILD_FIELDCAT3
    FORM BUILD_FIELDCAT4.
      CLEAR FIELDCAT_LN.
    ADD 1 TO COL_POS.
      FIELDCAT_LN-REF_TABNAME = 'SPFLI'.
      FIELDCAT_LN-FIELDNAME = 'COUNTRYFR'.
    FIELDCAT_LN-REF_FIELDNAME = SPACE.
      FIELDCAT_LN-OUTPUTLEN = 20.
    FIELDCAT_LN-EMPHASIZE = 'C310'.
    FIELDCAT_LN-EMPHASIZE = 'X'.
    FIELDCAT_LN-EMPHASIZE = SPACE.
    FIELDCAT_LN-KEY = SPACE.
    FIELDCAT_LN-DO_SUM = 'X'.
      FIELDCAT_LN-COL_POS = 3.
      FIELDCAT_LN-NO_OUT = SPACE.
    FIELDCAT_LN-QFIELDNAME = SPACE.
    FIELDCAT_LN-HOTSPOT = SPACE.
      APPEND FIELDCAT_LN TO FIELDCAT.
    ENDFORM.                    "BUILD_FIELDCAT3
    *&      Form  BUILD_SORTCAT
          text
    FORM BUILD_SORTCAT.
      CLEAR SORTCAT_LN.
      SORTCAT_LN-SPOS = '1'.
      SORTCAT_LN-FIELDNAME = 'CONNID'.
      SORTCAT_LN-UP = 'X'..
    SORTCAT_LN-DOWN = SPACE.
      SORTCAT_LN-SUBTOT = 'X'.
      APPEND SORTCAT_LN TO SORTCAT.
    ENDFORM.                    "BUILD_SORTCAT
    *&      Form  BUILD_SORTCAT2
          text
    FORM BUILD_SORTCAT2.
      CLEAR SORTCAT_LN.
      SORTCAT_LN-SPOS = '2'.
      SORTCAT_LN-FIELDNAME = 'CARRID'.
    SORTCAT_LN-UP = SPACE.
      SORTCAT_LN-DOWN = 'X'.
    SORTCAT_LN-SUBTOT = SPACE.
      APPEND SORTCAT_LN TO SORTCAT.
    ENDFORM.                    " BUILD_SORTCAT2
    FORM BUILD_LAYOUT1.
      LAYOUT1-BOX_FIELDNAME = 'CHECK'.
      LAYOUT1-INFO_FIELDNAME = 'R_COLOR'.
      LAYOUT1-COLTAB_FIELDNAME = 'CELL'.
    ENDFORM.                    " BUILD_LAYOUT1
    *&      Form  BUILD_EVENTCAT
          text
    FORM BUILD_EVENTCAT.
      EVENTCAT_LN-NAME = 'TOP_OF_PAGE'.
      EVENTCAT_LN-FORM = 'PAGE_HEADER'.
      APPEND EVENTCAT_LN TO EVENTCAT.
    ENDFORM.                    "BUILD_EVENTCAT
    *&      Form  START_LIST_VIEWER
          text
    FORM START_LIST_VIEWER.
      DATA: PGM LIKE SY-REPID.
      PGM = SY-REPID.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
          EXPORTING
              I_INTERFACE_CHECK        = ' '
               I_CALLBACK_PROGRAM       = PGM
              i_callback_pf_status_set = ' '
            I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
              I_STRUCTURE_NAME         =
               IS_LAYOUT                = LAYOUT1
               IT_FIELDCAT              = FIELDCAT
              IT_EXCLUDING             =
              IT_SPECIAL_GROUPS        =
               IT_SORT                  = SORTCAT
              IT_FILTER                =
              IS_SEL_HIDE              =
              I_DEFAULT                = 'X'
              I_SAVE                   = 'A'
              IS_VARIANT               = ' '
              IT_EVENTS                =
              IT_EVENT_EXIT            =
              IS_PRINT                 =
              I_SCREEN_START_COLUMN    = 0
              I_SCREEN_START_LINE      = 0
              I_SCREEN_END_COLUMN      = 0
              I_SCREEN_END_LINE        = 0
         IMPORTING
              E_EXIT_CAUSED_BY_CALLER  =
              es_exit_caused_by_user   =
           TABLES
                T_OUTTAB                 = ISPFLI
           EXCEPTIONS
                PROGRAM_ERROR            = 1
                OTHERS                   = 2.
    ENDFORM.                    "START_LIST_VIEWER
    Hope you got it.
    <b>Reward points if it helps you.</b>
    Regds,
    Rama chary.Pammi

  • Is it possible to put colors while displaying report using ALVs?

    Gayathri

    hi
    i think the following code is the ur solution
    TABLES VBAK.
    TYPE-POOLS SLIS.
    * Data Declaration
    TYPES: BEGIN OF T_VBAK,
          VBELN TYPE VBAK-VBELN,
          ERDAT TYPE VBAK-ERDAT,
          ERNAM TYPE VBAK-ERNAM,
          AUDAT TYPE VBAK-AUDAT,
          VBTYP TYPE VBAK-VBTYP,
          NETWR TYPE VBAK-NETWR,
          VKORG TYPE VBAK-VKORG,
          VKGRP TYPE VBAK-VKGRP,
         <b> LINE_COLOR(4) TYPE C,</b>
          END OF T_VBAK.
    DATA: IT_VBAK TYPE STANDARD TABLE OF T_VBAK INITIAL SIZE 0,
          WA_VBAK TYPE T_VBAK.
    * ALV Data Declaration
    DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
          GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
          GD_REPID TYPE SY-REPID.
    *      I_EVENTS TYPE SLIS_T_EVENT,
    *      W_EVENTS LIKE LINE OF I_EVENTS.
    START-OF-SELECTION.
    PERFORM DATA_RETRIEVAL.
    PERFORM BLD_FLDCAT.
    PERFORM BLD_LAYOUT.
    PERFORM DISPLAY_ALV_REPORT.
    * Build Field Catalog for ALV Report
    FORM BLD_FLDCAT.
    FLDCAT-FIELDNAME = 'VBELN'.
    FLDCAT-SELTEXT_M = 'Sales Document'.
    FLDCAT-COL_POS = 0.
    *FLDCAT-EMPHASIZE = 'C411'.
    FLDCAT-OUTPUTLEN = 20.
    FLDCAT-KEY = 'X'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'ERDAT'.
    FLDCAT-SELTEXT_L = 'Record Date created'.
    FLDCAT-COL_POS = 1.
    FLDCAT-KEY = 'X'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'ERNAM'.
    FLDCAT-SELTEXT_L = 'Cteated Object Person Name'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'AUDAT'.
    FLDCAT-SELTEXT_M = 'Document Date'.
    FLDCAT-COL_POS = 3.
    FLDCAT-EMPHASIZE = 'C110'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'VBTYP'.
    FLDCAT-SELTEXT_L = 'SD Document category'.
    FLDCAT-COL_POS = 4.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'NETWR'.
    FLDCAT-SELTEXT_L = 'Net Value of the SO in Document Currency'.
    FLDCAT-COL_POS = 5.
    FLDCAT-OUTPUTLEN = 60.
    FLDCAT-DO_SUM = 'X'.
    FLDCAT-DATATYPE = 'CURR'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'VKORG'.
    FLDCAT-SELTEXT_L = 'Sales Organization'.
    FLDCAT-COL_POS = 6.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    FLDCAT-FIELDNAME = 'VKGRP'.
    FLDCAT-SELTEXT_M = 'Sales Group'.
    FLDCAT-COL_POS = 7.
    FLDCAT-EMPHASIZE = 'C801'.
    APPEND FLDCAT TO FLDCAT.
    CLEAR FLDCAT.
    ENDFORM.
    * Build Layout for ALV Grid Report
    FORM BLD_LAYOUT.
    GD_LAYOUT-NO_INPUT = 'X'.
    GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
    GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.
    GD_LAYOUT-WINDOW_TITLEBAR = 'GRID DISPLAY'.
    *GD_LAYOUT-TOTALS_TEXT = 'GRAND TOTAL'.
    ENDFORM.
    * Display report using ALV grid
    FORM DISPLAY_ALV_REPORT.
    DATA T_EVENT TYPE SLIS_T_EVENT.
    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
       I_LIST_TYPE           = 0
    IMPORTING
       ET_EVENTS             = T_EVENT.
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    GD_REPID = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM                = GD_REPID
       IS_LAYOUT                         = GD_LAYOUT
       I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
       I_GRID_TITLE                      = 'SALES DOCUMENT HEADER'
       IT_FIELDCAT                       = FLDCAT[]
       I_SAVE                            = 'X'
      TABLES
        T_OUTTAB                          = IT_VBAK
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2.
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.
    * Retrieve data from VBAK table and populate itab IT_VBAK
    FORM DATA_RETRIEVAL.
    <b>DATA LD_COLOR(1) TYPE C.</b>
    SELECT VBELN ERDAT ERNAM AUDAT VBTYP NETWR VKORG
    UP TO 20 ROWS
    FROM VBAK
    INTO TABLE IT_VBAK.
    <b>LOOP AT IT_VBAK INTO WA_VBAK.
    LD_COLOR = LD_COLOR + 1.
    IF LD_COLOR = 8.
      LD_COLOR = 1.
    ENDIF.
    CONCATENATE 'C' LD_COLOR '10' INTO WA_VBAK-LINE_COLOR.
    MODIFY IT_VBAK FROM WA_VBAK.
    ENDLOOP.</b>
    ENDFORM.
    FORM TOP_OF_PAGE.
    DATA: T_HEADER TYPE SLIS_T_LISTHEADER,
          W_HEADER TYPE SLIS_LISTHEADER.
    W_HEADER-TYP = 'H'.
    W_HEADER-INFO = 'WELCOME HEADER LIST'.
    APPEND W_HEADER TO T_HEADER.
    W_HEADER-TYP = 'S'.
    W_HEADER-KEY = 'REPORT:'.
    W_HEADER-INFO = SY-REPID.
    APPEND W_HEADER TO T_HEADER.
    W_HEADER-TYP = 'S'.
    W_HEADER-KEY = 'DATE:'.
    CONCATENATE SY-DATUM+6(2) ' / ' SY-DATUM+4(2) ' / ' SY-DATUM(4) INTO W_HEADER-INFO.
    APPEND W_HEADER TO T_HEADER.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY       = T_HEADER.
    ENDFORM.
    reward points,if it is useful

  • Color a cell in ALV using CL_GUI_ALV_GRID

    Hi,
    How to color a cell using CL_GUI_ALV_GRID?
    Thanks!

    Hi Ezachiael,
    you dont have to trigger event DOUBLE_CLICK, it will be triggered, in case of double click :-).
    You have to implent event handling class and event handler method - It is quite simple.
    Check out this [Reference on SDN|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907].
    Regards
    REA

  • SUBTOTAL USING LIST DISPLAY

    Hi,
    Is it possible to calculate subtotals using reuse_alv_list_display instead of using reuse_alv_grid_display.
    Also i want to print sub-headings using ALV.
    Ex:
    Under the column Mark
    i want the subject names as sub_heading.
                                      MARKS
    ENG          HINDI           MATHS              SCIENCE
    Like this i want output.
    Thanx in advance.

    HI Anitha
    Initially you need to have the following coloumns in your internal table
    CLASS
    ROLL NO.
    ENG
    HINDI
    MATHS
    SCIENCE
    Populate the internal table with values.
    Please refer for ALV output
    http://www.sap-partner.hu/ABAP_HELP_INFO/An%20Easy%20Reference%20for%20ALV%20Grid%20Control.pdf
    Code for your ALV
    CALL SCREEN 100.
    * SCREEN PROGRAM SHOULD CONTAIN
    PROCESS BEFORE OUTPUT.
      MODULE status_0100.
      MODULE create_alv.
    PROCESS AFTER INPUT.
      MODULE user_command_0100.
    * DOUBLE CLICK ON THESE MODULES AND DO THE FOLLOWING CODE
    MODULE status_0100 OUTPUT.
    * DOUBLE CLICK ON 'S_LIST1' AND CREATE PF-STATUS
      SET PF-STATUS 'S_LIST1'.
      SET TITLEBAR 'T1'.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    MODULE create_alv OUTPUT.
    DATA: alv_dock    TYPE REF TO cl_gui_docking_container,
          alv_grid    TYPE REF TO cl_gui_alv_grid,
          gt_fieldcat TYPE lvc_t_fcat,
          wa_fieldcat TYPE lvc_s_fcat,
          it_sort     TYPE lvc_t_sort,
          wa_sort     TYPE lvc_s_sort,
      CLEAR wa_fieldcat.
      wa_fieldcat-tabname       = ITAB
      wa_fieldcat-fieldname     = 'CLASS'.
      wa_fieldcat-outputlen     = '10'.
      APPEND wa_fieldcat TO gt_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-tabname       = ITAB
      wa_fieldcat-fieldname     = 'ID'.
      wa_fieldcat-outputlen     = '10'.
      APPEND wa_fieldcat TO gt_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-tabname       = ITAB
      wa_fieldcat-fieldname     = 'MATHS'.
      wa_fieldcat-outputlen     = '10'.
      APPEND wa_fieldcat TO gt_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-tabname       = ITAB
      wa_fieldcat-fieldname     = 'SCI'.
      wa_fieldcat-outputlen     = '10'.
      APPEND wa_fieldcat TO gt_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-tabname       = ITAB
      wa_fieldcat-fieldname     = 'SOCIAL'.
      wa_fieldcat-outputlen     = '10'.
      APPEND wa_fieldcat TO gt_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-tabname       = ITAB
      wa_fieldcat-fieldname     = 'ENG'.
      wa_fieldcat-outputlen     = '10'.
      APPEND wa_fieldcat TO gt_fieldcat.
      wa_layout-grid_title = sy-title.
      wa_layout-zebra      = 'X'.
      wa_layout-cwidth_opt = 'X'.
      wa_layout-sel_mode   = 'A'.
      wa_layout-info_fname = 'COLOR'.
      LOOP AT gt_fieldcat INTO wa_fieldcat.
        CASE wa_fieldcat-fieldname.
          WHEN 'CLASS' OR 'ID'.
           WHEN OTHERS.
            wa_fieldcat-do_sum = 'X'.
            MODIFY gt_fieldcat FROM wa_fieldcat.
        ENDCASE.
      ENDLOOP.
      wa_sort-fieldname = 'CLASS'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      wa_sort-down = space.
      APPEND wa_sort TO it_sort.
      CHECK alv_dock IS INITIAL.
      CREATE OBJECT alv_dock
        EXPORTING
          extension  = 1200
         EXCEPTIONS
           OTHERS    = 1.
      IF sy-subrc <> 0 AND sy-batch IS INITIAL.
        MESSAGE a016(pn) WITH 'Unable to create output area'(e01).
      ENDIF.
      CREATE OBJECT alv_grid
        EXPORTING
          i_parent      = alv_dock
       EXCEPTIONS
          OTHERS    = 1.
      IF sy-subrc <> 0 AND sy-batch IS INITIAL.
        MESSAGE a016(pn) WITH 'Unable to create output area'(e01).
      ENDIF.
      CALL METHOD alv_grid->set_table_for_first_display
          EXPORTING
            i_structure_name              = 'ZPS_NI_SAVING'
            is_layout                     = wa_layout
    *      it_toolbar_excluding          = t_ui_functions
          CHANGING
            it_outtab                     = it_output
            it_fieldcatalog               = gt_fieldcat
            it_sort                       = it_sort
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            OTHERS                        = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDMODULE.
    MODULE user_command_0100 INPUT.
      CASE ok_code.
        WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.
          CALL METHOD: alv_grid->free, alv_dock->free.
          FREE: alv_grid, alv_dock.
          SET SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT

  • How to print check boxes in output using alv

    send me replly immediately

    hi
    Program Name: ALV ON SECONDARY LISTS            Creation: 02/01/2007*
    SAP Name    : YH634_0102007_ALV_LIST            Application:        *
    Author      : P.V.D.Veeresh Babu                Type: 1             *
    Description : This program is used to display secondary lists using *
                  ALV.                                                  *
    Inputs:                                                             *
      Tables:                                                           *
        SPFLI - Flight information                                      *
        SFLIGHT - Flight                                                *
        SBOOK   - Flight booking details                                *
      Select options:                                                   *
        N/A                                                             *
      Parameters:                                                       *
        NO                                                              *
    Outputs: secondary lists with ALV                                   *
    External Routines                                                   *
      Function Modules:                                                 *
        REUSE_ALV_LIST_DISPLAY                                          *
      Transactions    : No                                              *
      Programs        : No                                              *
    Return Codes: No                                                    *
    Ammendments:                                                        *
       Programmer        Date     Req. #            Action              *
    ================  ==========  ======  ==============================*
    type-pools: slis.
    *" Data declarations...................................................
    Data declaration of the structure to hold layout details            *
    data:
      fs_layout type slis_layout_alv.
    *" Data declarations...................................................
    Data declaration of the structure to hold spfli details             *
    data: begin of fs_spfli,
            color(4) type c,               " Color
            check    type c.               " Check box
            include  structure spfli.      " Spfli
    data  end of fs_spfli.
    *" Data declarations...................................................
    Data declaration of the structure to hold sflight details           *
    data:begin of fs_sflight,
          color(4) type c,                 " Color
          check    type c.                 " Check box
          include  structure sflight.      " Sflight
    data  end of fs_sflight.
    *" Data declarations...................................................
    Data declaration of the structure to hold sbook details             *
    data:
      fs_sbook like sbook.
    Internal table to hold list details                                 *
    data:
      t_sbook like
    standard table
           of fs_sbook.
    Internal table to hold list details                                 *
    data:
      t_sflight like
       standard table
             of fs_sflight .
    Internal table to hold spfli details                                *
    data:
    t_spfli like
    standard table
    of fs_spfli.
    fs_layout-box_fieldname = 'CHECK'.
    fs_layout-info_fieldname = 'COLOR'.
    "........Retrieving basic list data containing spfli details......."
    select *
      from spfli
      into corresponding fields of table t_spfli.
    if sy-subrc ne 0.
      message text-001 type 'I'.
    endif.                                 " IF SY-SUBRC NE 0
    ".................Calling function module for ALV..................."
    call function 'REUSE_ALV_LIST_DISPLAY'
      exporting
        i_callback_program       = sy-repid
        i_callback_pf_status_set = 'STATUS1'
        i_callback_user_command  = 'USER_COMMAND1'
        i_structure_name         = 'SPFLI'
        is_layout                = fs_layout
      tables
        t_outtab                 = t_spfli
      exceptions
        program_error            = 1
        others                   = 2.
    if sy-subrc <> 0.
      message text-002 type 'I'.
    endif.                                 " IF SY-SUBRC NE 0
    Form  STATUS1                                                     *
    This subroutine gives pf-status for spfli list                    *
         -->T_EXTAB    excluding table                                 *
    form status1 using t_extab type slis_t_extab.
      set pf-status 'STATUS1'.
    endform.                               " STATUS1
    Form  USER_COMMAND1                                               *
    This subroutine displays secondary list containing sflight details*
         -->FS_UCOMM   user command                                    *
         -->T_SELFIELD selfield                                        *
    form user_command1 using fs_ucomm type sy-ucomm
                             t_selfield type slis_selfield.
      case fs_ucomm.
        when 'SFLIGHT'.
          perform display_list2.
      endcase.                             " CASE FS_UCOMM
      t_selfield-refresh = 'X'.
    endform.                               " USER_COMMAND1
    Form  DISPLAY_LIST2                                                *
    This subroutine displays sflight details on secondary list         *
    There are no interface parameters to be passed in this subroutine  *
    form display_list2 .
      data lw_flag type i.                 " Flag
      refresh t_sflight.
      loop at t_spfli into fs_spfli.
        if fs_spfli-check = 'X'.
    "........Retrieving basic list data containing sflight details......."
          select *
            from sflight
       appending corresponding fields of table t_sflight
           where carrid eq fs_spfli-carrid
             and connid eq fs_spfli-connid.
          if sy-subrc eq 0.
            lw_flag = 1.
          endif.                           " IF SY-SUBRC EQ 0
          FS_SPFLI-CHECK = '0'.
          fs_spfli-color = 'C510'.
          modify t_spfli from fs_spfli .
        endif.                             " IF FS_SPFLI-CHECK EQ 'X'
      endloop.                             " LOOP AT T_SPFLI INTO FS_SPFLI
      if lw_flag eq 0.
        message text-003 type 'E'.
      endif.                               " IF LW_FLAG EQ 1
    ".................Calling function module for ALV..................."
      call function 'REUSE_ALV_LIST_DISPLAY'
        exporting
          i_callback_program       = sy-repid
          i_callback_pf_status_set = 'STATUS2'
          i_callback_user_command  = 'USER_COMMAND2'
          i_structure_name         = 'SFLIGHT'
          is_layout                = fs_layout
        tables
          t_outtab                 = t_sflight
        exceptions
          program_error            = 1
          others                   = 2.
      if sy-subrc <> 0.
        message text-002 type 'I'.
      endif.                               " IF SY-SUBRC NE 0
    endform.                               " DISPLAY_LIST2
    Form  STATUS2                                                     *
    This subroutine gives pf-status for secondary list.               *
         -->T_EXTAB    Excluding table                                 *
    form status2 using t_extab type slis_t_extab.
      set pf-status 'STATUS2'.
    endform.                               " STATUS2
    Form  USER_COMMAND2                                               *
    This subroutine gives secondary list containing sbook details     *
         -->FS_UCOMM   user command                                    *
         -->T_SELFIELD selfield                                        *
    form user_command2 using fs_ucomm type sy-ucomm
                             t_selfield type slis_selfield.
      case fs_ucomm.
        when 'SBOOK'.
          perform display_list3.
      endcase.                             " CASE FS_UCOMM
      t_selfield-refresh = 'X'.
    endform.                               " USER_COMMAND2
    Form  DISPLAY_LIST3                                                *
    This subroutine displays sbook details on secondary list           *
    There are no interface parameters to be passed in this subroutine  *
    form display_list3 .
      data lw_flag type i.                 " Flag
      refresh t_sbook.
      loop at t_sflight into fs_sflight.
        if fs_sflight-check eq 'X'.
    "........Retrieving basic list data containing sbook details......."
          select *
            from sbook
       appending corresponding fields of table t_sbook
           where carrid eq fs_sflight-carrid
             and connid eq fs_sflight-connid
             and fldate eq fs_sflight-fldate.
          if sy-subrc eq 0.
            lw_flag = 1.
          endif.                           " IF SY-SUBRC EQ 0
          FS_SFLIGHT-CHECK = '0'.
          fs_sflight-color = 'C910'.
          modify  t_sflight from fs_sflight.
        endif.                             " IF FS_FLIGHT-CHECK EQ 'X'
      endloop.                             " LOOP AT T_SFLIGHT INTO....
      if lw_flag eq 0.
        message text-004 type 'E'.
      endif.                               " IF LW_FLAG EQ 1
    ".................Calling function module for ALV..................."
      call function 'REUSE_ALV_LIST_DISPLAY'
        exporting
          i_structure_name = 'SBOOK'
          is_layout        = fs_layout
        tables
          t_outtab         = t_sbook
        exceptions
          program_error    = 1
          others           = 2.
      if sy-subrc <> 0.
        message text-002 type 'I'.
      endif.                               " IF SY-SUBRC NE 0
    endform.                               " DISPLAY_LIST3
    regards,
    veeresh
    null

  • How to color a line in ALV Dispaly

    Hi Abaper,
    As of my requirement i want to display output of the report for certain lines in a color iam using ALV method,
    Plz help me ASAP
    answer will be reward.
    Thanks in advance
    hema

    Hi Hema..
    this is The code for Applying the colors For Lines or Cells also..
    report  yacpr0007.
    This must be included in order to create the fieldcatalog.
    type-pools: slis.
    parameters: p_dummy type c.
    types: begin of ty_data,
             select type c,
             f1 type i,
             f2 type i,
             f3 type i,
             color_line(4) type c, " Line color
             color_cell type lvc_t_scol, " Cell color
           end of ty_data.
    constants: c_true  type boolean_flg value 'X',
               c_false type boolean_flg value space.
    data: i_data type table of ty_data,
          i_field_cat type slis_t_fieldcat_alv,
          s_layout    type slis_layout_alv.
    start-of-selection.
      perform f_create_field_cat.
      perform f_set_layout.
      perform f_create_data.
    end-of-selection.
      perform f_display_grid.
    *&      @FORMS
    *&      Form  f_create_data
    Create some sample data.
    form f_create_data.
      data: lw_data type ty_data,
            lw_color_cell like line of lw_data-color_cell.
      do 15 times.
        clear lw_data.
        lw_data-f1 = sy-index.
        case sy-index.
          when 3.
    **/ Set the row or cell to color
            lw_data-color_line = 'C410'.
          when 8.
            lw_color_cell-color-col = 6.
            lw_color_cell-fname = 'F1'.
            append lw_color_cell to lw_data-color_cell. "/ .
        endcase.
        lw_data-f2 = sy-index * 2.
        lw_data-f3 = lw_data-f1 + lw_data-f2.
        append lw_data to i_data.
      enddo.
    endform.                    "f_create_data
    *&      Form  f_create_field_cat
      Create the fieldcatalog.  This needs to contain a minimum of
      the names of the fields you wish to display.  However there are
      numerous other things which can be added such as position, colour etc.
    form f_create_field_cat.
    **/ Add data to the field catalog
      perform f_append_row using: 'F1' 'field one' 3,
                                  'F2' 'field two' 2,
                                  'F3' 'field three' 1.  "/ .
    endform.                    "f_create_field_cat
    *&      Form  f_append_row
    Append a single row to the field catalog.
         -->L_NAME     The name of the field to be added.
         -->L_DESC     The description for the column heading.
         -->L_POS      The column number for the field.
    form f_append_row using pv_name pv_desc pv_pos.
      data: lw_field_cat like line of i_field_cat.
    **/ Append the field catalog record.
      lw_field_cat-fieldname = pv_name.
      lw_field_cat-seltext_l = pv_desc.
      lw_field_cat-col_pos = pv_pos.
      append lw_field_cat to i_field_cat. "/ .
    endform.                    "f_append_row
    *&      Form  f_set_layout
    Set the layout including the field names used to indicate the
    cells or rows should be coloured.
    form f_set_layout.
      s_layout-colwidth_optimize = space.
      s_layout-no_colhead = space.
      s_layout-zebra = space.
      s_layout-no_vline = space.
    **/ Field that identify color line in internal table
      s_layout-info_fieldname = 'COLOR_LINE'.
    Field that identify cell color in inetrnal table
      s_layout-coltab_fieldname = 'COLOR_CELL'. "/ .
    endform.                    "f_create_layout
    *&      Form  f_display_grid
    Call the function to display the grid.
    form f_display_grid.
    **/ You need to pass in a minimum of the fieldcatalog and the table of data
      call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
      I_CALLBACK_PROGRAM                = ' '
      I_CALLBACK_PF_STATUS_SET          = ' '
      I_CALLBACK_USER_COMMAND           = ' '
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
       is_layout                         = s_layout
    **/ the field catalog.  Tells SAP what to display
       it_fieldcat                       = i_field_cat
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      I_HTML_HEIGHT_TOP                 =
      I_HTML_HEIGHT_END                 =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
    **/ The table of data and exceptions
        tables
          t_outtab                          = i_data
       exceptions
         program_error                     = 1
         others                            = 2
      if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
    endform.                    "f_display_grid
    <b>reward if Helpful</b>

  • How to color a row using REUSE_ALV_HIERSEQ_LIST_DISPLAY

    Hi,
    I'm able to color a row using REUSE_ALV_GRID_DISPLAY, I tried the same way to color a row at the item level using 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' but I'm not able to get the row color, please let me know how to acheive this.
    Thanks in Advnce
    Narayan

    you need to do 4 things.
    1. Add a field in your final internal table which ur going to display.
    2.Name the field as----
    > color_line(4)   TYPE  c,
                begin of itab,
                              matnr            type  mara-matnr,
                              ernam          type  mara-ernam,
                           color_line(4)   TYPE  c,
               end of itab.
    3.declare layout ....................> data :  it_layout   TYPE lvc_s_layo.
    4. After filled your fieldcat and before display your ALV
            loop at itab assigning to <itab>.
                          if <itab>-ernam eq 'XYZ'.
                          <itab>-color_line = 'C600'.
           end loop.
    it_layout-info_fname = 'COLOR_LINE'.
    CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    exporting
        IS_LAYOUT                      = it_layout
        IT_FIELDCAT                    = your_fieldcat
      and pass ur  ITAB.

  • How to display subtotal in ALV, where the field is not a numeric.

    Hi
    We are having a requirement to display the sub total for a field using ALV grid display, where the field is not numeric.
    The field is characte, Status field(consists of values Submit, Approve ,Reject), where the subtotal should be value of count of group by status .
    say status with submit are 10 records, so after all records with submit status are, displyed, we need to display its subtotal as 10.
    Thanks & Advance

    Hi Satya,
    REPORT z_alv_subtotal.*&---------------------------------------------------------------------*
    *& Table declaration
    *&---------------------------------------------------------------------*TABLES: ekko.*&---------------------------------------------------------------------*
    *& Type pool declaration
    TYPE-POOLS: slis. " Type pool for ALV*&---------------------------------------------------------------------*
    *& Selection screen
    SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.*&---------------------------------------------------------------------*
    *& Type declaration
    *&---------------------------------------------------------------------** Type declaration for internal table to store EKPO data
    TYPES: BEGIN OF x_data,
           ebeln  TYPE char30,  " Document no.
           ebelp  TYPE ebelp,   " Item no
           matnr  TYPE matnr,   " Material no
           matnr1 TYPE matnr,   " Material no
           werks  TYPE werks_d, " Plant
           werks1 TYPE werks_d, " Plant
           ntgew  TYPE entge,   " Net weight
           gewe   TYPE egewe,   " Unit of weight                          
           END OF x_data.*&---------------------------------------------------------------------*
    *& Internal table declaration
    DATA:* Internal table to store EKPO data
      i_ekpo TYPE STANDARD TABLE OF x_data INITIAL SIZE 0,
    * Internal table for storing field catalog information
      i_fieldcat TYPE slis_t_fieldcat_alv,
    * Internal table for Top of Page info. in ALV Display
      i_alv_top_of_page TYPE slis_t_listheader,
    * Internal table for ALV Display events
      i_events TYPE slis_t_event,
    * Internal table for storing ALV sort information
      i_sort TYPE  slis_t_sortinfo_alv,
      i_event TYPE slis_t_event.*&---------------------------------------------------------------------*
    *& Work area declaration
    *&---------------------------------------------------------------------*DATA:
      wa_ekko TYPE x_data,
      wa_layout     TYPE slis_layout_alv,
      wa_events         TYPE slis_alv_event,
      wa_sort TYPE slis_sortinfo_alv.*&---------------------------------------------------------------------*
    *& Constant declaration
    *&---------------------------------------------------------------------*CONSTANTS:
       c_header   TYPE char1
                  VALUE 'H',                    "Header in ALV
       c_item     TYPE char1
                  VALUE 'S'.*&---------------------------------------------------------------------*
    *& Start-of-selection event
    *&---------------------------------------------------------------------*START-OF-SELECTION.* Select data from ekpo
      SELECT ebeln " Doc no
             ebelp " Item
             matnr " Material
             matnr " Material
             werks " Plant
             werks " Plant
             ntgew " Quantity
             gewei " Unit
             FROM ekpo
             INTO TABLE i_ekpo
             WHERE ebeln IN s_ebeln
             AND ntgew NE '0.00'.  IF sy-subrc = 0.
        SORT i_ekpo BY ebeln ebelp matnr .
      ENDIF.* To build the Page header
      PERFORM sub_build_header.* To prepare field catalog
      PERFORM sub_field_catalog.* Perform to populate the layout structure
      PERFORM sub_populate_layout.* Perform to populate the sort table.
      PERFORM sub_populate_sort.* Perform to populate ALV event
      PERFORM sub_get_event.END-OF-SELECTION.* Perform to display ALV report
      PERFORM sub_alv_report_display.
    *&      Form  sub_build_header
    *       To build the header
    *       No Parameter
    FORM sub_build_header .* Local data declaration
      DATA: l_system     TYPE char10 ,          "System id
            l_r_line     TYPE slis_listheader,  "Hold list header
            l_date       TYPE char10,           "Date
            l_time       TYPE char10,           "Time
            l_success_records TYPE i,           "No of success records
            l_title(300) TYPE c.                " Title
    * Title  Display
      l_r_line-typ = c_header.               " header
      l_title = 'Test report'(001).
      l_r_line-info = l_title.
      APPEND l_r_line TO i_alv_top_of_page.
      CLEAR l_r_line.* Run date Display
      CLEAR l_date.
      l_r_line-typ  = c_item.                " Item
      WRITE: sy-datum  TO l_date MM/DD/YYYY.
      l_r_line-key = 'Run Date :'(002).
      l_r_line-info = l_date.
      APPEND l_r_line TO i_alv_top_of_page.
      CLEAR: l_r_line,
             l_date.ENDFORM.                    " sub_build_header
    *&      Form  sub_field_catalog
    *       Build Field Catalog
    *       No Parameter
    FORM sub_field_catalog .*  Build Field Catalog
      PERFORM sub_fill_alv_field_catalog USING:     '01' '01' 'EBELN' 'I_EKPO' 'L'
         'Doc No'(003) ' ' ' ' ' ' ' ',     '01' '02' 'EBELP' 'I_EKPO' 'L'
         'Item No'(004) 'X' 'X' ' ' ' ',     '01' '03' 'MATNR' 'I_EKPO' 'L'
         'Material No'(005) 'X' 'X' ' ' ' ',     '01' '03' 'MATNR1' 'I_EKPO' 'L'
         'Material No'(005) ' ' ' ' ' ' ' ',
         '01' '04' 'WERKS' 'I_EKPO' 'L'
         'Plant'(006) 'X' 'X' ' ' ' ',     '01' '04' 'WERKS1' 'I_EKPO' 'L'
         'Plant'(006) ' ' ' ' ' ' ' ',     '01' '05' 'NTGEW' 'I_EKPO' 'R'
         'Net Weight'(007) ' ' ' ' 'GEWE' 'I_EKPO'.ENDFORM.                    " sub_field_catalog*&---------------------------------------------------------------------*
    *&     Form  sub_fill_alv_field_catalog
    *&     For building Field Catalog
    *&     p_rowpos   Row position
    *&     p_colpos   Col position
    *&     p_fldnam   Fldname
    *&     p_tabnam   Tabname
    *&     p_justif   Justification
    *&     p_seltext  Seltext
    *&     p_out      no out
    *&     p_tech     Technical field
    *&     p_qfield   Quantity field
    *&     p_qtab     Quantity table
    FORM sub_fill_alv_field_catalog  USING  p_rowpos    TYPE sycurow
                                            p_colpos    TYPE sycucol
                                            p_fldnam    TYPE fieldname
                                            p_tabnam    TYPE tabname
                                            p_justif    TYPE char1
                                            p_seltext   TYPE dd03p-scrtext_l
                                            p_out       TYPE char1
                                            p_tech      TYPE char1
                                            p_qfield    TYPE slis_fieldname
                                            p_qtab      TYPE slis_tabname.* Local declaration for field catalog
      DATA: wa_lfl_fcat    TYPE  slis_fieldcat_alv.  wa_lfl_fcat-row_pos        =  p_rowpos.     "Row
      wa_lfl_fcat-col_pos        =  p_colpos.     "Column
      wa_lfl_fcat-fieldname      =  p_fldnam.     "Field Name
      wa_lfl_fcat-tabname        =  p_tabnam.     "Internal Table Name
      wa_lfl_fcat-just           =  p_justif.     "Screen Justified
      wa_lfl_fcat-seltext_l      =  p_seltext.    "Field Text
      wa_lfl_fcat-no_out         =  p_out.        "No output
      wa_lfl_fcat-tech           =  p_tech.       "Technical field
      wa_lfl_fcat-qfieldname     =  p_qfield.     "Quantity unit
      wa_lfl_fcat-qtabname       =  p_qtab .      "Quantity table  IF p_fldnam = 'NTGEW'.
        wa_lfl_fcat-do_sum  = 'X'.
      ENDIF.
      APPEND wa_lfl_fcat TO i_fieldcat.
      CLEAR wa_lfl_fcat.
    ENDFORM.                    " sub_fill_alv_field_catalog*&---------------------------------------------------------------------*
    *&      Form  sub_populate_layout
    *       Populate ALV layout
    *       No Parameter
    FORM sub_populate_layout .  CLEAR wa_layout.
      wa_layout-colwidth_optimize = 'X'." Optimization of Col widthENDFORM.                    " sub_populate_layout*&---------------------------------------------------------------------*
    *&      Form  sub_populate_sort
    *       Populate ALV sort table
    *       No Parameter
    FORM sub_populate_sort .* Sort on material
      wa_sort-spos = '01' .
      wa_sort-fieldname = 'MATNR'.
      wa_sort-tabname = 'I_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO i_sort .
      CLEAR wa_sort.* Sort on plant
      wa_sort-spos = '02'.
      wa_sort-fieldname = 'WERKS'.
      wa_sort-tabname = 'I_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO i_sort .
      CLEAR wa_sort.
    ENDFORM.                    " sub_populate_sort*&---------------------------------------------------------------------*
    *&      Form  sub_get_event
    *       Get ALV grid event and pass the form name to subtotal_text
    *       event
    *       No Parameter
    FORM sub_get_event .
      CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE
    'SUBTOTAL_TEXT'.  DATA: l_s_event TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 4
        IMPORTING
          et_events       = i_event
        EXCEPTIONS
          list_type_wrong = 0
          OTHERS          = 0.* Subtotal
      READ TABLE i_event  INTO l_s_event
                        WITH KEY name = slis_ev_subtotal_text.
      IF sy-subrc = 0.
        MOVE c_formname_subtotal_text TO l_s_event-form.
        MODIFY i_event FROM l_s_event INDEX sy-tabix.
      ENDIF.ENDFORM.                    " sub_get_event*&---------------------------------------------------------------------*
    *&      Form  sub_alv_report_display
    *       For ALV Report Display
    *       No Parameter
    FORM sub_alv_report_display .
      DATA: l_repid TYPE syrepid .
      l_repid = sy-repid .* This function module for displaying the ALV report
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = l_repid
          i_callback_top_of_page   = 'SUB_ALV_TOP_OF_PAGE'
          is_layout                = wa_layout
          it_fieldcat              = i_fieldcat
          it_sort = i_sort
          it_events                = i_event
          i_default                = 'X'
          i_save                   = 'A'
        TABLES
          t_outtab                 = i_ekpo
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
    *    MESSAGE i000 WITH 'Error in ALV report display'(055).
      ENDIF.ENDFORM.                    " sub_alv_report_display*&---------------------------------------------------------------------*
    *       FORM sub_alv_top_of_page
    *       Call ALV top of page
    *       No parameter
    *---------------------------------------------------------------------*FORM sub_alv_top_of_page.                                   "#EC CALLED* To write header for the ALV
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = i_alv_top_of_page.
    ENDFORM.                    "alv_top_of_page*&---------------------------------------------------------------------*
    *&      Form  subtotal_text
    *       Build subtotal text
    *       P_total  Total
    *       p_subtot_text Subtotal text info
    FORM subtotal_text CHANGING
                   p_total TYPE any
                   p_subtot_text TYPE slis_subtot_text.
    * Material level sub total
      IF p_subtot_text-criteria = 'MATNR'.
        p_subtot_text-display_text_for_subtotal
        = 'Material level total'(009).
      ENDIF.* Plant level sub total
      IF p_subtot_text-criteria = 'WERKS'.
        p_subtot_text-display_text_for_subtotal = 'Plant level total'(010).
      ENDIF.
    ENDFORM.                    "subtotal_text
    Regards,
    Pravin

  • Subtotal in alv grid output.

    hi experts,
                   i want to display subtotal in the alv output using control break statement, without using alv functionality and layout.
    my code is given below, how can i add subtotal field and display them in alv ,
    *& Report  Y_VARUNSHARMA
    REPORT  Y_VARUNSHARMA.
    TABLES: VBAK.
    TYPE-POOLS: SLIS.
    TYPES: BEGIN OF T_ITAB,
           VBELN LIKE VBAK-VBELN,
           ERDAT LIKE VBAK-ERDAT,
           ERNAM LIKE VBAK-ERNAM,
           ANGDT LIKE VBAK-ANGDT,
           BNDDT LIKE VBAK-BNDDT,
           AUART LIKE VBAK-AUART,
           POSNR LIKE VBAP-POSNR,
           MATNR LIKE VBAP-MATNR,
           CHARG LIKE VBAP-CHARG,
           MAKTX LIKE MAKT-MAKTX,
           NETPR LIKE VBAP-NETPR,
           VGBEL LIKE VBAK-VGBEL,
           MEINS LIKE VBAP-MEINS,
           SMENG LIKE VBAP-SMENG,
            END OF T_ITAB.
    DATA: G_REPID LIKE SY-REPID.
    DATA: WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
    DATA: I_ITAB TYPE T_ITAB OCCURS 0,
          WA_ITAB TYPE T_ITAB.
    DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV ,
          WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
    DATA: I_LISTHEADER TYPE SLIS_T_LISTHEADER,
          WA_LISTHEADER TYPE SLIS_LISTHEADER.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: DOCNO FOR VBAK-VBELN.
    PARAMETER DOCTYPE LIKE VBAK-AUART.
    SELECT-OPTIONS: DATE FOR SY-DATUM.
    SELECTION-SCREEN SKIP 2.
    PARAMETER P_CHECK AS CHECKBOX.
    SELECTION-SCREEN END OF BLOCK B1.
    INITIALIZATION.
    G_REPID = SY-REPID.
    PERFORM BUILD_CATALOGE.
    PERFORM LIST_HEADER.
    PERFORM SET_LAYOUT.
    AT SELECTION-SCREEN.
    IF DOCNO-LOW = '' .
    MESSAGE E000(ZVARUN) .
    elseif DOCNO-HIGH = '' .
    MESSAGE E001(ZVARUN) .
    ENDIF.
    START-OF-SELECTION.
    PERFORM GET_DATA.
    *PERFORM DISPLAY.
    END-OF-SELECTION.
    IF P_CHECK = 'X'.
    PERFORM DOWNLOAD_EXCEL.
    ELSE.
    PERFORM DISPLAY.
    ENDIF.
    FORM DOWNLOAD_EXCEL.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
      BIN_FILESIZE                    =
        FILENAME                        = 'C:\FILE.XLS'
      FILETYPE                        = 'XLS'
      APPEND                          = ' '
      WRITE_FIELD_SEPARATOR           = ' '
      HEADER                          = '00'
      TRUNC_TRAILING_BLANKS           = ' '
      WRITE_LF                        = 'X'
      COL_SELECT                      = ' '
      COL_SELECT_MASK                 = ' '
      DAT_MODE                        = ' '
      CONFIRM_OVERWRITE               = ' '
      NO_AUTH_CHECK                   = ' '
      CODEPAGE                        = ' '
      IGNORE_CERR                     = ABAP_TRUE
      REPLACEMENT                     = '#'
      WRITE_BOM                       = ' '
      TRUNC_TRAILING_BLANKS_EOL       = 'X'
      WK1_N_FORMAT                    = ' '
      WK1_N_SIZE                      = ' '
      WK1_T_FORMAT                    = ' '
      WK1_T_SIZE                      = ' '
    IMPORTING
      FILELENGTH                      =
      TABLES
        DATA_TAB                        = I_ITAB
      FIELDNAMES                      =
    EXCEPTIONS
      FILE_WRITE_ERROR                = 1
      NO_BATCH                        = 2
      GUI_REFUSE_FILETRANSFER         = 3
      INVALID_TYPE                    = 4
      NO_AUTHORITY                    = 5
      UNKNOWN_ERROR                   = 6
      HEADER_NOT_ALLOWED              = 7
      SEPARATOR_NOT_ALLOWED           = 8
      FILESIZE_NOT_ALLOWED            = 9
      HEADER_TOO_LONG                 = 10
      DP_ERROR_CREATE                 = 11
      DP_ERROR_SEND                   = 12
      DP_ERROR_WRITE                  = 13
      UNKNOWN_DP_ERROR                = 14
      ACCESS_DENIED                   = 15
      DP_OUT_OF_MEMORY                = 16
      DISK_FULL                       = 17
      DP_TIMEOUT                      = 18
      FILE_NOT_FOUND                  = 19
      DATAPROVIDER_EXCEPTION          = 20
      CONTROL_FLUSH_ERROR             = 21
      OTHERS                          = 22
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.
    FORM BUILD_CATALOGE.
    WA_FIELDCAT-FIELDNAME = 'VBELN'.
    WA_FIELDCAT-SELTEXT_M = 'SALES DOC'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'ERDAT'.
    WA_FIELDCAT-SELTEXT_M = 'DATE'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'ERNAM'.
    WA_FIELDCAT-SELTEXT_M = 'NAME'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'ANGDT'.
    WA_FIELDCAT-SELTEXT_M = 'VALID FR'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'BNDDT'.
    WA_FIELDCAT-SELTEXT_M = 'VALID TO'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'AUART'.
    WA_FIELDCAT-SELTEXT_M = 'DOC TYPE'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'POSNR'.
    WA_FIELDCAT-SELTEXT_M = 'DOC ITEM'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'MATNR'.
    WA_FIELDCAT-SELTEXT_M = 'MATERIAL NO'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'CHARG'.
    WA_FIELDCAT-SELTEXT_M = 'BATCH NO'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'MAKTX'.
    WA_FIELDCAT-SELTEXT_M = 'MATERIAL DESC'.
    WA_FIELDCAT-EDIT = 'X'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'NETPR'.
    WA_FIELDCAT-SELTEXT_M = 'UNIT PRICE'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'VGBEL'.
    WA_FIELDCAT-SELTEXT_M = 'RFR DOC NO'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'MEINS'.
    WA_FIELDCAT-SELTEXT_M = 'UNIT'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'SMENG'.
    WA_FIELDCAT-SELTEXT_M = 'QUANTITY'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    ENDFORM.
    FORM LIST_HEADER.
    WA_LISTHEADER-TYP = 'H'.
    WA_LISTHEADER-INFO = 'RJT COMPUSOLUTIONS'.
    APPEND WA_LISTHEADER TO I_LISTHEADER.
    CLEAR WA_LISTHEADER.
    ENDFORM.
    FORM SET_LAYOUT.
    WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
    ENDFORM.
    FORM DISPLAY.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
       I_CALLBACK_PROGRAM                = G_REPID
      I_CALLBACK_PF_STATUS_SET          = ' '
       I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
       I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
       IS_LAYOUT                         = WA_LAYOUT
       IT_FIELDCAT                       = I_FIELDCAT[]
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
      TABLES
        T_OUTTAB                          = I_ITAB
    EXCEPTIONS
      PROGRAM_ERROR                     = 1
      OTHERS                            = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.
    FORM TOP_OF_PAGE.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY       = I_LISTHEADER
       I_LOGO                   = 'RJT'
      I_END_OF_LIST_GRID       =
      I_ALV_FORM               =
    ENDFORM.
    FORM GET_DATA.
    SELECT AVBELN AERDAT AERNAM AANGDT ABNDDT AAUART AVGBEL BPOSNR BMATNR BCHARG BMEINS BSMENG BNETPR CMAKTX  INTO CORRESPONDING FIELDS OF TABLE I_ITAB FROM  ( ( VBAK AS A INNER JOIN VBAP AS B
    ON AVBELN = BVBELN ) INNER JOIN MAKT AS C  ON BMATNR = CMATNR )  WHERE AVBELN IN DOCNO AND AAUART = DOCTYPE .
    ENDFORM.
    FORM USER_COMMAND USING L_UCOMM LIKE SY-UCOMM L_SELFIELD TYPE SLIS_SELFIELD.
    CASE L_UCOMM.
    WHEN '&IC1'.
    IF L_SELFIELD-FIELDNAME  = 'VBELN'.
    CALL TRANSACTION 'VA02'.
    ELSEIF
    L_SELFIELD-FIELDNAME = 'MATNR'.
    CALL TRANSACTION 'MM02'.
    ENDIF.
    ENDCASE.
    ENDFORM.

    Hi,
    That I guess is difficult. Only way is to append a new line with your subtotal to the output table with the subtotal filled in appro. field.
    Santhosh

  • Subtotal in alv

    hi experts,
                   i want to display subtotal in the alv output using control break statement, without using alv functionality and layout.
    my code is given below, how can i add subtotal field and display them in alv ,
    *& Report  Y_VARUNSHARMA
    REPORT  Y_VARUNSHARMA.
    TABLES: VBAK.
    TYPE-POOLS: SLIS.
    TYPES: BEGIN OF T_ITAB,
           VBELN LIKE VBAK-VBELN,
           ERDAT LIKE VBAK-ERDAT,
           ERNAM LIKE VBAK-ERNAM,
           ANGDT LIKE VBAK-ANGDT,
           BNDDT LIKE VBAK-BNDDT,
           AUART LIKE VBAK-AUART,
           POSNR LIKE VBAP-POSNR,
           MATNR LIKE VBAP-MATNR,
           CHARG LIKE VBAP-CHARG,
           MAKTX LIKE MAKT-MAKTX,
           NETPR LIKE VBAP-NETPR,
           VGBEL LIKE VBAK-VGBEL,
           MEINS LIKE VBAP-MEINS,
           SMENG LIKE VBAP-SMENG,
            END OF T_ITAB.
    DATA: G_REPID LIKE SY-REPID.
    DATA: WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
    DATA: I_ITAB TYPE T_ITAB OCCURS 0,
          WA_ITAB TYPE T_ITAB.
    DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV ,
          WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
    DATA: I_LISTHEADER TYPE SLIS_T_LISTHEADER,
          WA_LISTHEADER TYPE SLIS_LISTHEADER.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: DOCNO FOR VBAK-VBELN.
    PARAMETER DOCTYPE LIKE VBAK-AUART.
    SELECT-OPTIONS: DATE FOR SY-DATUM.
    SELECTION-SCREEN SKIP 2.
    PARAMETER P_CHECK AS CHECKBOX.
    SELECTION-SCREEN END OF BLOCK B1.
    INITIALIZATION.
    G_REPID = SY-REPID.
    PERFORM BUILD_CATALOGE.
    PERFORM LIST_HEADER.
    PERFORM SET_LAYOUT.
    AT SELECTION-SCREEN.
    IF DOCNO-LOW = '' .
    MESSAGE E000(ZVARUN) .
    elseif DOCNO-HIGH = '' .
    MESSAGE E001(ZVARUN) .
    ENDIF.
    START-OF-SELECTION.
    PERFORM GET_DATA.
    *PERFORM DISPLAY.
    END-OF-SELECTION.
    IF P_CHECK = 'X'.
    PERFORM DOWNLOAD_EXCEL.
    ELSE.
    PERFORM DISPLAY.
    ENDIF.
    FORM DOWNLOAD_EXCEL.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
      BIN_FILESIZE                    =
        FILENAME                        = 'C:\FILE.XLS'
      FILETYPE                        = 'XLS'
      APPEND                          = ' '
      WRITE_FIELD_SEPARATOR           = ' '
      HEADER                          = '00'
      TRUNC_TRAILING_BLANKS           = ' '
      WRITE_LF                        = 'X'
      COL_SELECT                      = ' '
      COL_SELECT_MASK                 = ' '
      DAT_MODE                        = ' '
      CONFIRM_OVERWRITE               = ' '
      NO_AUTH_CHECK                   = ' '
      CODEPAGE                        = ' '
      IGNORE_CERR                     = ABAP_TRUE
      REPLACEMENT                     = '#'
      WRITE_BOM                       = ' '
      TRUNC_TRAILING_BLANKS_EOL       = 'X'
      WK1_N_FORMAT                    = ' '
      WK1_N_SIZE                      = ' '
      WK1_T_FORMAT                    = ' '
      WK1_T_SIZE                      = ' '
    IMPORTING
      FILELENGTH                      =
      TABLES
        DATA_TAB                        = I_ITAB
      FIELDNAMES                      =
    EXCEPTIONS
      FILE_WRITE_ERROR                = 1
      NO_BATCH                        = 2
      GUI_REFUSE_FILETRANSFER         = 3
      INVALID_TYPE                    = 4
      NO_AUTHORITY                    = 5
      UNKNOWN_ERROR                   = 6
      HEADER_NOT_ALLOWED              = 7
      SEPARATOR_NOT_ALLOWED           = 8
      FILESIZE_NOT_ALLOWED            = 9
      HEADER_TOO_LONG                 = 10
      DP_ERROR_CREATE                 = 11
      DP_ERROR_SEND                   = 12
      DP_ERROR_WRITE                  = 13
      UNKNOWN_DP_ERROR                = 14
      ACCESS_DENIED                   = 15
      DP_OUT_OF_MEMORY                = 16
      DISK_FULL                       = 17
      DP_TIMEOUT                      = 18
      FILE_NOT_FOUND                  = 19
      DATAPROVIDER_EXCEPTION          = 20
      CONTROL_FLUSH_ERROR             = 21
      OTHERS                          = 22
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.
    FORM BUILD_CATALOGE.
    WA_FIELDCAT-FIELDNAME = 'VBELN'.
    WA_FIELDCAT-SELTEXT_M = 'SALES DOC'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'ERDAT'.
    WA_FIELDCAT-SELTEXT_M = 'DATE'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'ERNAM'.
    WA_FIELDCAT-SELTEXT_M = 'NAME'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'ANGDT'.
    WA_FIELDCAT-SELTEXT_M = 'VALID FR'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'BNDDT'.
    WA_FIELDCAT-SELTEXT_M = 'VALID TO'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'AUART'.
    WA_FIELDCAT-SELTEXT_M = 'DOC TYPE'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'POSNR'.
    WA_FIELDCAT-SELTEXT_M = 'DOC ITEM'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'MATNR'.
    WA_FIELDCAT-SELTEXT_M = 'MATERIAL NO'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'CHARG'.
    WA_FIELDCAT-SELTEXT_M = 'BATCH NO'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'MAKTX'.
    WA_FIELDCAT-SELTEXT_M = 'MATERIAL DESC'.
    WA_FIELDCAT-EDIT = 'X'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'NETPR'.
    WA_FIELDCAT-SELTEXT_M = 'UNIT PRICE'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'VGBEL'.
    WA_FIELDCAT-SELTEXT_M = 'RFR DOC NO'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'MEINS'.
    WA_FIELDCAT-SELTEXT_M = 'UNIT'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    WA_FIELDCAT-FIELDNAME = 'SMENG'.
    WA_FIELDCAT-SELTEXT_M = 'QUANTITY'.
    *WA_FIELDCAT-OUTPUTLEN = 10.
    APPEND WA_FIELDCAT TO I_FIELDCAT.
    CLEAR WA_FIELDCAT.
    ENDFORM.
    FORM LIST_HEADER.
    WA_LISTHEADER-TYP = 'H'.
    WA_LISTHEADER-INFO = 'RJT COMPUSOLUTIONS'.
    APPEND WA_LISTHEADER TO I_LISTHEADER.
    CLEAR WA_LISTHEADER.
    ENDFORM.
    FORM SET_LAYOUT.
    WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
    ENDFORM.
    FORM DISPLAY.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
       I_CALLBACK_PROGRAM                = G_REPID
      I_CALLBACK_PF_STATUS_SET          = ' '
       I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
       I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
       IS_LAYOUT                         = WA_LAYOUT
       IT_FIELDCAT                       = I_FIELDCAT[]
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
      TABLES
        T_OUTTAB                          = I_ITAB
    EXCEPTIONS
      PROGRAM_ERROR                     = 1
      OTHERS                            = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.
    FORM TOP_OF_PAGE.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY       = I_LISTHEADER
       I_LOGO                   = 'RJT'
      I_END_OF_LIST_GRID       =
      I_ALV_FORM               =
    ENDFORM.
    FORM GET_DATA.
    SELECT AVBELN AERDAT AERNAM AANGDT ABNDDT AAUART AVGBEL BPOSNR BMATNR BCHARG BMEINS BSMENG BNETPR CMAKTX  INTO CORRESPONDING FIELDS OF TABLE I_ITAB FROM  ( ( VBAK AS A INNER JOIN VBAP AS B
    ON AVBELN = BVBELN ) INNER JOIN MAKT AS C  ON BMATNR = CMATNR )  WHERE AVBELN IN DOCNO AND AAUART = DOCTYPE .
    ENDFORM.
    FORM USER_COMMAND USING L_UCOMM LIKE SY-UCOMM L_SELFIELD TYPE SLIS_SELFIELD.
    CASE L_UCOMM.
    WHEN '&IC1'.
    IF L_SELFIELD-FIELDNAME  = 'VBELN'.
    CALL TRANSACTION 'VA02'.
    ELSEIF
    L_SELFIELD-FIELDNAME = 'MATNR'.
    CALL TRANSACTION 'MM02'.
    ENDIF.
    ENDCASE.
    ENDFORM.

    if u dont want std alv functionality,u have to explicitly sum it and insert it to ur itab.
    for dat u have to change ur itab declaration like dis..
    assuming u want to display the subtotals of NETPR based on vbeln...
    TYPES: BEGIN OF T_ITAB,
    VBELN LIKE VBAK-VBELN,
    NETPR LIKE VBAP-NETPR,
    ERDAT LIKE VBAK-ERDAT,
    ERNAM LIKE VBAK-ERNAM,
    ANGDT LIKE VBAK-ANGDT,
    BNDDT LIKE VBAK-BNDDT,
    AUART LIKE VBAK-AUART,
    POSNR LIKE VBAP-POSNR,
    MATNR LIKE VBAP-MATNR,
    CHARG LIKE VBAP-CHARG,
    MAKTX LIKE MAKT-MAKTX,
    VGBEL LIKE VBAK-VGBEL,
    MEINS LIKE VBAP-MEINS,
    SMENG LIKE VBAP-SMENG,
    END OF T_ITAB.
    den in form get_data.
    aftr select statement. itab2 is the final table
    sort itab by vbeln.
    loop at it itab into wa.
    move wa TO wa1.
    v_netpr = v_netpr +  wa-netpr.
    append wa1 to itab2.
    at end of vbeln.
      clear wa1.
      wa1-netpr = v_netpr.
      append wa1 to itab2.
    endat.
    endloop.

  • Multiple Subtotal in ALV

    Hello Experts,
           We are working on a report in which we are supposed to display few fields regarding customer and most of them are time fields. My issue is at the end of every customer i need to display the AVERAGE time as a subtotal. I am having all the data in a internal table which i am passing to REUSE_ALV_GRID_DISPLAY which will be having multiple customer and multiple records for each customer. I tried with the optoin 'do_sum' of field catalog but it is not working. I tested with some other sample program where it worked but in the sample program i am using quantity to be summed up. Is there is any way of getting the average of the  time at the end of every customer using ALV Grid..?? Or is there is any best way to display this other than ALV grid...?
    My requirement will be much similar to this
    Cust1   A1   123    00:04:00
                A2    111   00:06:00
          Total (2)           00:05:00
    Cust2   B1    898   00:01:00
                B2    789    00:06:00
                B3    454    00:02:00
          Total (3)           00:03:00
    Thanks & Regards,
    Uday S.

    Hi,
    In field catalog for avarage field make do_sum as truc (X) and pass the customer in the sort table. You can take reference of the below code.
    Grouping A
      wa_fieldcat-fieldname = 'TSL_A'.
      wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = text-015.
      wa_fieldcat-do_sum    = c_true.
      wa_fieldcat-outputlen = 20.
      l_col_pos = l_col_pos + 1.                                "SD0K962726
      wa_fieldcat-col_pos   = l_col_pos.                        "SD0K962726
    *--- Sort order for subtotal
      l_wa_sort-fieldname = 'RBUNIT'.
      l_wa_sort-spos = '01'.
      l_wa_sort-subtot = c_true.
      append l_wa_sort to it_sort.
      l_wa_sort-fieldname = 'HRTXT1'.
      l_wa_sort-spos = '02'.
      append l_wa_sort to it_sort.
      l_wa_sort-fieldname = 'HRTXT2'.
      l_wa_sort-spos = '03'.
      append l_wa_sort to it_sort.
    *--- call the list for output
      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program      = sy-repid
          i_callback_user_command = 'F_DOUBLE_CLICK'            "SD0K963313
          is_layout               = l_wa_layout
          it_fieldcat             = it_fieldcat
          it_sort                 = it_sort                     " You need pass this table for your case it will be customer field
          i_save                  = l_save
          is_variant              = wa_variant1
          it_events               = it_events
        tables
          t_outtab                = it_output
        exceptions
          program_error           = 1
          others                  = 2.
    Thanks
    Subhankar

  • Doing subtotal in ALV manually

    Hi since in alv when calculation % the summing up is wrong
    i did the calculation manually buy inserting lines.
    but now all properties of ALV is gone.  i am aware of that but still i want to arrange the display to may it same as AVL would do it.
    since i am new to ALV can u plzz tell me how to
    color a cell in alv?
    make the value in bold formal?
    thinker the cell border?

    Hi,
    <b>Coloring a Cell in ALV:</b>
    The structure that should be included must be of type “LVC_T_SCOL”. If you want to color the entire row, this inner table should contain only one row with field “fname” is set to space, some color value at field “col”, “0” or “1” at fields “int” (intensified) and “inv” (inverse). If you want to color individual cells, then for each cell column, append a line to this inner table which also contains the column name at field “fname”. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table. . Again key field coloring will override your settings. That’s why, we have another field in this inner table called “nokeycol”. For each field represented in the inner table, set this field to ‘X’ to prevent overriding of key color settings. In this procedure, again we must tell the control the name of the inner table containing color data. The field “CTAB_FNAME” of the layout structure is used for this purpose.
    Code Part 14 – Adding inner table that will contain cell color data *--- Internal table holding list data
    DATA BEGIN OF gt_list OCCURS 0 .
    INCLUDE STRUCTURE SFLIGHT .
    DATA rowcolor(4) TYPE c .
    DATA cellcolors TYPE lvc_t_scol .
    DATA END OF gt_list .
    Code Part 15 – A sample code to make the cell at row 5 and column ‘SEATSOCC’ colored
    DATA ls_cellcolor TYPE lvc_s_scol .
    READ TABLE gt_list INDEX 5 .
    ls_cellcolor-fname = 'SEATSOCC' .
    ls_cellcolor-color-col = '7' .
    ls_cellcolor-color-int = '1' .
    APPEND ls_cellcolor TO gt_list-cellcolors .
    MODIFY gt_list INDEX 5 .
    Check this
    http://www.sapfans.com/forums/viewtopic.php?t=52107
    <b>Value in Bold Format:</b>
    You need to have a nested internal table as a part of your DATA table which will be of type LVC_T_STYL.
    Fill that table for the field that you want to be BOLD, fill the row in the STYLE table and append it to the MAIN table. You might have to use a combination of the styles provided as attributes in the class CL_GUI_ALV_GRID.
    If you want to make entire column bold you can set the style in field catalog to
    ls_fieldcat-style = '0000016'
    this makes the entire column bold...
    Just look at the where used list for LVC_T_STYL, you will get multiple programs.
    It is used in the following programs.
    BCALV_EDIT_02
    BCALV_EDIT_04
    BCALV_GRID_EDIT
    BCALV_TEST_FULLSCREEN
    BCALV_TEST_GRID
    BCALV_TEST_GRID_DRAG_DROP
    BCALV_TEST_GRID_EDITABLE
    BCALV_TEST_GRID_FIELDS
    BCALV_TEST_GRID_INDEX
    BCALV_TEST_GRID_PRINT
    BCALV_TEST_GRID_TOOLBAR
    BCALV_VERIFY_DATATYPES
    Regards,
    Padmam.

  • Coloring column in an ALV tree

    Hi all,
    What I want to do is set background color for columns in a tree-view ALV(class cl_gui_alv_tree). However no matter how I set the field EMPHASIZE in the fieldcatalog internal table, the display of the ALV tree keeps unchange. Anyone can help me on this?
    Thanks,
    Chen Chang

    Hi,
    <b>If u want to change the node colr in ALV tree do as follows</b>
    Adding Root Nodes for the tree.
    Key:
    NODE_KEY, RELATKEY, RELATSHIP, HIDDEN, DISABLED, ISFOLDER, N_IMAGE,
    EXP_IMAGE, <b>STYLE</b>, LAST_HITEM, NO_BRANCH, EXPANDER, DRAGDROPID, TEXT
      perform f9101_node_list using: '1' 'ROOT' '' '' '' c_x '' '' '' '' ''
                              c_x '' text-003.
    Adding subitems for the root node.
      perform f9101_node_list using:
                            Material Details
                              'MATRL' '1' '' '' '' '' '' '' '' '' '' '' ''
                              text-001,
                            Document Details
                              'DOCU' '1' '' '' '' '' '' '' '' '' '' '' ''
                              text-002.
    form f9101_node_list using    value(pnodekey)
                                 value(prelatkey)
                                 value(prelatship)
                                 value(phidden)
                                 value(pdisabled)
                                 value(pisfolder)
                                 value(pimage)
                                 value(pexpimage)
                                 value(pstyle)
                                 value(plastitem)
                                 value(pnobranch)
                                 value(pexpander)
                                 value(pdragdropid)
                                 value(ptext).
      w_nodes-node_key   = pnodekey.
      w_nodes-relatkey   = prelatkey.
      w_nodes-relatship  = prelatship. "Natural number
      w_nodes-hidden     = phidden.
      w_nodes-disabled   = pdisabled.
      w_nodes-isfolder   = pisfolder.
      w_nodes-n_image    =  pimage.  "Icons / embedded bitmap
      w_nodes-exp_image  = pexpimage. "Icons / embedded bitmap
    <b>  w_nodes-style      = pstyle.</b>  w_nodes-last_hitem = plastitem. "Tree Control: Column Name / Item
      "Name
      w_nodes-no_branch  = pnobranch.
      w_nodes-expander   = pexpander.
      w_nodes-dragdropid = pdragdropid.
      w_nodes-text       = ptext.
      append w_nodes to i_nodes.
    endform.                    " f9101_node_list
    Try changing the style so that u can change the column color.
    If u want that in ALV grid
    1. different color in line of alv
    2. Coloring Cells/rows in ALV Grid.
    Got this from forum
    report .
    Use of colours in ALV grid (cell, line and column) *
    Table
    tables : mara.
    Type
    types : begin of ty_mara,
    matnr like mara-matnr,
    matkl like mara-matkl,
    counter(4) type n,
    free_text(15) type c,
    color_line(4) type c, " Line color
    color_cell type lvc_t_scol, " Cell color
    end of ty_mara.
    Structures
    data : wa_mara type ty_mara,
    wa_fieldcat type lvc_s_fcat,
    is_layout type lvc_s_layo,
    wa_color type lvc_s_scol.
    Internal table
    data : it_mara type standard table of ty_mara,
    it_fieldcat type standard table of lvc_s_fcat,
    it_color type table of lvc_s_scol.
    Variables
    data : okcode like sy-ucomm,
    w_alv_grid type ref to cl_gui_alv_grid,
    w_docking_container type ref to cl_gui_docking_container.
    parameters : p_column as checkbox,
    p_line as checkbox,
    p_cell as checkbox.
    at selection-screen output.
    perform get_data.
    perform fill_catalog.
    if w_docking_container is initial.
    perform create_objects.
    endif.
    *& Form create_objects
    form create_objects.
    create object w_docking_container
    exporting
    ratio = 60
    exceptions
    cntl_error = 1
    cntl_system_error = 2
    create_error = 3
    lifetime_error = 4
    lifetime_dynpro_dynpro_link = 5
    others = 6.
    create object w_alv_grid
    exporting
    i_parent = w_docking_container.
    Field that identify color line in internal table
    move 'COLOR_LINE' to is_layout-info_fname.
    Field that identify cell color in inetrnal table
    move 'COLOR_CELL' to is_layout-ctab_fname.
    call method w_alv_grid->set_table_for_first_display
    exporting
    is_layout = is_layout
    changing
    it_outtab = it_mara
    it_fieldcatalog = it_fieldcat
    exceptions
    invalid_parameter_combination = 1
    program_error = 2
    too_many_lines = 3
    others = 4.
    endform.
    *& Form get_data
    form get_data.
    select * from mara up to 5 rows.
    clear : wa_mara-color_line, wa_mara-color_cell.
    move-corresponding mara to wa_mara.
    add 1 to wa_mara-counter.
    move 'Blabla' to wa_mara-free_text.
    if wa_mara-counter = '0002'
    and p_line = 'X'.
    Color line move 'C410' to wa_mara-color_line.
    elseif wa_mara-counter = '0004'
    and p_cell = 'X'.
    Color cell
    move 'FREE_TEXT' to wa_color-fname.
    move '6' to wa_color-color-col.
    move '1' to wa_color-color-int.
    move '1' to wa_color-color-inv.
    append wa_color to it_color.
    wa_mara-color_cell[] = it_color[].
    endif.
    append wa_mara to it_mara.
    endselect.
    endform.
    *& Form fill_catalog
    form fill_catalog.
    Colour code : *
    Colour is a 4-char field where : *
    - 1st char = C (color property) *
    - 2nd char = color code (from 0 to 7) *
    0 = background color *
    1 = blue *
    2 = gray *
    3 = yellow *
    4 = blue/gray *
    5 = green *
    6 = red *
    7 = orange *
    - 3rd char = intensified (0=off, 1=on) *
    - 4th char = inverse display (0=off, 1=on) *
    Colour overwriting priority : *
    1. Line *
    2. Cell *
    3. Column *
    data : w_position type i value '1'.
    clear wa_fieldcat.
    move w_position to wa_fieldcat-col_pos.
    move 'MATNR' to wa_fieldcat-fieldname.
    move 'MARA' to wa_fieldcat-ref_table.
    move 'MATNR' to wa_fieldcat-ref_field.
    append wa_fieldcat to it_fieldcat.
    add 1 to w_position.
    clear wa_fieldcat.
    move w_position to wa_fieldcat-col_pos.
    move 'MATKL' to wa_fieldcat-fieldname.
    move 'MARA' to wa_fieldcat-ref_table.
    move 'MATKL' to wa_fieldcat-ref_field.
    Color column
    if p_column = 'X'.
    move 'C610' to wa_fieldcat-emphasize.
    endif.
    append wa_fieldcat to it_fieldcat.
    add 1 to w_position.
    clear wa_fieldcat.
    move w_position to wa_fieldcat-col_pos.
    move 'COUNTER' to wa_fieldcat-fieldname.
    move 'N' to wa_fieldcat-inttype.
    move '4' to wa_fieldcat-intlen.
    move 'Counter' to wa_fieldcat-coltext.
    append wa_fieldcat to it_fieldcat.
    add 1 to w_position.
    clear wa_fieldcat.
    move w_position to wa_fieldcat-col_pos.
    move 'FREE_TEXT' to wa_fieldcat-fieldname.
    move 'C' to wa_fieldcat-inttype.
    move '20' to wa_fieldcat-intlen.
    move 'Text' to wa_fieldcat-coltext.
    append wa_fieldcat to it_fieldcat.
    endform.
    Check this link to get code for different colors http://www.sapdesignguild.org/resources/ma_guidelines/VisualDesignRules/colors.html
    Try this out the same thing will work for Reuse also.
    Thanks & Regards,
    Judith.
    Message was edited by: Judith Jessie Selvi

  • Problem in Subtotal in ALV

    Hi Experts,
    I wanted to do the subtotal in ALV report. For subtotal which data type we need to take. Is it really affect with data type??
    My problem is: I wanted to do the subtotal based on Purchase order number. I need to do the subtotal of field LV_VAR based on purchase order number. The field LV_VAR having TYPE packed decimal.
    Do I need to change the data type of field LV_VAR for getting subtotal?
    For implementing the Subtotal functionality in my alv report, I did following changes
    1. Declared one sort catalog as
    gs_sort-fieldname = 'EBELN'.
    gs_sort-up  = 'X'.
    gs-sort-subtot = 'X'.
    append gs_sort to gt_sort.
    2. In fieldcatalog of field LV_VAR
    i_fieldcatalog-fieldname = 'LV_VAR'.
    i_fieldcatalog-tabname = 'ITAB'.
    i_fieldcatalog-do_sum = 'X'.
    append i_fieldcatalog.
    Then in FM REUSE_ALV_GRID_DISPLAY, I had passed sort catalog as
    it_sort = gt_sort[]
    But I did not get the subtotal functionality.
    Any suggestion pls?

    Hi ,
    I will give you one sample code which has a functionality of subtotal and grand total also .
    And this code will help you in many aspects also.
    *& Report  ZSAND_SUBTOTAL                                              *
    REPORT  ZSAND_SUBTOTAL LINE-COUNT 65                        .
    *& Report ZALV_LIST
    TABLES : mseg.
    TYPE-POOLS : slis.
    DATA : BEGIN OF itab OCCURS 0,
            mblnr LIKE mseg-mblnr,
            matnr LIKE mseg-matnr,
            werks LIKE mseg-werks,
            menge LIKE mseg-menge,
            line_color(4) TYPE c,
           END OF itab.
    DATA : BEGIN OF itab1 OCCURS 0,
            mblnr LIKE mseg-mblnr,
            matnr LIKE mseg-matnr,
            werks LIKE mseg-werks,
            menge LIKE mseg-menge,
            line_color(4) TYPE c,
            END OF itab1.
    data: it_sortcat   type slis_sortinfo_alv occurs 1,
           wa_sort like line of it_sortcat.
    DATA: it_header TYPE slis_t_listheader,
            wa_header TYPE slis_listheader.
    data: var1(1).
    DATA  var2.
    data:mytabix like sy-tabix.
    data:wtab1 like line of itab,
         wtab2 like line of itab.
    DATA : t_fcat TYPE slis_t_fieldcat_alv,
    t_eve TYPE slis_t_event,
    t_subtot TYPE slis_t_sortinfo_alv,
    subtot LIKE LINE OF t_subtot,
    wa_fcat LIKE LINE OF t_fcat,
    gd_layout TYPE slis_layout_alv.
    DATA : gt_menge LIKE mseg-menge,
    st_menge LIKE mseg-menge.
    data:it_extab type SLIS_t_EXTAB,
         wa_extab like line of it_extab.
    SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS : doc FOR mseg-mblnr.
    SELECTION-SCREEN : END OF BLOCK blk1.
    START-OF-SELECTION.
    PERFORM build_cat USING t_fcat.
    PERFORM build_layout.
    PERFORM build_eve.
    perform fill_sort.
    PERFORM get_data.
    PERFORM display.
    *& Form build_cat
    *text
    *-->TEMP_FCAT text
    FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.
    wa_fcat-tabname = 'ITAB'.
    wa_fcat-fieldname = 'MBLNR'.
    wa_fcat-seltext_m = 'Material Doc.'.
    APPEND wa_fcat TO temp_fcat.
    CLEAR wa_fcat.
    wa_fcat-tabname = 'ITAB'.
    wa_fcat-fieldname = 'MATNR'.
    wa_fcat-seltext_m = 'Material'.
    APPEND wa_fcat TO temp_fcat.
    CLEAR wa_fcat.
    wa_fcat-tabname = 'ITAB'.
    wa_fcat-fieldname = 'WERKS'.
    wa_fcat-seltext_m = 'Plant'.
    APPEND wa_fcat TO temp_fcat.
    CLEAR wa_fcat.
    wa_fcat-tabname = 'ITAB'.
    wa_fcat-fieldname = 'MENGE'.
    wa_fcat-seltext_m = 'Quantity'.
    wa_fcat-do_sum = 'Y'.
    APPEND wa_fcat TO temp_fcat.
    CLEAR wa_fcat.
    ENDFORM. "build_cat
    *& Form build_eve
    *text
    FORM build_eve.
    DATA : wa_eve TYPE slis_alv_event.
    data:mytabix type sy-tabix.
    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
    i_list_type = 0
    IMPORTING
    et_events = t_eve
    EXCEPTIONS
    list_type_wrong = 1
    OTHERS = 2.
    IF sy-subrc  <> 0.
    *MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    READ TABLE t_eve  into wa_eve WITH KEY name = slis_ev_top_of_page.
    *INTO wa_eve.
    IF sy-subrc = 0.
    mytabix = sy-tabix.
    MOVE 'TOP_OF_PAGE' TO wa_eve-form.
    append  wa_eve  to t_eve.
    *modify t_eve from wa_eve index mytabix transporting form.
    ENDIF.
    READ TABLE t_eve  into wa_eve WITH KEY name = slis_ev_end_of_page.
    *INTO wa_eve.
    IF sy-subrc = 0.
    mytabix = sy-tabix.
    MOVE 'END_OF_PAGE' TO wa_eve-form.
    append  wa_eve  to t_eve.
    *modify t_eve from wa_eve index mytabix transporting form.
    ENDIF.
    ENDFORM. "build_eve
    *& Form build_layout
    *text
    FORM build_layout.
    *gd_layout-no_input = 'X'.
    gd_layout-colwidth_optimize = 'X'.
    gd_layout-info_fieldname = 'LINE_COLOR'.
    gd_layout-subtotals_text = 'SUBTOTAL'.
    *gd_layout-totals_text = 'TOTAL'.
    gd_layout-EDIT = 'X'.
    ENDFORM. " BUILD_LAYOUT
    *& Form get_data
    *text
    FORM get_data.
    SELECT mblnr matnr werks menge FROM mseg INTO CORRESPONDING FIELDS OF
    TABLE itab
    WHERE mblnr IN doc.
    SORT itab BY mblnr.
    sort itab by mblnr matnr.
    read table itab into wtab1 index 1.
    mytabix = 1.
    loop at itab into wtab2 from 2.
    if wtab1-mblnr = wtab2-mblnr and wtab1-matnr = wtab2-matnr.
    wtab1-menge = wtab1-menge + wtab2-menge.
    modify itab from wtab1 index mytabix.
    else.
    modify itab from wtab1 index mytabix.
    clear wtab1.
    mytabix = sy-tabix.
    move wtab2 to wtab1.
    endif.
    clear wtab2.
    endloop.
    delete ADJACENT DUPLICATES  from itab comparing mblnr matnr.
    ENDFORM. "get_data
    *& Form display
    *text
    FORM display.
    wa_extab-fcode = '&ETA'.
    append wa_extab to it_extab.
      wa_header-typ  = 'H'.
       wa_header-info = 'SANDY is Great'.
       append wa_header to it_header.
       clear wa_header.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
       I_CALLBACK_PROGRAM                = 'ZSAND_SUBTOTAL'
      I_CALLBACK_PF_STATUS_SET          = ' '
       I_CALLBACK_USER_COMMAND           = 'USERCOMMAND'
       I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
       IS_LAYOUT                         = gd_layout
       IT_FIELDCAT                       = t_fcat
       IT_EXCLUDING                      = it_extab
      IT_SPECIAL_GROUPS                 =
       IT_SORT                           = it_sortcat
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =
       IT_EVENTS                         = t_eve[]
      IT_EVENT_EXIT                     = 'BUILD_EVE'
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      I_HTML_HEIGHT_TOP                 =
      I_HTML_HEIGHT_END                 =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
      TABLES
        t_outtab                          = itab
    EXCEPTIONS
      PROGRAM_ERROR                     = 1
      OTHERS                            = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. "display
    ***& Form top_of_page
    *text
    FORM top_of_page.
    if var1 is initial.
      wa_header-typ  = 'H'.
       wa_header-info = 'SANDY is Great'.
       append wa_header to it_header.
       clear wa_header.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY       = it_header
        I_LOGO                   = 'HR_LOGO'
      I_END_OF_LIST_GRID       =
              var1 = 'X'.
    endif.
      ENDFORM. "top_of_page
      FORM end_of_page.
    if var2 is initial.
      wa_header-typ  = 'H'.
       wa_header-info = 'SANDY is Great'.
       append wa_header to it_header.
       clear wa_header.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        IT_LIST_COMMENTARY       = it_header
        I_LOGO                   = 'HR_LOGO'
      I_END_OF_LIST_GRID       =
              var2 = 'X'.
    endif.
      ENDFORM. "top_of_page
    *&      Form  fill_sort
          text
    -->  p1        text
    <--  p2        text
    form fill_sort .
    wa_sort-spos      = 1.
      wa_sort-fieldname = 'MBLNR'.
      wa_sort-SUBTOT    = 'X'. "subtotals any totals column by this field
    gd_sortcat-tabname
      APPEND wa_sort TO it_sortcat.
      wa_sort-spos      = 2.
      wa_sort-fieldname = 'MATNR'.
    gd_sortcat-tabname
      APPEND wa_sort TO it_sortcat.
    endform.                    " fill_sort
    FORM status USING rt_extab TYPE slis_t_extab.
    set pf-status  'ZSTANDARD'.
    endform.
    form USERCOMMAND USING R_UCOMM type sy-ucomm
                           rselfield type slis_selfield .
    set parameter id 'MAT'  field rselfield-value .
    call transaction 'MM03' and  skip first screen.
    endform.
    I hope this program will help you out.
    Help children of U.N World Food Program by rewarding  points and encourage others to answer your queries.

Maybe you are looking for

  • Can I transfer photos from my iMac to my iPad via wi-fi or Bluetooth?

    I have a PDF reader on my iPad that can fetch files from my iMac via wi-fi: All I do is open the PDF reader on the iPad, then open a browser on the computer and type in the URL the PDF reader gives me. (Or I can have that URL bookmarked, even easier.

  • Unable to join domain when OD Master is set up as PDC

    Hi all, I'm working on trying to get my OD server to authenticate our new windows vmware workstations. I have both LDAP and Kerberos set up, and everything works really well with my OS X clients, as do our Linux servers. However, I'm unable to get ou

  • Updating Username in BP

    Hi All,    I need to Update the User name in the Transaction BP in identification Tab ..... PL. let me know are there any BAPIs or function modules to do this ... I tried BAPI_IDENTIFICATION_ADD by passing the category as 'BUP003' but its not working

  • HT1212 I have forgotten my new passcode on iphone and also have find my iphone activated. what do i do?

    Hi . I have forgotten my new passcode on my iphone and also have the find my iphone activated! Is there anything I can do to fix this? I started to restore it on my computer but it won't let me go past the find my iphone activation part. also i am wo

  • Windows cannot start the installation process

    I have windows server 2012 datacenter with hyper-v role that I tried to upgrade to R2 RTM. All went fine until the reboot and the error "windows cannot start the installation process" I can start windows server 2012 I must say that I used a ISO file