ABAP Dialog Programming : Sorting selected column in Table Control

This is example of abap code for sorting selected table control.

*---------------------------------------------------------------------*
*      Form  F_SORT_TABLE
*---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      By Oka Wirasatha
*----------------------------------------------------------------------*
form F_SORT_TABLE using FV_CODE.
  field-symbols :
    <lfs1>,
    <selected_col> type CXTAB_COLUMN.

  data : LW_COLS like TC_ITEM-COLS.
  data : LV_TXT1(20),
         LV_INDEX(2) type N.
  data : begin of W_SORT,
          SORT01(20),
          SORT02(20),
          SORT03(20),
          SORT04(20),
          SORT05(20),
          SORT06(20),
          SORT07(20),
    end of W_SORT.

* find out if a column is selected.
  LV_INDEX = 0.
  clear W_SORT.
  loop at TC_ITEM-COLS assigning <selected_col>.
    if <selected_col>-SELECTED = 'X'.
      LV_INDEX = LV_INDEX + 1.
      concatenate 'w_sort-sort' LV_INDEX into LV_TXT1.
      assign (LV_TXT1) to <lfs1>.
      <lfs1> = <selected_col>-SCREEN-NAME+7(10).
    endif.
  endloop.

  if not W_SORT is initial.
    if FV_CODE = 'ASC'.
      sort T_ITEM by (W_SORT-SORT01).
    else.
      sort T_ITEM descending by (W_SORT-SORT01).
    endif.
  else.
    message S000(ZMM) with 'No column is selected'.
  endif.

endform.                    " sort_table

Comments

Popular posts from this blog

ABAP Dialog Programming : Set Filter data of Table Control

Step by step Create SAP LIS Report

SAP Bapi Price Change (MR21)