ALV - Sort - Subtotal

hi,
Can u pls tell me what is the use of subtotal in sort exactly with an example of records..
I need to work out with this..in ALV.
will be rewarded.
Thankx in adv

REPORT ZALV.
TYPE-POOLS: SLIS.
DATA: G_REPID LIKE SY-REPID,
GS_PRINT            TYPE SLIS_PRINT_ALV,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
GT_EVENTS           TYPE SLIS_T_EVENT,
GT_SORT             TYPE SLIS_T_SORTINFO_ALV,
GS_LAYOUT           TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT         TYPE SLIS_T_FIELDCAT_ALV,
FIELDCAT_LN LIKE LINE OF GT_FIELDCAT,
COL_POS TYPE I.
DATA: BEGIN OF ITAB,
  FIELD1(5) TYPE C,
  FIELD2(5) TYPE C,
  FIELD3(5) TYPE P DECIMALS 2,
END OF ITAB.
DATA: BEGIN OF ITAB1 OCCURS 0.
  INCLUDE STRUCTURE ITAB.
DATA: END OF ITAB1.
DATA: BEGIN OF ITAB_FIELDCAT OCCURS 0.
  INCLUDE STRUCTURE ITAB.
DATA: END OF ITAB_FIELDCAT.
Print Parameters
PARAMETERS:
            P_PRINT  AS CHECKBOX DEFAULT ' ', "PRINT IMMEDIATE
            P_NOSINF AS CHECKBOX DEFAULT 'X', "NO SELECTION INFO
            P_NOCOVE AS CHECKBOX DEFAULT ' ', "NO COVER PAGE
            P_NONEWP AS CHECKBOX DEFAULT ' ', "NO NEW PAGE
            P_NOLINF AS CHECKBOX DEFAULT 'X', "NO PRINT LIST INFO
            P_RESERV TYPE I.                  "NO OF FOOTER LINE
INITIALIZATION.
G_REPID = SY-REPID.
PERFORM PRINT_BUILD    USING GS_PRINT.      "Print PARAMETERS
START-OF-SELECTION.
TEST DATA
MOVE 'TEST1' TO ITAB1-FIELD1.
MOVE 'TEST1' TO ITAB1-FIELD2.
MOVE '10.00' TO ITAB1-FIELD3.
APPEND ITAB1.
MOVE 'TEST2' TO ITAB1-FIELD1.
MOVE 'TEST2' TO ITAB1-FIELD2.
MOVE '20.00' TO ITAB1-FIELD3.
APPEND ITAB1.
DO 50 TIMES.
  APPEND ITAB1.
