‎2007 Nov 14 5:53 AM
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
‎2007 Nov 14 6:09 AM
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.
‎2007 Nov 14 5:59 AM
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
‎2007 Nov 14 6:02 AM
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
‎2007 Nov 14 6:03 AM
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.
‎2007 Nov 14 6:09 AM
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.