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

Sorted Internal tables.

Former Member
0 Likes
519

Hi ,

Could you please tell me how to declare a sorted internal table of type sy-uname.

Is there any different method to read sorted internal table than we normally do?

Please suggest.

Thanks,

Suchi.

1 ACCEPTED SOLUTION
Read only

sreekanthgo
Contributor
0 Likes
482

Hi Suchi,

Check the below link.

http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3800358411d1829f0000e829fbfe/content.htm

You can use Binary search on sorted internal table.

Search forum on how to use Binary search and its importance.

REPORT  YSK_TEST_SORT.


TYPES: BEGIN OF T_TAB,
         UNAME TYPE SY-UNAME,
       END OF T_TAB.

TYPES: TT_TAB TYPE SORTED TABLE OF T_TAB WITH UNIQUE KEY UNAME.

DATA: IT_TAB TYPE TT_TAB,
      WA_TAB TYPE T_TAB.

WA_TAB-UNAME = 'ZZZZ'.
INSERT WA_TAB INTO TABLE IT_TAB.

WA_TAB-UNAME = 'ABCD'.
INSERT WA_TAB INTO TABLE IT_TAB.


LOOP AT IT_TAB INTO WA_TAB.

  WRITE:/ WA_TAB-UNAME.

ENDLOOP.

Thanks,

Sreekanth

3 REPLIES 3
Read only

sreekanthgo
Contributor
0 Likes
483

Hi Suchi,

Check the below link.

http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3800358411d1829f0000e829fbfe/content.htm

You can use Binary search on sorted internal table.

Search forum on how to use Binary search and its importance.

REPORT  YSK_TEST_SORT.


TYPES: BEGIN OF T_TAB,
         UNAME TYPE SY-UNAME,
       END OF T_TAB.

TYPES: TT_TAB TYPE SORTED TABLE OF T_TAB WITH UNIQUE KEY UNAME.

DATA: IT_TAB TYPE TT_TAB,
      WA_TAB TYPE T_TAB.

WA_TAB-UNAME = 'ZZZZ'.
INSERT WA_TAB INTO TABLE IT_TAB.

WA_TAB-UNAME = 'ABCD'.
INSERT WA_TAB INTO TABLE IT_TAB.


LOOP AT IT_TAB INTO WA_TAB.

  WRITE:/ WA_TAB-UNAME.

ENDLOOP.

Thanks,

Sreekanth

Read only

Former Member
0 Likes
482

hi Sucharita,

try this code,


Types: begin of ty_uname,
            uname type syuname,
            field1 type field1,
            field2 type field2,
            field3 type field3,
            end of ty_uname.
data itab type sorted table of ty_uname .

Also you dont need any other way to read this type of internal table.

There is no need of Binary search as it is used by default.

Regards,

Sumesh Nair

Read only

huseyindereli
Active Contributor
0 Likes
482

Hi,

DATA : BEGIN OF gs_uname ,
         uname TYPE syuname ,
         END OF gs_uname.

  DATA : gt_uname LIKE SORTED TABLE OF gs_uname WITH HEADER LINE
         WITH UNIQUE KEY uname.


  " insert
  gs_uname-uname = sy-uname.
  INSERT gs_uname INTO TABLE gt_uname.

  " read with key
  READ TABLE gt_uname WITH TABLE KEY uname = sy-uname.

Edited by: Hüseyin Dereli on Jul 31, 2009 12:00 PM