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

Doubt

Former Member
0 Likes
556

Hi Experts

I am using the following query, but it reads only one row at a time, how to store another internal table, can i use append statement here.

loop at i_mkpf.

select MBLNR

MJAHR

BWART

MATNR

WERKS

MENGE

AUFNR

from mseg

into corresponding fields of table itab2

for all entries in itab

where aufnr = itab-aufnr and

bwart = '261' and

mblnr = i_mkpf-mblnr.

endloop.

Regards

Rajaram

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
535

data : l_i_mkpf type ( as of I_MKPF)

l_i_mkpf[] = i_mkpf[].

SORT l_i_mkpf BY aufnr bwart mblnr.

delete adjacent du[plicates in l_i_mkpf comparing aufnr bwart mblnr.

if not l_i_mkpf[] is initial.

select MBLNR

MJAHR

BWART

MATNR

WERKS

MENGE

AUFNR

from mseg

into corresponding fields of table itab2

for all entries l_i_mkpf[]

where aufnr = l_i_mkpf-aufnr and

bwart = '261' and

mblnr = l_i_mkpf-mblnr.

if sy-sybrc is initial.

write : ' U have got all correcponding records'.

else.

write : ' selection failed'

endif.

endif.

Also please check that in MKPF and MSEG common key field is MBLNR.

Hence it would be better to get data from MSEG with the primary key and then delete all the unnecessary data from the internal table.

Hope I have wriiten a clear message.

for other issues please write back.

Keep Rocking ,

Pavan.

loop at i_mkpf.

select MBLNR MJAHR BWART MATNR WERKS MENGE AUFNR

from mseg

into corresponding fields of table itab2

for all entries in itab

where aufnr = itab-aufnr and

bwart = '261' and

mblnr = i_mkpf-mblnr.

endloop.

4 REPLIES 4
Read only

former_member404244
Active Contributor
0 Likes
535

Hi,

Try like this

if not itab[] is initial.

select MBLNR

MJAHR

BWART

MATNR

WERKS

MENGE

AUFNR

from mseg

into corresponding fields of table itab2

for all entries in itab

where aufnr = itab-aufnr and

bwart = '261' .

endif.

LOOP AT I_MKPF.

Read table itab2 with key mblnr = i_mkpf-mblnr.

if sy-subrc ne 0.

delete itab2.

endif.

ENDLOOP.

Reward if helpful.

Regards,

Nagaraj

Read only

former_member386202
Active Contributor
0 Likes
535

Hi,

dont use select statement within loop it is perfomance wise very bad, use for all entries for that and use read statement within loop ad read the data.

Regards,

Prashant

Read only

hymavathi_oruganti
Active Contributor
0 Likes
535

The select statement is not for reading data,

it selects data from database and stores it in the internal table.

in ur statement

into corresponding fields of <b>table</b> itab2,

the use of word <b>table</b> itself appends as many rows seletced.

no need of additional append statement.

Read only

Former Member
0 Likes
536

data : l_i_mkpf type ( as of I_MKPF)

l_i_mkpf[] = i_mkpf[].

SORT l_i_mkpf BY aufnr bwart mblnr.

delete adjacent du[plicates in l_i_mkpf comparing aufnr bwart mblnr.

if not l_i_mkpf[] is initial.

select MBLNR

MJAHR

BWART

MATNR

WERKS

MENGE

AUFNR

from mseg

into corresponding fields of table itab2

for all entries l_i_mkpf[]

where aufnr = l_i_mkpf-aufnr and

bwart = '261' and

mblnr = l_i_mkpf-mblnr.

if sy-sybrc is initial.

write : ' U have got all correcponding records'.

else.

write : ' selection failed'

endif.

endif.

Also please check that in MKPF and MSEG common key field is MBLNR.

Hence it would be better to get data from MSEG with the primary key and then delete all the unnecessary data from the internal table.

Hope I have wriiten a clear message.

for other issues please write back.

Keep Rocking ,

Pavan.

loop at i_mkpf.

select MBLNR MJAHR BWART MATNR WERKS MENGE AUFNR

from mseg

into corresponding fields of table itab2

for all entries in itab

where aufnr = itab-aufnr and

bwart = '261' and

mblnr = i_mkpf-mblnr.

endloop.