ENDDO.
END-OF-SELECTION.
PERFORM BUILD.
PERFORM EVENTTAB_BUILD CHANGING GT_EVENTS.
PERFORM COMMENT_BUILD  CHANGING GT_LIST_TOP_OF_PAGE.
PERFORM CALL_ALV.
FORM BUILD.
DATA FIELD CATALOG
Explain Field Description to ALV
DATA: FIELDCAT_IN TYPE SLIS_FIELDCAT_ALV.
CLEAR FIELDCAT_IN.
FIELDCAT_LN-FIELDNAME = 'FIELD1'.
FIELDCAT_LN-TABNAME   = 'ITAB1'.
*FIELDCAT_LN-NO_OUT    = 'X'.  "FIELD NOT DISPLAY, CHOOSE FROM LAYOUT
FIELDCAT_LN-KEY       = ' '.   "SUBTOTAL KEY
FIELDCAT_LN-NO_OUT    = ' '.
FIELDCAT_LN-SELTEXT_L = 'HEAD1'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_IN.
FIELDCAT_LN-FIELDNAME = 'FIELD2'.
FIELDCAT_LN-TABNAME   = 'ITAB1'.
FIELDCAT_LN-NO_OUT    = 'X'.
FIELDCAT_LN-SELTEXT_L = 'HEAD2'.
APPEND FIELDCAT_LN TO GT_FIELDCAT.
CLEAR FIELDCAT_IN.
FIELDCAT_LN-FIELDNAME     = 'FIELD3'.
FIELDCAT_LN-TABNAME       = 'ITAB1'.
FIELDCAT_LN-REF_FIELDNAME = 'MENGE'. "<- REF FIELD IN THE DICTIONNARY
FIELDCAT_LN-REF_TABNAME   = 'MSEG'.  "<- REF TABLE IN THE DICTIONNARY
FIELDCAT_LN-NO_OUT        = ' '.
FIELDCAT_LN-DO_SUM        = 'X'.   "SUM UPON DISPLAY
APPEND FIELDCAT_LN TO GT_FIELDCAT.
DATA SORTING AND SUBTOTAL
DATA: GS_SORT TYPE SLIS_SORTINFO_ALV.
CLEAR GS_SORT.
GS_SORT-FIELDNAME = 'FIELD1'.
GS_SORT-SPOS      = 1.
GS_SORT-UP        = 'X'.
GS_SORT-SUBTOT    = 'X'.
APPEND GS_SORT TO GT_SORT.
CLEAR GS_SORT.
GS_SORT-FIELDNAME = 'FIELD2'.
GS_SORT-SPOS      = 2.
GS_SORT-UP        = 'X'.
*GS_SORT-SUBTOT    = 'X'.
APPEND GS_SORT TO GT_SORT.
ENDFORM.
FORM CALL_ALV.
ABAP List Viewer
CALL FUNCTION 'REUSE_ALV_LIST_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 = ' '
I_STRUCTURE_NAME = 'ITAB1'
IS_LAYOUT =  GS_LAYOUT
IT_FIELDCAT = GT_FIELDCAT[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
  IT_SORT = GT_SORT[]
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
  IT_EVENTS = GT_EVENTS[]
IT_EVENT_EXIT =
  IS_PRINT = GS_PRINT
IS_REPREP_ID =
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 = ITAB1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM.
HEADER FORM
FORM EVENTTAB_BUILD CHANGING LT_EVENTS TYPE SLIS_T_EVENT.
CONSTANTS:
GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.
*GC_FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE 'END_OF_PAGE'.
  DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
       EXPORTING
            I_LIST_TYPE = 0
       IMPORTING
            ET_EVENTS   = LT_EVENTS.
  READ TABLE LT_EVENTS WITH KEY NAME =  SLIS_EV_TOP_OF_PAGE
                           INTO LS_EVENT.
  IF SY-SUBRC = 0.
    MOVE GC_FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.
    APPEND LS_EVENT TO LT_EVENTS.
  ENDIF.
define END_OF_PAGE event
READ TABLE LT_EVENTS WITH KEY NAME =  SLIS_EV_END_OF_PAGE
                         INTO LS_EVENT.
IF SY-SUBRC = 0.
  MOVE GC_FORMNAME_END_OF_PAGE TO LS_EVENT-FORM.
  APPEND LS_EVENT TO LT_EVENTS.
ENDIF.
ENDFORM.
FORM COMMENT_BUILD CHANGING GT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
  DATA: GS_LINE TYPE SLIS_LISTHEADER.
  CLEAR GS_LINE.
  GS_LINE-TYP  = 'H'.
  GS_LINE-INFO = 'HEADER 1'.
  APPEND GS_LINE TO GT_TOP_OF_PAGE.
  CLEAR GS_LINE.
  GS_LINE-TYP  = 'S'.
  GS_LINE-KEY  = 'STATUS 1'.
  GS_LINE-INFO = 'INFO 1'.
  APPEND GS_LINE TO GT_TOP_OF_PAGE.
  GS_LINE-KEY  = 'STATUS 2'.
  GS_LINE-INFO = 'INFO 2'.
  APPEND GS_LINE TO GT_TOP_OF_PAGE.
CLEAR GS_LINE.
GS_LINE-TYP  = 'A'.
GS_LINE-INFO = 'ACTION'.
APPEND GS_LINE TO  GT_TOP_OF_PAGE.
ENDFORM.
FORM TOP_OF_PAGE.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
       EXPORTING
            IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
  WRITE: SY-DATUM, 'Page No', SY-PAGNO LEFT-JUSTIFIED.
ENDFORM.
FORM END_OF_PAGE.
  WRITE at (sy-linsz) sy-pagno CENTERED.
ENDFORM.
PRINT SETTINGS
FORM PRINT_BUILD USING LS_PRINT TYPE SLIS_PRINT_ALV.
  LS_PRINT-PRINT              = P_PRINT.  "PRINT IMMEDIATE
  LS_PRINT-NO_PRINT_SELINFOS  = P_NOSINF. "NO SELECTION INFO
  LS_PRINT-NO_COVERPAGE       = P_NOCOVE. "NO COVER PAGE
  LS_PRINT-NO_NEW_PAGE        = P_NONEWP.
  LS_PRINT-NO_PRINT_LISTINFOS = P_NOLINF. "NO PRINT LIST INFO
  LS_PRINT-RESERVE_LINES      = P_RESERV.
ENDFORM.
*END OF ZALV PROGRAM
Check this program...
Regards,
Pavan

Similar Messages

  • How we can sort subtotal results value in abap alv report

    Hi, How we can sort subtotal results value in abap alv report

    Thanks a lot for your code
    but i am still getting double and weird results.
    Subtotal     IN     PARTY              KGS        TOTAL VALUE
         1     40008     3,141.20     192,799.00
         1     40008     16,681.06     1,908,659.00
    Subtotal     1          19,822.25     2,101,458.00
         10     40022     4,590.60     531,228.00
         10     40022     3,448.27     377,173.00
    Subtotal     10          8,038.87     908,401.00
         100     40010     270.172     19,852.00
    Subtotal     100          270.172     19,852.00
         101     40036     752.898     61,051.00
         101     40036     207.586     19,431.00
    Subtotal     101          960.484     80,482.00
         102     40048     325.936     32,154.00
         102     40048     264.32     19,364.00
    Subtotal     102          590.256     51,518.00
         103     40066     216.134     18,088.00
    Subtotal     103          216.134     18,088.00
         104     40001     231.96     16,986.00
    Subtotal     104          231.96     16,986.00
         105     40021     585.918     65,461.00
         105     40021     108.683     15,825.00
    Subtotal     105          694.601     81,286.00
         106     40046     209.777     15,341.00
    Subtotal     106          209.777     15,341.00
         107     40043     167.353     14,755.00
    Subtotal     107          167.353     14,755.00
         108     40046     153.023     14,343.00
         108     40046     342.348     32,223.00
    Subtotal     108          495.371     46,566.00
         109     40008     184.085     13,483.00
    Subtotal     109          184.085     13,483.00
         11     40011     5,275.63     524,232.69
         11     40011     6,723.28     643,911.82
    Subtotal     11          11,998.90     1,168,144.51
         110     40067     142.113     13,333.00
         110     40067     492.883     44,428.00
    Subtotal     110          634.996     57,761.00
         111     40040     118.961     13,190.00
         111     40040     492.433     60,029.00
    Subtotal     111          611.394     73,219.00
    Edited by: Timaji Sawant on Feb 16, 2012 12:16 PM
    Edited by: Timaji Sawant on Feb 17, 2012 9:27 AM

  • ALV Sort

    Hi Guru's
    i am use alv sort in my report .
    i use following code.
    but it gives me DUMP ERROR.
    my code like this.
    DATA : it_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE.
    FORM do_sort .
      it_sort-spos = 1.
      it_sort-fieldname = 'vbeln'.
      it_sort-tabname = 'it_vbak'.
      it_sort-up = 'X'.
      it_sort-subtot = 'X'.
    it_sort-group = '*'.
    it_sort-expa = 'X'.
      APPEND it_sort.
      it_sort-spos = 2.
      it_sort-fieldname = 'posnr'.
      it_sort-tabname = 'it_vbap'.
      it_sort-up = 'X'.
      it_sort-subtot = 'X'.
    it_sort-group = '*'.
    it_sort-expa = 'X'.
      APPEND it_sort.
    ENDFORM.  
    please tell me where is the error.
    Thanks in advance.
    Regards.
    Sam.

    Hi,
    Try the following code
    DATA : it_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE.
    FORM do_sort .
    it_sort-spos = 1.
    it_sort-fieldname = 'VBELN'.
    it_sort-tabname = 'IT_VBAK'.
    it_sort-up = 'X'.
    it_sort-subtot = 'X'.
    it_sort-group = '*'.
    it_sort-expa = 'X'.
    APPEND it_sort.
    it_sort-spos = 2.
    it_sort-fieldname = 'POSNR'.
    it_sort-tabname = 'IT_VBAP'.
    it_sort-up = 'X'.
    it_sort-subtot = 'X'.
    it_sort-group = '*'.
    it_sort-expa = 'X'.
    APPEND it_sort.
    ENDFORM.
    Hope this will have u.
    If it is helpful provide point.
    Thanks.

  • Hotspot-clicking (Insert function) plus ALV Sorting

    Hi,
    I have a requirement where the ALV display has to be SORTED based on values entered/changed on a certain column. The sort works ok when used with a custom APPEND button for new records (always inserted at the bottom of the list).
    However, it does not work correctly when used with the Hotspot-click (INSERT functionality). It looks like if you CLICK on a particular record onscreen, you are actually addressing the original record in that position before the SORT was effected. 
    Is the Hotspot-clicking (Insert functionality) possible with ALV sorting? The ideal solution would be to have the ALV sorted at PBO and also at PAI so that the user can change existing records and add new ones with the sorting being updated everytime ON_DATA_CHANGED is triggered.
    Will appreciate any help on this.
    Thanks!
    Michael

    Hello Michael
    Thanks for further specifying your requirements. I have created the sample variant ZUS_SDN_ALVGRID_HOTSPOT_SORT_1 which contains two differences as compared to its template:
    Replace table VBAK with VBAP (so we have two levels of sorting: VBELN, POSNR)
    Move SET_TABLE_FOR_FIRST_DISPLAY method call into PBO
    When I click on the hotspot (VBELN) a new row entry for the order number is created. The sorting (VBELN, POSNR) is kept even though the new row has been appended to the itab.
    *& Report  ZUS_SDN_ALVGRID_HOTSPOT_SORT
    *& Thread: Hotspot-clicking (Insert function) plus ALV Sorting
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1159431"></a>
    REPORT  zus_sdn_alvgrid_hotspot_sort.
    TYPES: BEGIN OF ty_s_outtab.
    INCLUDE TYPE vbap.
    TYPES: END OF ty_s_outtab.
    TYPES: ty_t_outtab    TYPE STANDARD TABLE OF ty_s_outtab
                          WITH DEFAULT KEY.
    DATA: gt_outtab    TYPE ty_t_outtab.
    DATA:
      gd_okcode        TYPE ui_func,
      gd_repid         TYPE syrepid,
      gt_sort          TYPE lvc_t_sort,
      gt_fcat          TYPE lvc_t_fcat,
      gs_layout        TYPE lvc_s_layo,
      gs_variant       TYPE disvariant,
      go_docking       TYPE REF TO cl_gui_docking_container,
      go_grid          TYPE REF TO cl_gui_alv_grid.
    *       CLASS lcl_eventhandler DEFINITION
    CLASS lcl_eventhandler DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA:
          ms_sel_row    TYPE lvc_s_row. " selected row
        CLASS-METHODS:
          handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
            IMPORTING
              er_data_changed
              e_onf4
              e_onf4_before
              e_onf4_after
              sender,
          handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
            IMPORTING
              e_row_id
              e_column_id
              es_row_no
              sender.
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    *       CLASS lcl_eventhandler IMPLEMENTATION
    CLASS lcl_eventhandler IMPLEMENTATION.
      METHOD handle_data_changed.
        FIELD-SYMBOLS: <lt_outtab>  TYPE ty_t_outtab.
        BREAK-POINT.
      ENDMETHOD.                    "handle_data_changed
      METHOD handle_hotspot_click.
        " define local data
        DATA: ls_outtab    TYPE ty_s_outtab,
              ld_msg        TYPE bapi_msg.
        BREAK-POINT.
        CLEAR: lcl_eventhandler=>ms_sel_row.
        ms_sel_row = e_row_id.
        READ TABLE gt_outtab INTO ls_outtab INDEX e_row_id-index.
        CONCATENATE 'Selected Sales Order = ' ls_outtab-vbeln ' / '
                                              ls_outtab-posnr
          INTO ld_msg.
          message i398(00) with ld_msg.
        " Trigger PAI
        CALL METHOD cl_gui_cfw=>set_new_ok_code
          EXPORTING
            new_code = 'INSERT'
    *      IMPORTING
    *        rc       =
      ENDMETHOD.                    "handle_hotspot_click
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    PARAMETERS:
      p_vkorg      TYPE vkorg  DEFAULT '0001'  OBLIGATORY.
    START-OF-SELECTION.
    **  SELECT  * FROM  vbak INTO CORRESPONDING FIELDS OF TABLE gt_outtab
    **    UP TO 200 ROWS
    **         WHERE  vkorg = p_vkorg.
      SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE gt_outtab
        UP TO 100 ROWS.
      PERFORM init_controls.
    * Build fieldcatalog and set hotspot for field KUNNR
      PERFORM build_fieldcatalog.
      PERFORM set_layout_and_variant.
      PERFORM set_sorting.
      " Register EDIT event
      CALL METHOD go_grid->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_enter
        EXCEPTIONS
          error      = 1
          OTHERS     = 2.
      IF sy-subrc NE 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      SET HANDLER:
        lcl_eventhandler=>handle_data_changed  FOR go_grid,
        lcl_eventhandler=>handle_hotspot_click FOR go_grid.
    * Link the docking container to the target dynpro
      gd_repid = syst-repid.
      CALL METHOD go_docking->link
        EXPORTING
          repid                       = gd_repid
          dynnr                       = '0100'
    *      CONTAINER                   =
        EXCEPTIONS
          OTHERS                      = 4.
      IF sy-subrc NE 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    * ok-code field = GD_OKCODE
      CALL SCREEN '0100'.
    END-OF-SELECTION.
    *&      Module  STATUS_0100  OUTPUT
    *       text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS_0100'.
    *  SET TITLEBAR 'xxx'.
    * Display data
      CALL METHOD go_grid->set_table_for_first_display
        EXPORTING
          i_bypassing_buffer            = abap_true
          is_variant                    = gs_variant
          i_save                        = 'A'
    *      i_default                     = 'X'
          is_layout                     = gs_layout
    *      is_print                      =
    *      it_special_groups             =
    *      it_toolbar_excluding          =
    *      it_hyperlink                  =
    *      it_alv_graphics               =
    *      it_except_qinfo               =
    *      ir_salv_adapter               =
        CHANGING
          it_outtab                     = gt_outtab
          it_fieldcatalog               = gt_fcat
          it_sort                       = gt_sort
    *      it_filter                     =
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
      IF sy-subrc NE 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    **  CALL METHOD go_grid->refresh_table_display
    ***        EXPORTING
    ***          IS_STABLE      =
    ***          I_SOFT_REFRESH =
    **    EXCEPTIONS
    **      finished       = 1
    **      OTHERS         = 2.
    **  IF sy-subrc ne 0.
    ***       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    ***                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    **  ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
    *       text
    MODULE user_command_0100 INPUT.
      CASE gd_okcode.
        WHEN 'BACK' OR
             'EXIT'  OR
             'CANC'.
          SET SCREEN 0. LEAVE SCREEN.
        WHEN 'INSERT'.
          PERFORM insert_row.
        WHEN OTHERS.
          " Check for changed data at the frontend (= grid control)
          CALL METHOD go_grid->check_changed_data( ).
      ENDCASE.
      CALL METHOD go_grid->refresh_table_display
    *    EXPORTING
    *      IS_STABLE      =
    *      I_SOFT_REFRESH =
        EXCEPTIONS
          finished       = 1
          OTHERS         = 2.
      IF sy-subrc NE 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CLEAR: gd_okcode.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Form  INIT_CONTROLS
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM init_controls .
    * Create docking container
      CREATE OBJECT go_docking
        EXPORTING
          parent = cl_gui_container=>screen0
          ratio  = 90
        EXCEPTIONS
          others = 6.
      IF sy-subrc NE 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL METHOD go_docking->set_extension
        EXPORTING
          extension  = 99999
        EXCEPTIONS
          cntl_error = 1
          OTHERS     = 2.
      IF sy-subrc NE 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    * Create ALV grid
      CREATE OBJECT go_grid
        EXPORTING
          i_parent = go_docking
        EXCEPTIONS
          others   = 5.
      IF sy-subrc NE 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " INIT_CONTROLS
    *&      Form  BUILD_FIELDCATALOG
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM build_fieldcatalog.
    * define local data
      DATA:
        ls_fcat        TYPE lvc_s_fcat.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
    *     I_BUFFER_ACTIVE              =
          i_structure_name             = 'VBAP'  " 'VBAK'
    *     I_CLIENT_NEVER_DISPLAY       = 'X'
    *     I_BYPASSING_BUFFER           =
    *     I_INTERNAL_TABNAME           =
        CHANGING
          ct_fieldcat                  = gt_fcat
        EXCEPTIONS
          inconsistent_interface       = 1
          program_error                = 2
          OTHERS                       = 3.
      IF sy-subrc NE 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    **  LOOP AT gt_fcat INTO ls_fcat.
    **    CASE ls_fcat-fieldname.
    **      WHEN 'VBELN'  OR
    **           'ERDAT'  OR
    **           'ERZET'  OR
    **           'ERNAM'  OR
    **           'AUART'  OR
    **           'NETWR'  OR
    **           'WAERK'.
    **        CONTINUE.
    **      WHEN OTHERS.
    **        ls_fcat-no_out = abap_true.
    **    ENDCASE.
    **    MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
    **  ENDLOOP.
    * Only non-key fields are editable
    **  ls_fcat-edit = 'X'.
    **  MODIFY gt_fcat FROM ls_fcat
    **    TRANSPORTING edit
    **    WHERE ( fieldname NE space ).
      ls_fcat-hotspot = abap_true.
      MODIFY gt_fcat FROM ls_fcat
        TRANSPORTING hotspot
        WHERE ( fieldname = 'AUART'   OR
                fieldname = 'VBELN' ).
    **  DELETE gt_fcat FROM 15 TO 99.
    ENDFORM.                    " BUILD_FIELDCATALOG_KNB1
    *&      Form  SET_LAYOUT_AND_VARIANT
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM set_layout_and_variant .
      CLEAR: gs_layout,
             gs_variant.
      gs_layout-cwidth_opt = abap_true.
      gs_variant-report = syst-repid.
      gs_variant-handle = 'GRID'.
    ENDFORM.                    " SET_LAYOUT_AND_VARIANT
    *&      Form  SET_SORTING
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM set_sorting .
    * define local data
      DATA: ls_sort   TYPE lvc_s_sort.
      REFRESH: gt_sort.
      CLEAR: ls_sort.
      ls_sort-spos = 1.
      ls_sort-fieldname = 'VBELN'.
      ls_sort-up = abap_true.
      APPEND ls_sort TO gt_sort.
      CLEAR: ls_sort.
      ls_sort-spos = 1.
      ls_sort-fieldname = 'POSNR'.
      ls_sort-up = abap_true.
      APPEND ls_sort TO gt_sort.
    ENDFORM.                    " SET_SORTING
    *&      Form  INSERT_ROW
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM insert_row .
    * define local data
      DATA: ls_outtab   TYPE ty_s_outtab,
            ld_order    TYPE vbeln.
      READ TABLE gt_outtab INTO ls_outtab
                           INDEX lcl_eventhandler=>ms_sel_row-index.
      ld_order = ls_outtab-vbeln.
      " Find last item of sales order
      LOOP AT gt_outtab INTO ls_outtab
                        WHERE ( vbeln = ld_order ).
      ENDLOOP.
      " Create next item:
      add 10 to ls_outtab-posnr.
      " NOTE: added at the end of the list
      APPEND ls_outtab TO gt_outtab.
      " NOTE: insert new row AFTER selected row => works, too
    **  INSERT ls_outtab INTO gt_outtab
    **                   INDEX lcl_eventhandler=>ms_sel_row-index.
    ENDFORM.                    " INSERT_ROW

  • ALV Sorting Not Working after Adding Checkbox to ALV

    Hi All.
    I am currently doing an ALV report using REUSE_ALV_GRID_DISPLAY function. I am sorting the list by Employee Name and Personnel Area. It works fine where the personnel are field and employee name field are merger together for same personnel are and employee name. But afterwards I added a checkbox field to the internal table and the list outputs a checkbox for each line. Afer  putting the checkbox the list no long merges the same personnel are and employee name fields according to original sorting.
    Can anyone explain if there is a way to solve this?
    Thanks a lot.
    Lily

    yes there is a way. Just see this..
    There is no Straight forward solution. There is a work around.
    REPORT  ztest_check_box                         .
    TYPE-POOLS: slis,icon.
    DATA: BEGIN OF it_vbap OCCURS 0,
           vbeln LIKE vbap-vbeln,
           matnr LIKE vbap-matnr,
           posnr LIKE vbap-posnr,
           kunnr LIKE vbak-kunnr,
           kwmeng LIKE vbap-kwmeng,
           check TYPE c,
           id TYPE icon-id,
          END OF it_vbap.
    DATA: it_fieldcat  TYPE slis_t_fieldcat_alv.
    DATA:  x_fieldcat  TYPE slis_fieldcat_alv.
    DATA: it_sort TYPE slis_t_sortinfo_alv,
          x_sort TYPE slis_sortinfo_alv.
    SELECT vbak~vbeln
           vbak~kunnr
           vbap~posnr
           vbap~matnr
           vbap~kwmeng
           INTO CORRESPONDING FIELDS OF TABLE it_vbap
           FROM vbak JOIN vbap
           ON vbak~vbeln = vbap~vbeln.
    SORT it_vbap BY matnr.
    DELETE it_vbap WHERE matnr IS INITIAL.
    LOOP AT it_vbap.
      it_vbap-id = '@T9@'.
      MODIFY it_vbap.
    ENDLOOP.
    x_fieldcat-fieldname = 'ID'.
    x_fieldcat-seltext_l = 'CHECK'.
    x_fieldcat-outputlen = 4.
    x_fieldcat-icon  = 'X'.
    x_fieldcat-col_pos   = 1.
    x_fieldcat-hotspot  = 'X'.
    x_fieldcat-tabname   = 'IT_VBAP'.
    APPEND x_fieldcat TO it_fieldcat.
    CLEAR x_fieldcat.
    x_fieldcat-fieldname = 'MATNR'.
    x_fieldcat-seltext_l = 'MATNR'.
    x_fieldcat-col_pos   = 2.
    x_fieldcat-tabname   = 'IT_VBAP'.
    APPEND x_fieldcat TO it_fieldcat.
    CLEAR x_fieldcat.
    x_fieldcat-fieldname = 'KUNNR'.
    x_fieldcat-seltext_l = 'KUNNR'.
    x_fieldcat-col_pos   = 3.
    x_fieldcat-tabname   = 'IT_VBAP'.
    APPEND x_fieldcat TO it_fieldcat.
    CLEAR x_fieldcat.
    x_fieldcat-fieldname = 'VBELN'.
    x_fieldcat-seltext_l = 'VBELN'.
    x_fieldcat-col_pos   = 4.
    x_fieldcat-tabname   = 'IT_VBAP'.
    APPEND x_fieldcat TO it_fieldcat.
    CLEAR x_fieldcat.
    x_fieldcat-fieldname = 'POSNR'.
    x_fieldcat-seltext_l = 'POSNR'.
    x_fieldcat-col_pos   = 5.
    x_fieldcat-tabname   = 'IT_VBAP'.
    APPEND x_fieldcat TO it_fieldcat.
    CLEAR x_fieldcat.
    x_fieldcat-fieldname = 'KWMENG'.
    x_fieldcat-seltext_l = 'KWMENG'.
    x_fieldcat-col_pos   = 6.
    x_fieldcat-do_sum   = 'X'.
    x_fieldcat-tabname   = 'IT_VBAP'.
    APPEND x_fieldcat TO it_fieldcat.
    CLEAR x_fieldcat.
    x_sort-fieldname = 'MATNR'.
    x_sort-spos       = 1.
    x_sort-up = 'X'.
    x_sort-group = 'X'.
    x_sort-subtot = 'X'.
    APPEND x_sort TO it_sort.
    CLEAR x_sort.
    x_sort-fieldname = 'KUNNR'.
    x_sort-spos       = 2.
    x_sort-up = 'X'.
    APPEND x_sort TO it_sort.
    CLEAR x_sort.
    x_sort-fieldname = 'VBELN'.
    x_sort-spos       = 3.
    x_sort-up = 'X'.
    APPEND x_sort TO it_sort.
    CLEAR x_sort.
    *DATA:x_layout TYPE lvc_s_layo.
    *x_layout-box_fname = 'CHECK'.
    *x_layout-no_rowmark = 'X'.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program = sy-repid
    *   is_layout          = x_layout
        i_callback_user_command = 'USER_COMMAND'
        it_fieldcat        = it_fieldcat
        it_sort            = it_sort
      TABLES
        t_outtab           = it_vbap[]
      EXCEPTIONS
        program_error      = 1
        OTHERS             = 2.
    IF sy-subrc ne 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    *&      Form  itab_user_command
    *       text
    *      -->WHATCOMM   text
    *      -->WHATROW    text
    FORM user_command USING whatcomm TYPE sy-ucomm selfield TYPE
    slis_selfield.
      IF selfield-fieldname = 'ID'.
        READ TABLE it_vbap INDEX selfield-tabindex.
        IF sy-subrc = 0.
          IF it_vbap-check = ''.
            it_vbap-id = '@R7@'.
            it_vbap-check = 'X'.
          ELSE.
            it_vbap-id = '@T9@'.
            it_vbap-check = ''.
          ENDIF.
          MODIFY it_vbap INDEX selfield-tabindex.
        ENDIF.
      ENDIF.
      selfield-refresh = 'X'.
    ENDFORM.                    "itab_user_command
    if you want to make the above code to work in lower versions then you have to do this..
    then maintain the ICON using the view V_ICON from SM30 add the New Entry.
    get the properties from the below screen shot.
    http://img404.imageshack.us/img404/3338/testig9.png

  • ALV - Sort on Subtotals

    Hi,
    Does anyone know how to sort on the subtotals of a numeric column in an ALV.
    Murali.

    Hi Santosh,
    Wouldnt this just sort a column and then show the subtotals ?
    a     X     1
    b     X     2
    c     X     3
    X subtotal     6     
    d     Y     4
    e     Y     5
    f     Y     6
    g     Y     7
    Y subtotal     22     
    Grand total     28
    I am looking to sort 22 and 6 in descending order with subtotal 22 at the top.
    Thanks
    Edited by: Muralidaran Shanmugam on Feb 10, 2010 7:11 AM

  • ALV Sort with cell merge

    Please help!
    When i run an ALV report in foreground, there is cell-merge when a column is sorted.
    However, when the ALV run @ background, why the cell-merge cannot work ? All data is listed, rather than is summarized into a block for all rows with the same field content.
    Please Advice
    Regards
    Annie

    Hi,
    see this example.
    TABLES : vbak.
    TYPE-POOLS: slis.                      " ALV Global types
    SELECT-OPTIONS :
      s_vkorg FOR vbak-vkorg,              " Sales organization
      s_kunnr FOR vbak-kunnr,              " Sold-to party
      s_vbeln FOR vbak-vbeln.              " Sales document
    SELECTION-SCREEN :
      SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.
    PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    DATA:
      BEGIN OF gt_vbak OCCURS 0,
        vkorg LIKE vbak-vkorg,             " Sales organization
        kunnr LIKE vbak-kunnr,             " Sold-to party
        vbeln LIKE vbak-vbeln,             " Sales document
        netwr LIKE vbak-netwr,             " Net Value of the Sales Order
        waerk LIKE vbak-waerk,             " Document currency
      END OF gt_vbak.
    INITIALIZATION.
      v_1 = 'Maximum of records to read'.
    START-OF-SELECTION.
      PERFORM f_read_data.
      PERFORM f_display_data.
    *      Form  f_read_data
    FORM f_read_data.
      SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
               FROM vbak
                 UP TO p_max ROWS
              WHERE kunnr IN s_kunnr
                AND vbeln IN s_vbeln
                AND vkorg IN s_vkorg.
    ENDFORM.                               " F_READ_DATA
    *      Form  f_display_data
    FORM f_display_data.
      DEFINE m_fieldcat.
        add 1 to ls_fieldcat-col_pos.
        ls_fieldcat-fieldname   = &1.
        ls_fieldcat-ref_tabname = 'VBAK'.
        ls_fieldcat-do_sum      = &2.
        ls_fieldcat-cfieldname  = &3.
        append ls_fieldcat to lt_fieldcat.
      END-OF-DEFINITION.
      DEFINE m_sort.
        add 1 to ls_sort-spos.
        ls_sort-fieldname = &1.
        ls_sort-up        = 'X'.
        ls_sort-subtot    = &2.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv,
        lt_sort     TYPE slis_t_sortinfo_alv,
        ls_sort     TYPE slis_sortinfo_alv,
        ls_layout   TYPE slis_layout_alv.
      m_fieldcat 'VKORG' ''  ''.
      m_fieldcat 'KUNNR' ''  ''.
      m_fieldcat 'VBELN' ''  ''.
      m_fieldcat 'NETWR' 'X' 'WAERK'.
      m_fieldcat 'WAERK' ''  ''.
      m_sort 'VKORG' 'X'.                  " Sort by vkorg and subtotal
      m_sort 'KUNNR' 'X'.                  " Sort by kunnr and subtotal
      m_sort 'VBELN' ''.                   " Sort by vbeln
      ls_layout-cell_merge = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                is_layout   = ls_layout
                it_fieldcat = lt_fieldcat
                it_sort     = lt_sort
           TABLES
                t_outtab    = gt_vbak.
    ENDFORM.
    rgds,
    bharat.

  • Inconsistency in ALV grid subtotal

    I have an oops ALV grid where I am doing subtotal by a particular column called 'PRDHA'. But my subtotal seems very inconsistent. It is grouping non-similar PRDHA's as one PRDHA.
    My assumption was that perhaps I need to sort the internal table (which in my case is a field symbol - <gt_tabletotal>) by that column 'PRDHA'. Is this right ? Please correct me if this assumption is right.
    Also this internal table is a dynamic internal table number of columns depend on certain conditions.
    How do I sort <gt_tabletotal> by PRDHA ?
    wa_sort2-fieldname = 'PRDHA'.
        wa_sort2-up = 'X'.
        wa_sort2-subtot = 'X'.
        append wa_sort2 to gt_sort.
      call method o_grid->set_table_for_first_display
        exporting
          is_variant      = gx_variant
          i_save          = 'A'
          is_layout       = gs_layout
        changing
          it_fieldcatalog = it_fldcat
          it_sort         = gt_sort[]
          it_outtab       = <gt_tabletotal>.
    (I am trying to subtotal by PRDHA. The row with '*' indicates the subtotal line and you see inconsistency )
    Report as is :
    Plant     Cont.  PRDHA   Material                     Desc.
    2001     021     18/10R     33200-1866043     AHDC 24/4.3oz AW BS&P     CS     0.000
         *         11/16T                                                                                     0.000
    2001     021     18/10R     33200-1866450     AHDC 24/4.3oz AW Brillnt Sprkl Gel     CS     0.000
    2001     021     18/10R     33200-2784000     AHDC 121g/24ct Enamel Care Korea     CS     0.000
    2001     021     18/10S     33200-1805330     AHDC 24/6.0oz Complete X-White     CS     8,100.000
         *       18/10R                                                                                    0.000
    2001     021     18/10S     33200-1877030     AHDC 24/6.0oz TC Peroxicare     CS     0.000
    2001     021     18/10S     33200-1886030     AHDC 24/6.0oz Peroxicare     CS     5,400.000
    2001     021     18/10S     33200-2781501     AHDC 178gr/24ct Complete Care Korea     CS     0.000
    2001     021     18/1M5     33130-1008010     AHDC 12/75ml Email Diamant Replenium     CS     0.000
         *         18/10S                                                                                           13,500.000

    Found it on my own.
    data : field(5) value 'PRDHA' .
    assign field to <prdha>.  
    sort <gt_tabletotal> ascending by (<prdha>).
    (If I dont sort the table by PRDHA, subtotal is inconsistent ).

  • ALV show subtotal

    i have a ALV report, i would like to show subtotal in the report.
    The following filed will appear in my report.
    Customer, Material, Description, Price1, Price2, Price3, Average Price.
    I want to group by customer, then sum the price1, price2, price and sumup average price / total of item.
    How can i do that in ALV. Thanks.

    Hi,
    Steps
    1) For the fields price1 & price2 have DO_SUM = 'X' in the field catalog internal table.
    2) Prepare a sort internal table with the customer field..
    DATA: T_SORT TYPE SLIS_T_SORTINFO_ALV.
    DATA: S_SORT LIKE LINE OF T_SORT.
    S_SORT-SPOS = '1'.
    S_SORT-FIELDNAME = 'KUNNR'.   "Customer field name.
    S_SORT-UP = 'X'.
    S_SORT-SUBTOT = 'X'.
    APPEND S_SORT TO T_SORT.
    3)
    Pass the internal table T_SORT to the parameter IT_SORT when calling the Function module.
    Thanks
    Naren

  • Regarding ALV sort & summation

    Hi
       I want to do sort & summation in ALV programatically.
    Can anyone provide me the sample code.
    Ponits are assured for helpful answers.
    Regards,
    kumar

    Hi,
    chk thi:
    report  zkeerthi_alv2                           .
    tables: vbak.
    type-pools : slis.
    data: begin of it_vbak occurs 0,
          icon type icon-id,
          vbeln like vbak-vbeln,
          audat like vbak-audat,
          vbtyp like vbak-vbtyp,
          auart like vbak-auart,
          augru like vbak-augru,
          netwr like vbak-netwr,
          waerk like vbak-waerk,
          end of it_vbak.
    data: g_repid like sy-repid,
          wa_sort type slis_sortinfo_alv,
          it_sort type slis_t_sortinfo_alv,
          wa_layout type slis_layout_alv,
          it_fieldtab type slis_t_fieldcat_alv,
          wa_fieldcat type slis_fieldcat_alv.
    selection-screen begin of block b1 with frame.
    select-options:s_vbeln for vbak-vbeln,
                   s_vbtyp for vbak-vbtyp default 'C'.
    selection-screen end of block b1 .
    selection-screen begin of block b2 with frame.
    parameters: list radiobutton group rad1,
                grid radiobutton group rad1.
    selection-screen end of block b2.
    initialization.
      g_repid = sy-repid.
    start-of-selection.
      select vbeln
             audat
             vbtyp
             auart
             augru
             netwr
             waerk into corresponding fields of table it_vbak
             from vbak where audat > '01/01/2004' and
             netwr > 0 and
             vbeln in s_vbeln and
             vbtyp in s_vbtyp.
      loop at it_vbak.
        if it_vbak-netwr < 10000.
          it_vbak-icon = '@08@'.
        elseif it_vbak-netwr > 10000 and it_vbak-netwr < 100000.
          it_vbak-icon = '@09@'.
        elseif it_vbak-netwr > 100000.
          it_vbak-icon = '@0A@'.
        endif.
        modify it_vbak index sy-tabix.
      endloop.
    end-of-selection.
      perform sort_list.
      perform modify_fieldcat.
      perform layout_list.
    *&      Form  sort_list
          text
    -->  p1        text
    <--  p2        text
    form sort_list .
      clear wa_sort.
      wa_sort-fieldname = 'AUART'.
      wa_sort-spos = '1'.
      wa_sort-up = 'X'.
      append wa_sort to it_sort.
      clear wa_sort.
      wa_sort-fieldname = 'VBTYP'.
      wa_sort-spos = '2'.
      wa_sort-up = 'X'.
      append wa_sort to it_sort.
      clear wa_sort.
      wa_sort-fieldname = 'WAERK'.
      wa_sort-spos = '3'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      append wa_sort to it_sort.
    endform.                    " sort_list
    *&      Form  layout_list
          text
    -->  p1        text
    <--  p2        text
    form layout_list .
      clear wa_layout.
      if list = 'X'.
        wa_layout-zebra = 'X'.
        wa_layout-window_titlebar = 'LIST DISPLAY'.
        wa_layout-subtotals_text = 'SUBTOTAL'.
        wa_layout-totals_text = 'TOTAL'.
        call function 'REUSE_ALV_LIST_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        = ' '
      I_STRUCTURE_NAME               =
           is_layout                      = wa_layout
           it_fieldcat                    = it_fieldtab[]
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
           it_sort                        = 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
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
          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.
      elseif grid = 'X'.
        wa_layout-zebra = 'X'.
        wa_layout-window_titlebar = 'GRID DISPLAY'.
        wa_layout-subtotals_text = 'SUBTOTAL'.
        wa_layout-totals_text = 'TOTAL'.
        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           = ' '
      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                         = wa_layout
           it_fieldcat                       = it_fieldtab
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
           it_sort                           = 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            =
          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.
      endif.
    endform.                    " layout_list
    *&      Form  modify_fieldcat
          text
    -->  p1        text
    <--  p2        text
    form modify_fieldcat .
      clear wa_fieldcat.
      wa_fieldcat-tabname   = 'IT_VBAK'.
      wa_fieldcat-fieldname = 'ICON'.
      wa_fieldcat-seltext_l  = 'LIGHTS'.
      wa_fieldcat-icon = 'X'.
    WA_FIELDCAT-ddictxt = 'l'.
      wa_fieldcat-col_pos = 1.
      wa_fieldcat-outputlen = 10.
      append wa_fieldcat to it_fieldtab.
      clear wa_fieldcat .
      wa_fieldcat-tabname   = 'IT_VBAK'.
      wa_fieldcat-fieldname = 'VBELN'.
      wa_fieldcat-seltext_l  = 'SALES DOCUMENT'.
    WA_FIELDCAT-ddictxt = 'l'.
      wa_fieldcat-col_pos = 2.
      wa_fieldcat-outputlen = 10.
      append wa_fieldcat to it_fieldtab.
      clear wa_fieldcat .
    when 'maktx'.
      wa_fieldcat-tabname   = 'IT_VBAK'.
      wa_fieldcat-fieldname = 'AUDAT'.
      wa_fieldcat-seltext_l  = 'DATE'.
    WA_FIELDCAT-ddictxt = 'l'.
      wa_fieldcat-col_pos = 3.
      wa_fieldcat-outputlen = 15.
      append wa_fieldcat to it_fieldtab.
      clear wa_fieldcat .
      wa_fieldcat-tabname   = 'IT_VBAK'.
      wa_fieldcat-fieldname = 'VBTYP'.
      wa_fieldcat-seltext_l  = 'SALES CATEGORY'.
      wa_fieldcat-col_pos = 4.
      wa_fieldcat-outputlen = 10.
      append wa_fieldcat to it_fieldtab.
      clear wa_fieldcat .
      wa_fieldcat-tabname   = 'IT_VBAK'.
      wa_fieldcat-fieldname = 'AUART'.
      wa_fieldcat-seltext_l  = 'SALES DOCUMENT TYPE'.
      wa_fieldcat-col_pos = 5.
      wa_fieldcat-outputlen = 10.
      append wa_fieldcat to it_fieldtab.
      clear wa_fieldcat .
      wa_fieldcat-tabname   = 'IT_VBAK'.
      wa_fieldcat-fieldname = 'AUGRU'.
      wa_fieldcat-seltext_l  = 'ORDER REASON'.
    WA_FIELDCAT-ddictxt = 'l'.
      wa_fieldcat-col_pos = 6.
      wa_fieldcat-outputlen = 10.
      append wa_fieldcat to it_fieldtab.
      clear wa_fieldcat .
      wa_fieldcat-tabname   = 'IT_VBAK'.
      wa_fieldcat-fieldname = 'NETWR'.
      wa_fieldcat-seltext_l  = 'QUANTITY'.
      wa_fieldcat-do_sum = 'X'.
    WA_FIELDCAT-ddictxt = 'l'.
      wa_fieldcat-col_pos = 7.
      wa_fieldcat-outputlen = 25.
      append wa_fieldcat to it_fieldtab.
      clear wa_fieldcat .
      wa_fieldcat-tabname   = 'IT_VBAK'.
      wa_fieldcat-fieldname = 'WAERK'.
      wa_fieldcat-seltext_l  = 'CURRENCY'.
    WA_FIELDCAT-ddictxt = 'l'.
      wa_fieldcat-col_pos = 8.
      wa_fieldcat-outputlen = 10.
      append wa_fieldcat to it_fieldtab.
      clear wa_fieldcat .
    endform.                    " modify_fieldcat
    regards,
    keerthi

  • ALV Grid  Subtotal text and Total text display

    Hello ABAPGuru's
    I want to display the subtotal and Total texts. alv grid program runing on background.
    Regards
    Sweety(Sri)

    Hello Neil,
    Here I have attached my routines.anyway my confusion. I have wrote the routine subtotal_text .but i am not passing ALV GRID FM.
    *&      Form  eventtab_build
    &----       This is used to get the list of events
    ----      <--RI_EVENTS  Internal table
    FORM eventtab_build  CHANGING ri_events TYPE slis_t_event.
    Structure for event handling.
      DATA: rs_event TYPE slis_alv_event.
    Returns table of possible events for a list type.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = ri_events.  " Table of events to perform
    Read the internal table with the TOP_OF_PAGE and move the
    form name to the internal table
      READ TABLE ri_events
        WITH KEY name = slis_ev_top_of_page INTO rs_event.
      IF sy-subrc = 0.
        MOVE c_formname TO rs_event-form.              " Form name
        MODIFY ri_events FROM rs_event
           INDEX sy-tabix.                  " Top of page event
      ENDIF.
      READ TABLE ri_events
         WITH KEY name = slis_ev_end_of_page INTO rs_event.
      IF sy-subrc = 0.
        MOVE c_form_eop_name TO rs_event-form.              " Form name
        MODIFY ri_events FROM rs_event
           INDEX sy-tabix.                  " Top of page event
      ENDIF.
      READ TABLE ri_events
          WITH KEY name = slis_ev_subtotal_text INTO rs_event.
      IF sy-subrc = 0.
        MOVE c_formname_subtotal_text TO rs_event-form.     " Formname
        MODIFY ri_events FROM rs_event
           INDEX sy-tabix.                  " Top of page event
      ENDIF.
    *&-- Delete all unneeded events:
    DELETE ri_events  WHERE form IS INITIAL.
    ENDFORM.                    " eventtab_build
    *&      Form  SUBTOTAL_TEXT
          text
    -->  p1        text
    <--  p2        text
    FORM SUBTOTAL_TEXT USING  ep_subtot_line     TYPE  type_data
                              e_event_data       TYPE  slis_subtot_text.
      IF NOT e_event_data-criteria IS INITIAL.
      E_EVENT_DATA-DISPLAY_TEXT_FOR_SUBTOTAL = 'Account Total'.
       ENDIF.
    ENDFORM.                    "SUBTOTAL_TEXT
    *&      Form  initialise_layout
          Initialise Layout
    FORM initialise_layout .
      i_layout-colwidth_optimize = c_x.
      i_layout-group_change_edit = c_x.
    *i_layout-subtotals_text = ' a'.
      i_layout-detail_popup   = c_x.
    i_layout-zebra          = c_x.
      i_layout-no_vline       = 'X'.
      i_layout-no_hline       = 'X'.
      i_layout-totals_text = 'Account Total'.
    ENDFORM.                    " initialise_layout
    Call the function module to display the report
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program     = v_program
          i_callback_top_of_page = 'TOP_OF_PAGE'       "Top Of Page
          is_layout              = i_layout
          it_fieldcat            = i_fieldtab
          it_sort                = i_sort
          it_events              = i_events         " Events
          is_print               = i_print
          i_default              = c_x
          i_save                 = c_save
          is_variant             = v_variant
        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.
    Regards
    Sweety (Sri)

  • ALV Sort problem

    Hi Experts,
    I have encountered a peculiar situation with respect to ALV, using sort. The problem is as follows:
    1. I have an internal table with 3 fields, upon which I am supposed to implement a sort criteria on the first two fields.
    2. My data is something like this, for ex:
    abc  1  a
    abc  1  b
    cde  1  a
    cde  1  b
    3. I have applied sort criteria, on the first two fields and passed to the fm "REUSE_ALV_GRID_DISPLAY'.
    4. Now the output is as follows:
    abc  1  a
      --  b
    cde --  a
    ---   --  b
    Here ( -- ) dotted lines mean the identical entry from the previous row...
    5. My requirement is I want the output as:
    abc  1  a
    ---  --   b
    cde  1  a
    ---   --  b 
    I mean the sort critetia of the second column should follow the first(adjacent column) sort criteria
    I hope it is clearly explained, and kindly let me know how this can be solved..
    Thank you,
    Shashi

    Hi Bala,
    The suggested solution is not giving the desired results..
    This happens because, when i sort the entries i mentioned earlier, remains the same, even after the two explicit sort statements on the internal table.
    Kindly check the same and let me know.
    Regards,
    Shashi

  • Alv sorting

    hi
    need to sort alv data, but the entries are like header and item
    means first line is of header data and if has items then
          the items will be displayed starting from second line but some columns for all items
          will be empty (means header data at the top line refers)
    now second header data comes and then its items.
    in such case how to sort the ALV basing on the header number.
    while sorting all the items are going at the bottom since it has no header number in its line
      and header items are coming at the top
    how to sort these entries correctly

    Hi,
    Try this
    DATA : gt_sort TYPE slis_t_sortinfo_alv,
               wa_sort TYPE slis_sortinfo_alv.
    PERFORM fill_sort.               " Filling sort of REUSE_ALV_GRID_DISPALY
    FORM fill_sort .
      wa_sort-fieldname = 'MATNR'.
      wa_sort-up = c_x.
      APPEND wa_sort TO gt_sort.
      CLEAR wa_sort.
    ENDFORM.                    " FILL_SORT
          CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
              i_callback_program = g_repid
              i_grid_title       = text-012
              is_layout          = wa_slis_layout
              it_sort            = gt_sort[]
              it_fieldcat        = gt_fieldcat[]
              i_save             = 'A'              
            TABLES
              t_outtab           = <fs_table>
            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.

  • ALV display subtotal only on one column

    Hi Everyone,
    I'm trying to display in alv format a report that has the % in the subtotals only. (I still need the individual lines, but not the percentage on them, just on the subtotal).
    Can anyone suggest how to do this, for example, by working out the percentage on each line, and hiding the contents except for the subtotals. Or calculating the percentage on the subtotal line. Below is an example of what I'm after.
    a     X     1
    b     X     2
    c     X     3
    X subtotal     6     21.43%
    d     Y     4
    e     Y     5
    f     Y     6
    g     Y     7
    Y subtotal     22     78.57%
    Grand total     28
    Thank you
    Tim

    Hi Vinod,
    Thank you for your reply.
    Thats the part I've already figured out. I'm after how to display only the subtotals for the percentage on the ALV.
    regards
    Tim

  • Query on ALV List Subtotal texts

    Hi,
    I am using the FM REUSE_ALV_LIST_DISPLAY and my internal table would have data categorized by for ex. two company codes 1000 and 2000.
    My requirement is for the subtotal text to display something like this during the subtotals-
    Total: 1000 <Company code text for 1000>
    instead of the existing
    <w_fieldcat-seltext_> 1000.
    I have tried changing the field seltext_l in the  fieldcat for the first field 'BUKRS', which is working. But i need the changed value of the company code (i.e. like "Total: 2000 <company code text for 2000>" at the next summation level, which i am unable to get as the fieldcat modifications do not reflect in between the ALV list.
    I have also tried changing layout-subtotals_text, but of no use.
    Any pointers/help would be useful.
    Thanks in advance,
    Daksh.

    You need activate the event for SUBTOTAL TEXT and handle the text in there. There is a sample program in BCALV which does the same, take a look at that.
    Regards,
    Ravi
    Note : Please mark all the helpful answers

Maybe you are looking for

  • One Open Directory server for multiple businesses?

    Hi all, Is it possible to have one Mac OS X server seen by client computers through different domain names? See, I have one server now, with name: server01.it.lan As we are managing three different companies, I'd like the users working for one partic

  • Acc tag - iTunes Library unsynced

    Hi, I have this very strange problem: when I try to change some data in some files through the iTunes (i.e. the "artist" field) I see it change in iTunes, but first time I play it it came right back to the wrong one. It happens also by telling iTunes

  • Help please: static instance of a class

    Hello guys, I'm quite new to Java (I had abandonned it for years, and now i'm recovering the good habbits) and i am finding trouble with an static instance of a class. The thing is that I created a JSP page that calls a Java class. My JSP page will b

  • How can I print to PDF?

    I need the ability to print to PDF is this possible?

  • I'm now restricted, but this has got to be unfair?

    I know a lot of people moan about BT, generally about speed and the 100gb fair usage limit, but personally myself I have always been a fan. I get decent speeds and I know the 100gb limit is there and for me that's more than enough. This month however