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

Problem with loop

Former Member
0 Likes
1,382

Hello,

I have only one entry in P0000 with aedtm = 11/01/2006 and iam writing this code.

loop at p0000 into p0000 where aedtm in s_aedtm.

IF SY-SUBRC EQ 0.

some code.

endif.

endloop.

but the thing is it is looping twice even though it has only one entry in p0000 and iam getting 2 entries. can yoe please explain why this is happening

Thanks

Viky

15 REPLIES 15
Read only

Former Member
0 Likes
1,281

What is in s_aedtm?

You don't need the if sy-subrc inside the loop, as it will only go into the loop if it find an entry to match the where condition.

Read only

0 Likes
1,281

Yes ,

But why is it going into the loop twice if it has only one entry in that.

Thanks

Viky

Read only

Former Member
0 Likes
1,281

Also why are you looping into a header line of the same name as the table? If the table has a header line you can use the syntax:

LOOP AT p0000 WHERE etc

without specifing the header line.

Read only

0 Likes
1,281

Post the code exactly as it is in your program.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
1,281

Remove the code you don't need and see if it's still doing the same time. Othewise we need to know whats in s_aedtm.

Read only

0 Likes
1,281

here is my code below

loop at p0000 where aedtm in s_aedtm.

MOVE P0000-PERNR TO IT_tab-PERNR.

MOVE P0000-AEDTM TO IT_tab-AEDTM.

MOVE P0000-BEGDA TO IT_tab-BEGDA.

MOVE P0000-UNAME TO IT_tab-UNAME.

endloop.

Read only

0 Likes
1,281

I dont think there would be a check for SY-SUBRC.

Please Write LOOP at i_tab into work_area.

You are not using work area explicitely. Please declare a work area of LINE TYPE of P000.

Regards,

Surya

Read only

0 Likes
1,281

Do you have GET PERNR above the loop?

it might be looping twice.

Regards

Sridhar

Read only

0 Likes
1,281

ya i have a get pernr.

Read only

0 Likes
1,281

Put a break point at LOOP and execute, the program should stop at loop twice, that's the reason for 2 records even if P0000 contain only one.

Regards

Sridhar

Read only

0 Likes
1,281

so how do I make a correction in that

Read only

0 Likes
1,281

GET PERNR event might be selecting 2 records depending on the user selection.

limit the selection to select only one record, or discard the records from itab after the selection is complete.

Regards

Sridhar

Read only

0 Likes
1,281

use CLEAR P000 before the loop , this should not be a problem but just a try

Read only

Former Member
0 Likes
1,281

data: i_p0000 type table of pa0000 with header line.

loop at p0000 where aedtm in s_aedtm.

read table i_p0000 with key

aedtm = s_aedtm.

if sy-subrc ne 0.

move p0000 to i_p0000.

append i_p0000.

endif.

endloop.

this will read your internal table and only append to it if it does not find an entry with a duplicate changed on date (s_aedtm) from the selection screen.

This will read the internal table and only insert 1 value with that aedtm. If your s_aedtm is a select option and you have several single entries it will do the same, entering 1 record for each aedtm you specify.

Warren

Read only

Former Member
0 Likes
1,281

Vicky,

You could do...

*********************

data: I_P0000 type table of PA0000 with header line.

start-of-selection.

get pernr.

provide single * from p0000 between pn-begda and pn-endda

where aedtm = s_aedtm.

move P0000 to I_P0000.

append I_P0000.

endprovide.

end-of-selection.