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

select query doubt

former_member227140
Active Participant
0 Likes
739

hello all,

i am writting this code .....first select is working fine for me as i am getting 5 entires in table itab which i am expecting...

but for second when i loop itab itab then at that time i should get one record in table itab2 out of second select query........

but as i can see while debugging i am getting that entry at third time when i am in loop.....but it again i think it overwrites with next enter and making itab2 entry as 0 at the end.....

what might be problem.

even i write append itab2.

clear itab2.

same error i am getting...(here CDPOS is cluster table..is this because of this??)..pease help

selection-screen:begin of block test with frame title new.

select-options: s_ddate for vbak-vdatu.

selection-screen:end of block test.

select avbeln avdatu bnetpr bnetwr b~matnr into corresponding fields of table itab

from vbak as a inner join vbap as b on avbeln = bvbeln where

b~matnr = 'AUP-501'

and a~vdatu in s_ddate.

LOOP AT ITAB.

select * from CDPOS into table itab2 where

OBJECTID = ITAB-VBELN AND

TABNAME = 'VBAP' AND

FNAME = 'NETPR'.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
704

Hi,

You are completely into wrong performance..

as per your query

selection-screen:begin of block test with frame title new.

select-options: s_ddate for vbak-vdatu.

selection-screen:end of block test.

select avbeln avdatu bnetpr bnetwr b~matnr into corresponding fields of table itab

from vbak as a inner join vbap as b on avbeln = bvbeln where

b~matnr = 'AUP-501'

and a~vdatu in s_ddate.

LOOP AT ITAB.

select * from CDPOS into table itab2 where

OBJECTID = ITAB-VBELN AND

TABNAME = 'VBAP' AND

FNAME = 'NETPR'.

ENDLOOP.

The second query is inside loop and its moving data into itab2 for every record in internnale table ITAB and

finally itab2 contains the last records of ITAB data if CDPOs has the data for itab-vbeln(last records).

To over come you need to write the select as beloew

select * from CDPOS APPENDING table itab2 where

OBJECTID = ITAB-VBELN AND

TABNAME = 'VBAP' AND

FNAME = 'NETPR'.

But I suggest you to write for all entries

select <the filed you need> from CDPOS

into table itab2

for all entries in itab

where OBJECTID = ITAB-VBELN AND

TABNAME = 'VBAP' AND FNAME = 'NETPR'.

Then

loop at ITAB.

Read table itab2 with key vbeln = itab-vbeln binary search.

If sy-subrc = 0.

<Write your code, functions etc>.

endif.

endloop.

regards,

Nazeer

5 REPLIES 5
Read only

Former Member
0 Likes
705

Hi,

You are completely into wrong performance..

as per your query

selection-screen:begin of block test with frame title new.

select-options: s_ddate for vbak-vdatu.

selection-screen:end of block test.

select avbeln avdatu bnetpr bnetwr b~matnr into corresponding fields of table itab

from vbak as a inner join vbap as b on avbeln = bvbeln where

b~matnr = 'AUP-501'

and a~vdatu in s_ddate.

LOOP AT ITAB.

select * from CDPOS into table itab2 where

OBJECTID = ITAB-VBELN AND

TABNAME = 'VBAP' AND

FNAME = 'NETPR'.

ENDLOOP.

The second query is inside loop and its moving data into itab2 for every record in internnale table ITAB and

finally itab2 contains the last records of ITAB data if CDPOs has the data for itab-vbeln(last records).

To over come you need to write the select as beloew

select * from CDPOS APPENDING table itab2 where

OBJECTID = ITAB-VBELN AND

TABNAME = 'VBAP' AND

FNAME = 'NETPR'.

But I suggest you to write for all entries

select <the filed you need> from CDPOS

into table itab2

for all entries in itab

where OBJECTID = ITAB-VBELN AND

TABNAME = 'VBAP' AND FNAME = 'NETPR'.

Then

loop at ITAB.

Read table itab2 with key vbeln = itab-vbeln binary search.

If sy-subrc = 0.

<Write your code, functions etc>.

endif.

endloop.

regards,

Nazeer

Read only

Former Member
0 Likes
704

Hello

Try this:


LOOP AT ITAB.
select * from CDPOS APPENDING table itab2 where " <- add APPENDING
OBJECTID = ITAB-VBELN AND
TABNAME = 'VBAP' AND
FNAME = 'NETPR'.
ENDLOOP.

Read only

former_member282823
Active Participant
0 Likes
704

Hi

Just do like this

select * from cdpos into table itab2 for all entries in itab

where objectid = itab-vbeln and

tabname = 'VBAP' and

fname = 'NETPR'.

Regards,

Ramesh.

Read only

Former Member
0 Likes
704

hi ,

please use " for all entries "

thanks..

Read only

nirajgadre
Active Contributor
0 Likes
704

hi,

instead of using the select statement inside the loop,try to use the select statement using FOR ALL ENTRIES in ITAB1.

Data type of the fields in the where condition needs to be same as that of CDPOS table variable.