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 in loop???

Former Member
0 Likes
906

Hi,

I have 2 internal tables ( i_pro & it_pbim ). In my first internal table(i_pro) having matnr. Using this matnr i am feting some values from another table and i populating into 2nd internaltable. but in the loop its feting the records from the table but its not appending the internal table its overwriting the current value from the 2nd internal table.

how to append the values. i pasted my sample code also. plz give me soln urgent point will be sure.

loop at i_pro .

SELECT * FROM pbim

INTO corresponding fields of

TABLE it_pbim

WHERE matnr = i_pro-matnr

AND werks = 'GB06'

AND bedae = 'VSF'

AND vervs = 'X'.

  • AND loevr = ''.

append it_pbim .

endloop .

point will be sure.

Gowri

7 REPLIES 7
Read only

Former Member
0 Likes
877

Remove dat LOOP ENDLOOP..

jus write

SELECT * FROM pbim

INTO corresponding fields of

TABLE it_pbim

<b>FOR ALL ENTRIES IN</b> it_pro

WHERE matnr = i_pro-matnr

AND werks = 'GB06'

AND bedae = 'VSF'

AND vervs = 'X'.

  • AND loevr = ''.

This will solve ur query..Reward if helpful

Read only

Former Member
0 Likes
877

Hi,

Please do not use SELECT statements inside loops as it degrades the performance and is against standards.

Instead you could select all records from table pbim into an internal table in the beginning itself and in the loop read this internal table with key matnr.

Transfer the records into a work area and then append the work area to the final internal table.

Hope it is useful.

Thanks,

Sandeep.

Read only

Former Member
0 Likes
877

Hi

Dont use select * inside the loop. Use only select single. For your case you can use FOR ALL ENTRIES which is best. No need for loop.

SELECT * FROM pbim

INTO corresponding fields of

TABLE it_pbim

FOR ALL ENTRIES IN it_pro

WHERE matnr = i_pro-matnr

AND werks = 'GB06'

AND bedae = 'VSF'

AND vervs = 'X'.

  • AND loevr = ''.

Reward points if useful.

Regards,

Murugan Arumugam.

Read only

Former Member
0 Likes
877

Please try this ...


loop at i_pro .
SELECT * FROM pbim
appending corresponding fields of
TABLE it_pbim
WHERE matnr = i_pro-matnr
AND werks = 'GB06'
AND bedae = 'VSF'
AND vervs = 'X'.
* AND loevr = ''.
endloop .

note: can append to the internal table directly.

p/s: if sure there is no duplicate of it_pro-matnr, you can edit the query using 'for all entries' in order to improve performance.

Read only

Former Member
0 Likes
877

Hi Gowri Sankar,

Use this...

SELECT * FROM pbim

INTO corresponding fields of

TABLE it_pbim

for all entries in i_pro

WHERE matnr = i_pro-matnr

AND werks = 'GB06'

AND bedae = 'VSF'

AND vervs = 'X'.

append it_pbim.

Reward If Useful.

Regards,

Chitra.

Read only

0 Likes
877

HI,

First populate the first internal table then use FOR ALL ENTRIES to relate the second internal tables . r try READ ITAB by filtering out using the comman fields

like.....

loop at itab1.

read table itab2 where field1 = itab1-field1 field2 = itab1-field2.

endloop.

try this

Read only

Former Member
0 Likes
877

Hi,

You need to use <b>appending corresponding fields of table it_pbim</b> in your select statement.

loop at i_pro .
SELECT * FROM pbim
appending corresponding fields of
TABLE it_pbim
WHERE matnr = i_pro-matnr
AND werks = 'GB06'
AND bedae = 'VSF'
AND vervs = 'X'.
* AND loevr = ''.
endloop .

Thanks,

Sriram Ponna.