Here is the simple program to sort selected columns within ALV grid.
=========================================================================
REPORT ZSORT_ALV.
type-pools: SLIS.
data:
begin of wa_SFLIGHT,
carrid type sflight-carrid,
connid type sflight-connid,
FLDATE type sflight-FLDATE,
PRICE type sflight-PRICE,
CURRENCY type sflight-CURRENCY,
end of wa_SFLIGHT,
it_sflight like STANDARD TABLE OF wa_sflight,
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
it_sort type SLIS_T_SORTINFO_ALV WITH HEADER LINE.
perform fill_fieldcat.
select * from SFLIGHT into corresponding fields of TABLE it_SFLIGHT.
it_sort-spos = 01.
it_sort-fieldname = 'CARRID'.
it_sort-UP = 'X'.
it_sort-SUBTOT = 'X'.
APPEND it_sort.
it_sort-spos = 02.
it_sort-fieldname = 'CONNID'.
it_sort-UP = 'X'.
it_sort-SUBTOT = 'X'.
APPEND it_sort.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = IT_FIELDCAT[]
IT_SORT = IT_SORT[]
TABLES
t_outtab = it_SFLIGHT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
ENDIF.
FORM FILL_FIELDCAT .
IT_FIELDCAT-col_pos = 1.
IT_FIELDCAT-fieldname = 'CARRID'.
IT_FIELDCAT-tabname = 'IT_SFLIGHT'.
IT_FIELDCAT-seltext_m = ' Carrid '.
APPEND IT_FIELDCAT.
IT_FIELDCAT-col_pos = 2.
IT_FIELDCAT-fieldname = 'CONNID'.
IT_FIELDCAT-tabname = 'IT_SFLIGHT'.
IT_FIELDCAT-seltext_m = ' Connid '.
APPEND IT_FIELDCAT.
IT_FIELDCAT-col_pos = 3.
IT_FIELDCAT-fieldname = 'FLDATE'.
IT_FIELDCAT-tabname = 'IT_SFLIGHT'.
IT_FIELDCAT-seltext_m = ' Date '.
APPEND IT_FIELDCAT.
IT_FIELDCAT-col_pos = 4.
IT_FIELDCAT-fieldname = 'PRICE'.
IT_FIELDCAT-tabname = 'IT_SFLIGHT'.
IT_FIELDCAT-seltext_m = ' Price '.
APPEND IT_FIELDCAT.
IT_FIELDCAT-col_pos = 5.
IT_FIELDCAT-fieldname = 'CURRENCY'.
IT_FIELDCAT-tabname = 'IT_SFLIGHT'.
IT_FIELDCAT-seltext_m = ' Currency '.
APPEND IT_FIELDCAT.
ENDFORM.
=========================================================================
And the output is :
=========================================================================
REPORT ZSORT_ALV.
type-pools: SLIS.
data:
begin of wa_SFLIGHT,
carrid type sflight-carrid,
connid type sflight-connid,
FLDATE type sflight-FLDATE,
PRICE type sflight-PRICE,
CURRENCY type sflight-CURRENCY,
end of wa_SFLIGHT,
it_sflight like STANDARD TABLE OF wa_sflight,
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
it_sort type SLIS_T_SORTINFO_ALV WITH HEADER LINE.
perform fill_fieldcat.
select * from SFLIGHT into corresponding fields of TABLE it_SFLIGHT.
it_sort-spos = 01.
it_sort-fieldname = 'CARRID'.
it_sort-UP = 'X'.
it_sort-SUBTOT = 'X'.
APPEND it_sort.
it_sort-spos = 02.
it_sort-fieldname = 'CONNID'.
it_sort-UP = 'X'.
it_sort-SUBTOT = 'X'.
APPEND it_sort.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = IT_FIELDCAT[]
IT_SORT = IT_SORT[]
TABLES
t_outtab = it_SFLIGHT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
ENDIF.
FORM FILL_FIELDCAT .
IT_FIELDCAT-col_pos = 1.
IT_FIELDCAT-fieldname = 'CARRID'.
IT_FIELDCAT-tabname = 'IT_SFLIGHT'.
IT_FIELDCAT-seltext_m = ' Carrid '.
APPEND IT_FIELDCAT.
IT_FIELDCAT-col_pos = 2.
IT_FIELDCAT-fieldname = 'CONNID'.
IT_FIELDCAT-tabname = 'IT_SFLIGHT'.
IT_FIELDCAT-seltext_m = ' Connid '.
APPEND IT_FIELDCAT.
IT_FIELDCAT-col_pos = 3.
IT_FIELDCAT-fieldname = 'FLDATE'.
IT_FIELDCAT-tabname = 'IT_SFLIGHT'.
IT_FIELDCAT-seltext_m = ' Date '.
APPEND IT_FIELDCAT.
IT_FIELDCAT-col_pos = 4.
IT_FIELDCAT-fieldname = 'PRICE'.
IT_FIELDCAT-tabname = 'IT_SFLIGHT'.
IT_FIELDCAT-seltext_m = ' Price '.
APPEND IT_FIELDCAT.
IT_FIELDCAT-col_pos = 5.
IT_FIELDCAT-fieldname = 'CURRENCY'.
IT_FIELDCAT-tabname = 'IT_SFLIGHT'.
IT_FIELDCAT-seltext_m = ' Currency '.
APPEND IT_FIELDCAT.
ENDFORM.
=========================================================================
And the output is :
adding custom sort to pivot grid table
ReplyDeleteThis is nice article for who is interested in learning SAP BPC.Thanks for sharing SAP BPC Online Training information with us. SAP BPC ONLINE TRAINING
ReplyDelete