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: 

Sort Statement Error

Former Member
0 Kudos

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

Former Member
0 Kudos

do

sort zitab by zecrno descending .

with luck,

Pritam.

16 REPLIES 16

Former Member
0 Kudos

Did you try:


SORT zitab BY zecrno DESCENDING.

0 Kudos

Hi,

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

Thanks and Regards.

Former Member
0 Kudos

do

sort zitab by zecrno descending .

with luck,

Pritam.

0 Kudos

Hi,

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

Thanks and Regards.

0 Kudos

That should have worked. Can you post your code?

0 Kudos

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.

0 Kudos

What does zsalesitem1b look like?

Avoid SELECT ENDSELECT.

Instead use:


select zecrno from zsalesitem1b into corresponding fields of table zitab.

0 Kudos

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.

0 Kudos

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

0 Kudos

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.

P561888
Active Contributor
0 Kudos

1.First delete the Duplicates.

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

try this...

Former Member
0 Kudos

Hi,

What is the data type of field zecrno ?

regards,

Advait.

Former Member
0 Kudos

hi,

write in the below way.

sort <internal table> by <field> descending.

Regards,

venkat

Former Member
0 Kudos

Hi,

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

Regards,

venkat

Former Member
0 Kudos

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

Former Member
0 Kudos

Thanks to all for your help.