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.

Similar Messages

  • 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 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.

  • 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 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 - 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.

  • 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

  • ALV Sort Vertical Merging

    I am trying to display a table in a subscreen,
    1. I have made my sort table and passed it to the set_table_first_display.
    lw_sort-spos = '1'.
    lw_sort-fieldname = 'KUNNR'.
    lw_sort-up = c_x.
    * Append Work Area to the Table
    APPEND lw_sort TO p_sort.
    CLEAR  lw_sort.
    2. I have also made sure that the No_merging field is not marked in the fieldcatalog and layout.
    But inspite of all of this, the cells do NOT get vertically merged.
    I was under the impression, In ALV Grid Display, the Sort Criterion by default makes the column contents Vertically merged.
    Basically I am getting this as a display,
    1400 -------other data -----
    1400 -------other data -----
    1500 -------other data -----
    1500 -------other data -----
    I want this,
    1400 -------other data -----
         -------other data -----
    1500 -------other data -----
         -------other data -----
    How do I achieve this? Doesnt this generally come default in ALV Grid?
    Also let me add, my display table is editable, so does this default vertical merge get turned off in any scenario?
    Has anyone encountered this/something similar?
    Would be thrilled to get a solution.
    Thanx.
    Message was edited by: Prasenjit Guha
    Message was edited by: Prasenjit Guha

    Hi Serdar thank you for your post.
    How do you suggest I achieve the following for an editable grid.
    Current Display,
    1400 -------other data -----
    1400 -------other data -----
    1500 -------other data -----
    1500 -------other data -----
    I want this,
    1400 -------other data -----
         -------other data -----
    1500 -------other data -----
         -------other data -----

  • Getting UNCAUGHT_EXCEPTION CX_WD_CONTEXT at using alv sort function

    Dear colleagues,
    I developed a simple application which displays records in an ALV and at lead-selection shows detailed data in a form. Everthing is working fine except one is clicking on the sort functionality at the top of the ALV short dump is thrown.
    In trx ST22 I find :
    The lead selection has not been set. V_DEFAULT
    "UNCAUGHT_EXCEPTION" "CX_WD_CONTEXT"
    "CL_WDR_CONTEXT_NODE===========CP" or "CL_WDR_CONTEXT_NODE===========CM00R"
    "_RAISE_ELEMENT_NOT_FOUND"
    Lead selection is checked and also debugging the code did not bring me any further.
    Any help is greatly appreciated.
    Thanks in advance
    Michael

    Hi Regina,
    first of all thanks for your quick answer and explanation. I'm not sure what you mean with 'register to the standard functions of the ALV' because this is a functionality which works in other ALVs without register any event method to them or do you mean that in my case I have to react to the sorting in a new method in the view controller? Concerning 'refill the subnode via supply function' I'm doing this already.
    Disabling the sorting is no option anymore because the users already know and love this feature
    Regards
    Michael

  • Simple question about ALV sorting

    I retrieve data from SFLIGHT table and display it in ALV by using cl_salv_table class. I added a sorting column PRICE as follows:
    data r_salv_sort type ref to cl_salv_sorts.
    r_salv_sort = r_salv_table->get_sorts( ).
    r_salv_sort->add_sort('PRICE').
    and got exception message:
    Subtotals cannot be calculated on aggregatable columns
    it is fine when I change from PRICE column to CONNID column.
    What could be the reason for that? I just want to sort the Price column. Thanks!

    We can do the sorting on the Quantity or Amount column once it ALV is displayed. Because now the control is no more with the SALV model. It is with the ALV framework.
    SALV model doesn't allow the sorting on the columns on which you can perform the Agreegation.
    You can save the default layout variant and then start the ALV with that variant.
    Regards,
    Naimesh Patel

  • ALV sort any column in fieldcatalog by default

    hi all
    i have developed report in ALV format. i have total 8 columns
    normally we sort any column in the output only.
    i have requirement that instead of sorting manually any column say Material no
    it should be sorted by default when user execute the report. he should not do manually by pressing Sort button in
    alv list
    give code for refrence

    hi u can use the IT_SORT parameter of the FM REUSE_ALV_GRID_DISPLAY for this purpose.
    specify the fields for which u need to sort ur table and the sorting order
    ( I have jst given da example for one field but this it_sort table can hav more than one fields.)
      gs_alv_sort-spos = 1.
      gs_alv_sort-fieldname = 'VKORG'.            " Sales Org
      gs_alv_sort-up = 'X'.                       " Ascending
      APPEND gs_alv_sort TO gt_alv_sort.
    then pass this internal table to teh alv fm
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
         I_CALLBACK_PROGRAM                = wf_repid
       I_CALLBACK_HTML_TOP_OF_PAGE       = 'HTML_TOP_OF_PAGE'
       I_BACKGROUND_ID                   = 'WEAVE_BACKGROUND'
       IS_LAYOUT                         = gs_alv_layout
       IT_FIELDCAT                       =  gt_alv_fieldcat
       IT_SORT                           =  gt_alv_sort
        TABLES
          T_OUTTAB                          = it_output
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2

  • Getting row information after an ALV sort

    I am using cl_gui_alv_grid.  My problem occurs after a user sorts the table.  All of the index values no longer match to the original table I passed to the class.  How do I match the results from
    CALL METHOD my_catlistgrid->get_selected_rows
       IMPORTING
        et_index_rows  = selected_rows.
    to my original itab?

    Let me be more specific.  I have an object that is handling the events double_click(), I have a button on the APP toolbar that will end up calling any or all of the following methods.
      CALL METHOD my_catlistgrid->get_selected_rows
       IMPORTING
        et_index_rows  = selected_rows.
      CALL METHOD my_catlistgrid->get_selected_cells_id
       IMPORTING
          ET_CELLS  =   selected_cells_id.
      CALL METHOD my_catlistgrid->get_selected_cells
       IMPORTING
          ET_CELL  =   selected_cells.
    Each of this methid returns to me the index(position) of the selected row in the ALVgrid.  After a sort in the ALV grid, row 1 does not relate to row 1 in the itab I passed to the ALV grid anymore.

  • Regarding ALV sort option

    HI ABAPer's,
    In my ALV Report i am using the sort option for all fields,In this report PO no one column and PO line item one column.
    If i am using the Sort layout option for both fields all similar values is merge but my requirement is for each PO the line item should be merge not for all values,Could you please help regarding this.
    Eg: PO No          POLine
          101                 1
                                2
                                3
         102                  1
          103                 1
          104                 1
                                 2
          105                 1
    Like that but now output is 
    Eg: PO No          POLine
          101                 1
                                2
                                3
          102                 1
          103                
          104                
                                2
          105                 1 like this could yo

    Hi,
    Please try sorting only PO No.
    In the case single PO containing same line items : Use delete adjascent duplicates.
    In case Line item are coming 1
                                               3
                                               2  jumbled order :  sort the Line no: in internal table only not In ALV option.
    Best Regards,
    Ashiq Hafeez

  • 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

