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

table sorting.

Former Member
0 Likes
1,025

Hi,

i am using below code

code no 1.

sort t_lae_cr by allocation_id event status procmode.

delete t_lae_cr where event = 'NEWL' and status eq '9' and procmode eq '5' .

after executing above commands i get 284 records,

but when i used below code,

code no 2.

LOOP AT t_lae_cr WHERE event = 'NEWL' AND status EQ '9' AND procmode EQ '5'

DELETE t_lae_cr WHERE allocation_id = t_lae_cr-allocation_id.

CLEAR t_lae_cr.

ENDLOOP.

after executing above command i get 283 records.

So i just want to know why record count is not coming same in both the codes when they are doing the same tasks. is there any sorting issue in code 1 ?

Please help.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,001

Hi,

In first code you havenot checked for allocation_id ,but in the second one while deleting you are checking it.

This might be the reason.

9 REPLIES 9
Read only

Former Member
0 Likes
1,002

Hi,

In first code you havenot checked for allocation_id ,but in the second one while deleting you are checking it.

This might be the reason.

Read only

Former Member
0 Likes
1,001

hi,

according to me , in 2 code : the delete statement in loop is deleting the 1 record corresponding to that allocation id, on basis of which you are deleting in loop.

so 283 records are left.

regards

rahul

Read only

Former Member
0 Likes
1,001

Hi,

Tell me before deleting, the original no of records is 285 or anything else !!!

Delete adjacent duplicates deletes duplicates and one original remains in the table .

But here in second DELETE condition you are deleting all the duplicate and original records of the for which there are duplicates in the table .

As far my guess there is only one record that have duplicate records .

Regards

Pinaki

Read only

Former Member
0 Likes
1,001

Hi,

you're checking the value of the row on code 2 before deleting. Try to remove the WHERE clause.

Regards,

Mon Magallanes

Read only

former_member404244
Active Contributor
0 Likes
1,001

Hi,

Do a small change in ur code 2 and see

code no 1.

sort t_lae_cr by allocation_id event status procmode.

delete t_lae_cr where event = 'NEWL' and status eq '9' and procmode eq '5' .

after executing above commands i get 284 records,

but when i used below code,

code no 2.

LOOP AT t_lae_cr WHERE event = 'NEWL' AND status EQ '9' AND procmode EQ '5'

DELETE t_lae_cr .

CLEAR t_lae_cr.

ENDLOOP.

Regards,

Nagaraj

Read only

Former Member
0 Likes
1,001

Hi,

DELETE t_lae_cr WHERE event = 'NEWL' AND status EQ '9' AND procmode EQ '5' .

To acheive this using loop you shud write,

LOOP AT t_lae_cr WHERE event = 'NEWL' AND status EQ '9' AND procmode EQ '5'
DELETE t_lae_cr. "You have added one more condition here
CLEAR t_lae_cr.
ENDLOOP.

Regards,

Manoj Kumar P

Read only

Former Member
0 Likes
1,001

Hi,

Check if the Allocation have one duplicate entry.

Beacues for second code:

DELETE t_lae_cr WHERE allocation_id = t_lae_cr-allocation_id.

The delet is happenig when allocation_id matches..

Alternate Code for 2:

LOOP AT t_lae_cr WHERE event = 'NEWL' AND status EQ '9' AND procmode EQ '5'

DELETE t_lae_cr index sy-tabix.

CLEAR t_lae_cr.

ENDLOOP.

For 1st code:Allocation Id is not considered.

Hope it resolves your query.

Regards,

Gurpreet

Read only

Former Member
0 Likes
1,001

Hi,

it is very simple,

Check this eg,

allocation_id event status procmode

100 NEWL 9 5

100 NEWL 8 5

101 NEWL 9 5

102 NEWL 9 5

102 NEWL 7 5

103 ABCD 5 3

According code 1.

U'll get like this

allocation_id event status procmode

100 NEWL 8 5

102 NEWL 7 5

103 ABCD 5 3

Accoding code 2.

allocation_id event status procmode

103 ABCD 5 3

In the second code u r using allocation Id to delete the records.

when allocation Id is 100 , u have to delete only one record which satisfies. But when u delete in the second code both the records are deleted because allocation Id is same for next record also.

Read only

Former Member
0 Likes
1,001

Hi Santosh,

Their might be a possibility that while loop into your internal table the header record is getting deleted.

Bcoz's your internal table is a table with header line.

That's why u r getting one record less.

Do like this:

Create an internal table with a workarea. like

data: t_lae_cr like standard table of <WA>.

and then proceed with your code.

also try removing the CLEAR Statement from your code.

Hope it's clear.

Thanks

Ravi Aswani