Application Development 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: 

sorting internal table

Former Member
0 Kudos

Hi,

i am having two internal tables it_bsid1 and it_bsad1 .

i need to sort both the internal table at atime by using budat.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

u can write

sort it_bsid1 by budat.

sort it_bsad1 by budat.

this is the way u can do this task.

Madhavi

7 REPLIES 7

Former Member
0 Kudos

Hi,

We can't sort 2 itab at a time.We can give single command as below

sort : itab1 by budat, itab2 by budat.

another method is merge both table into single table and then sort it.

L.Velu

Former Member
0 Kudos

Hi Santhosh,

You may sort both tables one by one.

sort itab_bsid1 by budat.

sort itab_bsad1 by budat.

Tayab shah

Former Member
0 Kudos

Hi Santosh,

Sorting Internal Tables

You can sort a standard or hashed table in a program. To sort a table by its key, use the statement

SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE].

The statement sorts the internal table <itab> in ascending order by its key. The statement always applies to the table itself, not to the header line. The sort order depends on the sequence of the standard key fields in the internal table. The default key is made up of the non-numeric fields of the table line in the order in which they occur.

You can specify the direction of the sort using the additions ASCENDING and DESCENDING. The default is ascending.

The larger the sort key, the more time the system needs to sort the table. If the sort key contains an internal table, the sorting process may be slowed down considerably.

You cannot sort a sorted table using the SORT statement. The system always maintains these tables automatically by their sort order. If an internal table is statically recognizable as a sorted table, the SORT statement causes a syntax error. If the table is a generic sorted table, the SORT statement causes a runtime error if the sort key is not the same as an extract of the beginning of the table key, you sort in descending order, or use the AS TEXT addition. In other words, the SORT statement is only allowed for generic internal tables, if it does not violate the internal sort order.

Refer to this sample sorting code, might help u out.

v_fieldx_count = 0. "Type I

v_fieldy_count = 0.

loop at itab.

if itab-fieldX is initial AND fieldY is initial .

v_fieldx_count = v_fieldx_count + 1.

v_fieldy_count = v_fieldy_count +1.

elseif itab-fieldX is initial.

v_fieldx_count = v_fieldx_count + 1.

elseif itab-fieldY is initial.

v_fieldY_count = v_fieldY_count + 1.

endif.

endlloop.

If v_fieldx_count GE v_fieldY_count .

sort itab by fieldX.

else.

sort itab by fieldY.

Endif.

Reeward if useful.

Thankyou,

Regards.

Former Member
0 Kudos

u can write

sort it_bsid1 by budat.

sort it_bsad1 by budat.

this is the way u can do this task.

Madhavi

0 Kudos

Hi madhvi,

i need to display both the tables data in one list. i done like that only. but it is sorting first it_bsid1 table disolaying all the data later bellow that data it_bsad is sorting and displaying like

05/10/2007 it_bsid1

10./10/2007 it_bsid1

5/10/2007 it_bsad1

0 Kudos

Then u can append both Internal Tables and then perform sort on entire values.

awrd points if helpful

Bhupal

Former Member
0 Kudos

Hi Santosh,

We have to declare one more internal table that internal table contain the other two internal table fileds and we have to perform sort on those ok..

SAMPLE CODE:

sort budat.

loop at itab.

endloop.

Award points if helpful.

Kiran Kumar.G.A

Have a Nice Day..