Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

SORT in ALV

1. Inorder to SORT the table data,you have to create an internal table of type LVC_T_SORT.

LVC_T_SORT is a table type whic has a line type LVC_S_SORT.

LVC_S_SORT contains the following fields:

2. You need to create a work area of type LVC_S_SORT

3. Populate the internal table using this work area and pass it to the method
SET_TABLE_FOR_FIRST_DISPLAY using the parameter IT_SORT.

Example:

REPORT ZTEST.
DATA:

R_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
R_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA:
T_SFLIGHT TYPE TABLE OF SFLIGHT,
FS_SFLIGHT TYPE SFLIGHT.

DATA:
T_SORT TYPE LVC_T_SORT,
FS_SORT TYPE LVC_S_SORT.

SELECT * FROM SFLIGHT INTO TABLE T_SFLIGHT.

FS_SORT-SPOS ='1'.
FS_SORT-FIELDNAME = 'CARRID'.
FS_SORT-DOWN = 'X'.
FS_SORT-SUBTOT = 'X'.
APPEND FS_SORT TO T_SORT.
clear fs_sort.

FS_SORT-SPOS ='2'.
FS_SORT-FIELDNAME = 'CONNID'.
FS_SORT-UP = 'X'.
APPEND FS_SORT TO T_SORT.
clear fs_sort.

CALL SCREEN 100.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'SCREEN'.
SET TITLEBAR 'TITLE'.

ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.

*&---------------------------------------------------------------------*
*& Module HANDLER OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE LIST OUTPUT.

CREATE OBJECT
R_CONTAINER
EXPORTING
CONTAINER_NAME = 'CONTAINER'.

CREATE OBJECT R_GRID
EXPORTING
I_PARENT = R_CONTAINER.

CALL METHOD R_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING
IT_OUTTAB = T_SFLIGHT
IT_SORT = T_SORT.

ENDMODULE.


Result:

  • No labels