Skip to Content
author's profile photo Former Member
Former Member

sort in alv report

Dear Freinds,

How to display sorted field in alv list.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2008 at 09:27 AM

    hi check this..

    &----


    *& Report ZALVTESTFORSUBTOTAL

    *&

    &----


    *&

    *&

    &----


    REPORT ZALVTESTFORSUBTOTAL.

    tables:pa0008.

    type-pools:slis.

    types:begin of ty_pa0008,

    pernr like pa0008-pernr,

    begda like pa0008-begda,

    endda like pa0008-endda,

    ansal like pa0008-ansal,

    lga01 like pa0008-lga01,

    bet01 like pa0008-bet01,

    end of ty_pa0008.

    data:it_pa0008 type standard table of ty_pa0008 with header line.

    data:it_fieldcat type SLIS_T_FIELDCAT_ALV,

    wa_fieldcat type slis_fieldcat_alv,

    it_layout type slis_layout_alv,

    WA_events TYPE slis_alv_event,

    it_events TYPE slis_t_event.

    select-options:s_pernr for pa0008-pernr.

    start-of-selection.

    perform getD_data.

    perform disp_alv.

    &----


    *& Form getD_data

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form getD_data .

    select pernr

    begda

    endda

    ansal

    lga01

    bet01

    from pa0008

    into table it_pa0008

    where pernr in s_pernr.

    sort it_pa0008 by pernr begda descending.

    endform. " getD_data

    &----


    *& Form disp_alv

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form disp_alv .

    wa_fieldcat-fieldname = 'PERNR'.

    wa_FIELDCAT-REPTEXT_DDIC = 'Personnel no'.

    *WA_FIELDCAT-no_subtotals = 'X'.

    append wa_fieldcat to it_fieldcat.

    clear wa_fieldcat.

    wa_fieldcat-fieldname = 'BEGDA'.

    wa_FIELDCAT-REPTEXT_DDIC = 'Start date'.

    append wa_fieldcat to it_fieldcat.

    clear wa_fieldcat.

    wa_fieldcat-fieldname = 'ENDDA'.

    wa_FIELDCAT-REPTEXT_DDIC = 'End date'.

    append wa_fieldcat to it_fieldcat.

    clear wa_fieldcat.

    wa_fieldcat-fieldname = 'ANSAL'.

    wa_FIELDCAT-REPTEXT_DDIC = 'Annula salary'.

    wa_fieldcat-do_sum = 'X'.

    append wa_fieldcat to it_fieldcat.

    clear wa_fieldcat.

    wa_fieldcat-fieldname = 'LGA01'.

    wa_FIELDCAT-REPTEXT_DDIC = 'Wage Type'.

    append wa_fieldcat to it_fieldcat.

    clear wa_fieldcat.

    wa_fieldcat-fieldname = 'BET01'.

    wa_FIELDCAT-REPTEXT_DDIC = 'Amount for wagetype'.

    append wa_fieldcat to it_fieldcat.

    clear wa_fieldcat.

    DATA: sort TYPE slis_sortinfo_alv,

    it_sort TYPE slis_t_sortinfo_alv.

    sort-fieldname = 'PERNR'.

    sort-subtot = 'X'.

    SORT-UP = 'X'.

    APPEND sort TO it_sort.

    *sort-fieldname = 'BEGDA'.

    *SORT-NO_SUBTOTS = 'X'.

    *APPEND sort TO it_sort.

    IT_layout-totals_text = 'total text'.

    IT_layout-subtotals_text = 'Subtotal text'.

    *WA_EVENTS-NAME = 'SUBTOTAL TEXT'.

    *WA_EVENTS-FORM = 'SUBTOTAL TEXT'.

    *APPEND WA_EVENTS TO IT_EVENTS.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = sy-repid

    IS_LAYOUT = it_LAYOUT

    IT_FIELDCAT = IT_FIELDCAT

    it_sort = it_sort

    • it_events = it_events

    TABLES

    t_outtab = it_pa0008 .

    endform. " disp_alv

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2008 at 09:18 AM

    Hi,

    Please refer the code below :

    *  ALV data declarations
      data: it_sortcat   type slis_sortinfo_alv occurs 1,
            wa_sort like line of it_sortcat.
    
     perform build_sortcat.
    
    *&------------------------------------------------------------------*
    *&      Form  build_sortcat
    *&------------------------------------------------------------------*
    *       Build Sort catalog
    *-------------------------------------------------------------------*
    FORM build_sortcat .
      wa_sort-spos      = 1.
      wa_sort-fieldname = 'EBELN'.
      wa_sort-SUBTOT    = 'X'. "subtotals any totals column by this field
    *  gd_sortcat-tabname
      APPEND wa_sort TO it_sortcat.
    
      wa_sort-spos      = 2.
      wa_sort-fieldname = 'EBELP'.
    *  gd_sortcat-tabname
      APPEND wa_sort TO it_sortcat.
    ENDFORM.                    " build_sortcat
    
    "And pass the it_sort to I_SORT export parameters ALV FM
    

    Thanks,

    Sriram Ponna.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2008 at 09:23 AM

    Hi,

    Their is a field in field catalog FM SORT give it X your problem will be solved.

    Reward some points.

    Regards,

    Anomitro Guha

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 16, 2008 at 09:25 AM

    Hi,

    If you want to sort the list then sort the internal table before disaplying thrgh ALV.

    Or after dispaly you can sort the list by using sort button on alv toolbar.

    Reward pts if helpfull

    Regards,

    Dhan

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.