Maybe you are looking for

  • "Activation Required" on a 3 year old iphone?

    I have had the same Iphone 3gs for about 3 years now. I have never had a real issue with it. Last night the battery died while i was sleeping, and this morning when I put it on the charger, it says "Activation required" but then it wont connect to my

  • Dynamic HTML Content in iFrames of a BSP application

    Hey Folks, I am currently having to build a context sensitive URL, which is built dynamically and accordingly load the page within a given view during runtime. The URL points to a simple HTML page. The application whcih is embedded in the view is a B

  • OAM alerts setup for Concurrent services down using workflow mailer

    Hi, We have ORacle Ebiz 12.0.6 with 10.2.0.4 database. Can some one please provide details how to end notification email for Concurrent services down using OAM in R12 with workflow. I have done the setup in clone with workflow up and running... and h

  • EDI - Material doc not created

    Hello,        Iam working with WMMBXY/WMMBID02 (WMMB)  to post a GR on receipt of an inbound IDOC.Iam able to post the GR but material document is not created.Iam posting against an inbound delivery created against a stock transfer order.In my case I

  • April 21, 2012 - UNABLE TO DOWNLOAD SONGS OR APP UPDATES

    Hello, I have been try to purchase songs, and download my app update, but it keeps saying it can not connect... I am connected to the internet.  I use Window's 7, have an Iphone and Ipad and PC and it doesnt work on either one. THanks.