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 Statement Error

Former Member
0 Likes
1,717

Friends,

I have declared an internal table declared as below:

data:zitab type table of zsalesitem1a.

The ztable 'zsalesitem1a' has a primary key, zecrno.

After populating the internal table zitab with values from the ztable, i am sorting the zitab using :

sort zitab descending by zecrno.

But the sort statement is sorting the zitab using line number, not by zecrno values.

Please let me know what is missing.

Thanks and Regards.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,692

do

sort zitab by zecrno descending .

with luck,

Pritam.

16 REPLIES 16
Read only

Former Member
0 Likes
1,692

Did you try:


SORT zitab BY zecrno DESCENDING.

Read only

0 Likes
1,692

Hi,

There is no change with this version of the sort statement.

Thanks and Regards.

Read only

Former Member
0 Likes
1,695

do

sort zitab by zecrno descending .

with luck,

Pritam.

Read only

0 Likes
1,692

Hi,

There is no change with this version of the sort statement.

Thanks and Regards.

Read only

0 Likes
1,692

That should have worked. Can you post your code?

Read only

0 Likes
1,692

Hi,

Here is the code:

data:zstruct type zsalesitem1b.

data:zitab type table of zsalesitem1b.

select zecrno from zsalesitem1b into zstruct.

append zstruct to zitab.

endselect.

describe table zitab.

sort zitab by zecrno descending.

Thanks and Regards.

Read only

0 Likes
1,692

What does zsalesitem1b look like?

Avoid SELECT ENDSELECT.

Instead use:


select zecrno from zsalesitem1b into corresponding fields of table zitab.

Read only

0 Likes
1,692

Hello

Try:


data:zstruct type zsalesitem1b.
data:zitab type table of zsalesitem1b.

select zecrno from zsalesitem1b into zstruct-zecrno.
append zstruct to zitab.
endselect.
describe table zitab.

sort zitab by zecrno descending.

Read only

0 Likes
1,692

Hi,

The SORT statement can be like:

sort zitab by zecrno descending.

OR

sort zitab descending by zecrno .

There is no problem.

But check the below ones:

1.You might have filled line numbers instead of zecrno values.If so Check the content and fill accordingly.

2.The fields order might be swapped.?If so Check the strture and content.

3.You might have declared the Key fields and not followed the rules as there are different kinds of internal tables like SORTED,HASHED,STANDARD.If so folllow the order.

Regards,

Rama Chary.Pammi

Read only

0 Likes
1,692

Hi,

Problem seems to be with the structure definition of zsalesitem1a and zsalesitem1b. Compare the two structures and make sure that zrecno from zsalesitem1a actually gets mapped to the same field in zsalesitem1b. In debug check that the right values are getting populated into your internal table. Once that happens, sorting should work just fine.

Read only

BH2408
Active Contributor
0 Likes
1,692

1.First delete the Duplicates.

2.SORT itab DESCENDING BY field-1 field-2 asceding .

try this...

Read only

Former Member
0 Likes
1,692

Hi,

What is the data type of field zecrno ?

regards,

Advait.

Read only

Former Member
0 Likes
1,692

hi,

write in the below way.

sort <internal table> by <field> descending.

Regards,

venkat

Read only

Former Member
0 Likes
1,692

Hi,

can you paste your code..then we will look at once.

Regards,

venkat

Read only

Former Member
0 Likes
1,692

Hi,

Pls try this

select zecrno from zsalesitem1b into corresponding fields of zstruct.

append zstruct to zitab.

endselect.

describe table zitab.

sort zitab descending by zecrno .

Regards

Read only

Former Member
0 Likes
1,692

Thanks to all for your help.