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

Looping issue

Former Member
0 Likes
1,469

Hi All...

When i use the following code, i am unable to append the data in the internal Table i_jest.

It is getting over written each time....

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

loop at i_aufk into wa_aufk.

select objnr stat inact from JEST into corresponding fields of table i_jest

where objnr = wa_aufk-objnr

and inact = 'X'.

append i_jest.

endloop.

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

I would like to get the data from table JEST and store it in i_jest.

What is the defect in above code and why data is not getting appended in the internal table i_jest..?????

Each time, there will be 3-4 lines get stored in the internal Table.

Very next loop, the data is getting overwritten in the internal Table.....

Please Help me.....

Regards

Pavan

1 ACCEPTED SOLUTION
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,438

Hi,

Another option is to use for all entries.

select objnr stat inact from JEST into corresponding fields of table i_jest

for all entries in i_aufk

where objnr = i_aufk-objnr

and inact = 'X'.

15 REPLIES 15
Read only

Former Member
0 Likes
1,438

remove append statement in the loop ..then it will work..as u r using clause into corresponding fields of table..u need not to use append..remove that.

amit

Read only

Former Member
0 Likes
1,438

loop at i_aufk into wa_aufk.

select objnr stat inact from JEST into corresponding fields of table i_jest

where objnr = wa_aufk-objnr

and inact = 'X'.

*<b>append i_jest.</b>------>remove this.

endloop.

Read only

Former Member
0 Likes
1,438

loop at i_aufk into wa_aufk.

select <you may use single > objnr stat inact from JEST into corresponding fields of i_jest

where objnr = wa_aufk-objnr

and inact = 'X'.

append i_jest.

<endselect if you are not using select single>.

endloop.

dont use table option in select qery.

for that only it has overwritten.

regards

shiba dutta

Read only

Former Member
0 Likes
1,438

Hi Pavan,

Try the code by removing append statement. It will work.

-Priyanka.

Read only

0 Likes
1,438

Hi Amit/Kishan/Shiba and Priyanka...

Thanks for your tips....

I have used the following code... Now data is appending in a desired manner..

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

loop at i_aufk into wa_aufk.

select objnr stat inact from JEST into corresponding fields of i_jest

where objnr = wa_aufk-objnr

and inact = 'X'.

append i_jest.

endselect.

endloop.

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

I have removed append statement as stated by you previously.. But it didn't work...

Anyway, Thanks dear friends.....

Regards

Pavan

Read only

0 Likes
1,438

always avoidf to use select statement with in a loop. try to code like that.

make one more internal table i_jest1 like i_jest.

select objnr stat inact from JEST into corresponding fields of table i_jest
where  inact = 'X'.

sort i_jest.
 loop at i_aufk into wa_aufk.
read table i_jest with key objnr = wa_aufk-objnr binary search.
i_jest1-objnr = i_jest-objnr.
i_jest1-stat = i_jest-stat.
i_jest1- inact = i_jest- inact.
append i_jest1.
endloop.

null

Read only

0 Likes
1,438

Kishan,

I have used the code as you mentioned...

Now i am having one more query...

I have multiple records in I_JEST for i_jest-objnr.

I mean to say.... i_jest-objnr = 100, i_jest-stat = I001, i_jest-inact= X

i_jest-objnr = 100, i_jest-stat = I002, i_jest-inact= X

i_jest-objnr = 100, i_jest-stat = I005, i_jest-inact= X

i_jest-objnr = 101, i_jest-stat = I001, i_jest-inact= X

i_jest-objnr = 101, i_jest-stat = I003, i_jest-inact= X

The read statment only reads single line (i_jest-objnr= 100) and skips rest records..

It will move to i_jest-objnr= 101

But i need all the records for i_jest-objnr= 100.. (all 3 lines)

How to tackle this issue...???

Regards

Pavan

Read only

0 Likes
1,438

Hi,

select objnr stat inact from JEST into corresponding fields of table i_jest

where inact = 'X'.

sort i_jest.

loop at i_aufk into wa_aufk.

loop at i_jest where objnr = wa_aufk-objnr .

i_jest1-objnr = i_jest-objnr.

i_jest1-stat = i_jest-stat.

i_jest1- inact = i_jest- inact.

append i_jest1.

endloop.

endloop.

Read only

Former Member
0 Likes
1,438

Remove the append statement and use

<i><b>appending</b></i> keyword in the select statement before <b>table</b> keyword.

Regards,

Balaji Reddy G

***Rewards if answers are helpful

Read only

Former Member
0 Likes
1,438

Again one more query has been posted.. Hence this issue is still open...

Read only

0 Likes
1,438

1)use for all entries.

select objnr stat inact from JEST into  table i_jest
for all entries in i_aufk 
where objnr = i_aufk-objnr
and  inact = 'X'.

2) otherwise u can use join fro both table

3)and last and performance wise poor option is to use nested loops.

select objnr stat inact from JEST into corresponding fields of table i_jest

where inact = 'X'.

sort i_jest.

loop at i_aufk into wa_aufk.

loop at i_jest where objnr = wa_aufk-objnr.

i_jest1-objnr = i_jest-objnr.

i_jest1-stat = i_jest-stat.

i_jest1- inact = i_jest- inact.

append i_jest1.

endloop

endloop.

kishan negi

kishan negi

Read only

0 Likes
1,438

Hi Pavan,

U cud try the following.

loop at i_aufk into wa_aufk.

loop at i_jest where objnr = wa_aufk-objnr

i_jest1-objnr = i_jest-objnr.

i_jest1-stat = i_jest-stat.

i_jest1- inact = i_jest- inact.

append i_jest1.

endloop.

endloop.

Regards,

Johnson

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,439

Hi,

Another option is to use for all entries.

select objnr stat inact from JEST into corresponding fields of table i_jest

for all entries in i_aufk

where objnr = i_aufk-objnr

and inact = 'X'.

Read only

Former Member
0 Likes
1,438

Hi Pavan,

The reason why you are getting onlye few records in the final internal table is that each time you do into table the previous contents gets replaced with the new set of values.

So there are two alternatives i would like to suggest .

1. If first three fields of your internal table i_jest are <b>objnr stat inact</b> , the you can use the command appending table in the select statement , but please do remeber that the fields must be in the order said else program will not work , i am sure whether this will work with the addition into corresponding fields. Below given is a sample code to illustrate this statement

Types : Begin of ty_one ,
          matnr type matnr ,
          werks type werks_d ,
        End of ty_one.
Types : Begin of ty_two ,
          matnr type matnr ,
         End of ty_two.

data : it_one type table of ty_one ,
       it_two type table of ty_two ,
       wa_two type ty_two.

Start-of-selection.

Select matnr
up to 10 rows
into table it_two
from mara.


loop at it_two into wa_two .

select matnr werks   " Please refer to the sequence in internal table
from marc
appending table it_one
where matnr =  wa_two-matnr
.
endloop.

2. The second options is to select the data into a temp table and the append the lines into the final table.

the code would look like this

loop at i_aufk into wa_aufk.
select objnr stat inact from JEST into corresponding fields of table i_jest1 " i_jest1 is temp table
where objnr = wa_aufk-objnr
and inact = 'X'.
*append i_jest. "code commented
append lines of i_jest1 to i_jest ." code added 
refresh i_jest1." code added.
endloop.

i feel options 2 will be better for you.

Please do revert back in case of any further queries.

Regards

Arun

  • Assign point if reply is useful

Read only

Former Member
0 Likes
1,438

Dear Pavan,

There's no point in using the APPEND I_JEST statement.

Please remove it.

Regards,

Abir

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

  • Don't forget to award Points *