2007 Feb 08 3:34 AM
Can I use read table instead of multiple select & loop statements.
Any one please give me the sample code ..how to do it.
Thanks in advance
2007 Feb 08 3:40 AM
Hi,
Yes you can use read instead of nested loops and select which will affect the performance.
REPORT zkeerthi_ITABLE9 .
tables:vbap,vbak,vbkd.
data:begin of it_vbap occurs 0,
vbeln like vbap-vbeln,
matnr like vbap-matnr,
end of it_vbap.
data:begin of it_vbak occurs 0,
erdat like vbak-erdat,
ernam like vbak-ernam,
vbeln like vbak-vbeln,
end of it_vbak.
data:begin of it_vbkd occurs 0,
konda like vbkd-konda,
kdgrp like vbkd-kdgrp,
vbeln like vbkd-vbeln,
end of it_vbkd.
data:begin of it_final occurs 0,
vbeln like vbap-vbeln,
matnr like vbap-matnr,
erdat like vbak-erdat,
ernam like vbak-ernam,
konda like vbkd-konda,
kdgrp like vbkd-kdgrp,
end of it_final.
parameters:v_matnr type vbap-matnr.
select vbeln
matnr
from vbap
into table it_vbap
where matnr = v_matnr.
select erdat
ernam
vbeln
from vbak
into table it_vbak
for all entries in it_vbap
where vbeln = it_vbap-vbeln.
select konda
kdgrp
vbeln
from vbkd
into table it_vbkd
for all entries in it_vbap
where vbeln = it_vbap-vbeln.
loop at it_vbap.
read table it_vbak with key vbeln = it_vbap-vbeln.
move :it_vbak-erdat to it_final-erdat,
it_vbak-ernam to it_final-ernam,
it_vbap-vbeln to it_final-vbeln,
it_vbap-matnr to it_final-matnr.
append it_final.
read table it_vbkd with key vbeln = it_vbap-vbeln.
move:it_vbkd-konda to it_final-konda,
it_vbkd-kdgrp to it_final-kdgrp.
append it_final.
endloop .
sort it_final by matnr.
loop at it_final.
write:/ it_final-vbeln,
it_final-matnr,
it_final-erdat,
it_final-ernam,
it_final-konda,
it_final-kdgrp.
endloop.
Can I use read table instead of multiple select & loop statements.
Any one please give me the sample code ..how to do it.
Thanks in advance
2007 Feb 08 3:40 AM
Hi,
Yes you can use read instead of nested loops and select which will affect the performance.
REPORT zkeerthi_ITABLE9 .
tables:vbap,vbak,vbkd.
data:begin of it_vbap occurs 0,
vbeln like vbap-vbeln,
matnr like vbap-matnr,
end of it_vbap.
data:begin of it_vbak occurs 0,
erdat like vbak-erdat,
ernam like vbak-ernam,
vbeln like vbak-vbeln,
end of it_vbak.
data:begin of it_vbkd occurs 0,
konda like vbkd-konda,
kdgrp like vbkd-kdgrp,
vbeln like vbkd-vbeln,
end of it_vbkd.
data:begin of it_final occurs 0,
vbeln like vbap-vbeln,
matnr like vbap-matnr,
erdat like vbak-erdat,
ernam like vbak-ernam,
konda like vbkd-konda,
kdgrp like vbkd-kdgrp,
end of it_final.
parameters:v_matnr type vbap-matnr.
select vbeln
matnr
from vbap
into table it_vbap
where matnr = v_matnr.
select erdat
ernam
vbeln
from vbak
into table it_vbak
for all entries in it_vbap
where vbeln = it_vbap-vbeln.
select konda
kdgrp
vbeln
from vbkd
into table it_vbkd
for all entries in it_vbap
where vbeln = it_vbap-vbeln.
loop at it_vbap.
read table it_vbak with key vbeln = it_vbap-vbeln.
move :it_vbak-erdat to it_final-erdat,
it_vbak-ernam to it_final-ernam,
it_vbap-vbeln to it_final-vbeln,
it_vbap-matnr to it_final-matnr.
append it_final.
read table it_vbkd with key vbeln = it_vbap-vbeln.
move:it_vbkd-konda to it_final-konda,
it_vbkd-kdgrp to it_final-kdgrp.
append it_final.
endloop .
sort it_final by matnr.
loop at it_final.
write:/ it_final-vbeln,
it_final-matnr,
it_final-erdat,
it_final-ernam,
it_final-konda,
it_final-kdgrp.
endloop.
2007 Feb 08 3:40 AM
Hi,
U cannot read a table directly.. U need to Select required data
into an Internal Table and then read this Internal table ..
select * from <table > into table <it> where ...
read table <it> with key ....
Regards,
GSR.
2007 Feb 08 3:43 AM
Ramana,
You can avoid using Nested Loop or Nested Select using READ statements.
Lets say you have to Select records from MARA and MARC table.
Either you can first select entries from MARA using
SELECT <req fields> FROM MARA INTO wa_mara WHERE <select condition>.
IF sy-subrc = 0.
SLECT <req field> FROM MARC INTO wa_marc WHERE matnr = wa_mara-matnr.
<Now move the req fields in the final ITAB using move statements>
ENDIF.
ENDSELECT.
You can avoid this nested select as below:
SELECT <req fields> INTO TABLE IT_MARA FROM MARA WHERE <condition>.
SELECT <req fields> INTO TABLE IT_MARC FROM MARC FOR ALL ENTRIES IN TABLE IT_MARA WHERE matnr = it_mara-matnr.
LOOP AT IT_MARA.
READ TABLE it_marc WITH KEY matnr = it_mara-matnr.
<Move req field in the final table ITAB>
ENDLOOP.
Thanks
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |