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

Sort Table based on Display Variant

Former Member
0 Likes
1,050

Hi...

I want to Sort a table based on Display Variant Sort option??

Please Help????

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
913

Hi Try this...

FM..

K_KKB_OUTTAB_SORT

  • To Sort Data

CALL FUNCTION 'K_KKB_OUTTAB_SORT'

EXPORTING

IT_SORT = I_SORT

TABLES

T_OUTTAB = I_MAIL_FINAL

EXCEPTIONS

SORTFIELD_NOT_FOUND = 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.

5 REPLIES 5
Read only

Former Member
0 Likes
914

Hi Try this...

FM..

K_KKB_OUTTAB_SORT

  • To Sort Data

CALL FUNCTION 'K_KKB_OUTTAB_SORT'

EXPORTING

IT_SORT = I_SORT

TABLES

T_OUTTAB = I_MAIL_FINAL

EXCEPTIONS

SORTFIELD_NOT_FOUND = 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.

Read only

0 Likes
913

Hmmm......

Read only

ingo_barschow
Explorer
0 Likes
913

Hi shashi,

in sy-slset SAP stores the name of the variant.

CASE sy-slset.
  WHEN 'TEST01'. SORT gt_itab BY x y z.
  WHEN 'TEST02'. SORT gt_itab BY y x z.
  WHEN OTHERS. SORT gt_itab.
ENDCASE.

Read only

0 Likes
913

Thanks for your reply..

But user can create new variants too..

In that case How to get the fields which are used for sorting???

Read only

ingo_barschow
Explorer
0 Likes
913

Hi Sashi,

I'm not sure understanding your needs. Maybe you have to read the SELECT-OPTIONS or using some radiobuttons / checkboxes to get the users preferences?

In other case, all known variants are stored in SAP-table VARIT, the specific field-descriptions and values you can retrieve by using function module 'RS_VARIANT_CONTENTS' (some informations are also in SAP-table VARID).

Hope it will help, otherwise try to explain what the user should do, please.