Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

sorting in alv.

Former Member
0 Likes
898

Hi,

TYPES: BEGIN OF TY_ANLA,

ANLN1 TYPE ANLA-ANLN1,

TXT50 TYPE ANLA-TXT50,

END OF TY_ANLA.

TYPES:BEGIN OF TY_FINAL,

ICON TYPE ICON-ID,

ANLA TYPE TY_ANLA,

LMSG TYPE CHAR512,

END OF TY_FINAL.

DATA: GT_ANLA TYPE TABLE OF TY_ANLA,

GT_FINAL TYPE TABLE OF TY_FINAL.

DATA: WA_FINAL TYPE TY_FINAL,

WA_ANLA TYPE TY_ANLA.

my final internal table gt_final contains the data.

i want to sort the GT_FINAL based on ANLN1 in ALVs

i wrote below code.

data:LT_SORT TYPE SLIS_T_SORTINFO_ALV,

WA_SORT TYPE SLIS_SORTINFO_ALV.

WA_SORT-FIELDNAME = 'ANLA-ANLN1'.

WA_SORT-TABNAME = 'GT_FINAL'.

WA_SORT-UP = 'X'.

APPEND WA_SORT TO LT_SORT.

CLEAR WA_SORT.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = GT_FIELDCAT

IT_SORT = LT_SORT

TABLES

T_OUTTAB = GT_FINAL

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

.

Data is not sorting Properly.

Please help me on this.

Regards,

Suresh.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
807

Hi,

Try this way..

WA_SORT-FIELDNAME = 'ANLN1'.
WA_SORT-TABNAME = 'GT_FINAL'.
WA_SORT-UP = 'X'.
APPEND WA_SORT TO LT_SORT.
CLEAR WA_SORT.

5 REPLIES 5
Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
807

Hi Suresh,

Use this link for a WIKI on ALV, this covers most of the parameters for REUSE_ALV_GRID_DISPLAY.

https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/learn%252bto%252bdisplay%252bdata%252bin...

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/an%20easy%20r...

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir

Read only

Former Member
0 Likes
807

hi

visit threads

hope this helps

regards

Aakash Banga

Read only

Former Member
0 Likes
808

Hi,

Try this way..

WA_SORT-FIELDNAME = 'ANLN1'.
WA_SORT-TABNAME = 'GT_FINAL'.
WA_SORT-UP = 'X'.
APPEND WA_SORT TO LT_SORT.
CLEAR WA_SORT.

Read only

Former Member
0 Likes
807

Hi Suresh,

For Sorting, you first have to declare one internal table and a work area of type:

DATA: itab_sort TYPE slis_t_sortinfo_alv,

wa_sort TYPE slis_sortinfo_alv.

Then to declare that internal table for the particular field according to which you want to sort the contents for eg:

Manintainig internal table for sorting

wa_sort-spos = 1.

wa_sort-fieldname = 'EBELP'.

wa_sort-tabname = 'IT_tab'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO itab_sort.

CLEAR wa_sort.

Then pass that internal table in the function module REUSE_ALV_GRID_DISPLAY for eg:

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = sy-repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

I_CALLBACK_TOP_OF_PAGE = 'TOP'

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

IT_FIELDCAT = it_field

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = itab_sort

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = ITAB_EVENTS

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP = 0

  • I_HTML_HEIGHT_END = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • IR_SALV_FULLSCREEN_ADAPTER =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = it_tab

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

Hope it helps you.

Thanks Mansi

Read only

Former Member
0 Likes
807

Hi,

Thanks for replies.

Regards,

Suresh.