‎2006 Nov 27 3:09 PM
Hi all ,
This is my code i have millons of records in MARA table . I dont have where condition for mara table also if loop that one it consumes lot of time . Is there any otheway to compare mara all entries which are suitale for cdpos with single attempt?
SELECT MATNR MTART ERSDA SPART ERNAM AENAM FROM MARA INTO TABLE IT_MARA.
Loop at it_mara => this statement consumes lot of time for me
SELECT * FROM cdpos INTO TABLE it_cdpos WHERE OBJECTID = it_mara-matnr
and tabname = 'mara' and fname = 'spart'.
loop at it_cdpos.
write:/ it_cdpos.
endloop
endloop.
‎2006 Nov 27 3:11 PM
<b>Hi Code like below
SELECT MATNR MTART ERSDA SPART ERNAM AENAM FROM MARA INTO corresponding fields of TABLE IT_MARA.
if IT_MARA[] is not initial.
SELECT * FROM cdpos INTO corresponding fields of TABLE it_cdpos
for all entries in IT_MARA
WHERE OBJECTID = it_mara-matnr
and tabname = 'mara' and fname = 'spart'.
endif.
DELETE ADJACENT DUPLICATES from it_cdpos comparing all fields.
loop at it_cdpos.
write:/ it_cdpos.
endloop
Regs
Manas Ranjan Panda
Message was edited by:
MANAS PANDA
‎2006 Nov 27 3:11 PM
<b>Hi Code like below
SELECT MATNR MTART ERSDA SPART ERNAM AENAM FROM MARA INTO corresponding fields of TABLE IT_MARA.
if IT_MARA[] is not initial.
SELECT * FROM cdpos INTO corresponding fields of TABLE it_cdpos
for all entries in IT_MARA
WHERE OBJECTID = it_mara-matnr
and tabname = 'mara' and fname = 'spart'.
endif.
DELETE ADJACENT DUPLICATES from it_cdpos comparing all fields.
loop at it_cdpos.
write:/ it_cdpos.
endloop
Regs
Manas Ranjan Panda
Message was edited by:
MANAS PANDA
‎2006 Nov 27 3:13 PM
manas,
Object id and matnr fileds have diff fieldlength . While iam validating this two fields iam getting fieldlengths mismatching error.
‎2006 Nov 27 3:17 PM
Hi Manas,
did you tried this:
SELECT * FROM cdpos INTO TABLE it_cdpos
where OBJECTCLAS = 'MATERIAL'
and tabname = 'mara'
and fname = 'spart'.
loop at it_cdpos.
write:/ it_cdpos.
endloop
I think it's not nessasary to select MARA.
regards, Dieter
sorry i have forgotten
where OBJECTCLAS = 'MATERIAL'
Message was edited by:
Dieter Gröhn
‎2006 Nov 27 3:19 PM
Hi
U can do it by IT_MARA, take mara-matnr field as char(15) instead of declaring it directly to mara-matnr
like
data: begin of IT_MARA
MATNR(15) ,
MTART type mara-mtart,
ERSDA type mara-ersda,
SPART type mara-spart,
ERNAM type mara-ernam
AENAM type mara-aenam,
end of IT_MARA.
while u declare SELECT MATNR MTART ERSDA SPART ERNAM AENAM FROM MARA INTO corresponding fields of TABLE IT_MARA.
if IT_MARA[] is not initial.
SELECT * FROM cdpos INTO corresponding fields of TABLE it_cdpos
for all entries in IT_MARA
WHERE OBJECTID = it_mara-matnr
and tabname = 'mara' and fname = 'spart'.
endif.
DELETE ADJACENT DUPLICATES from it_cdpos comparing all fields.
loop at it_cdpos.
write:/ it_cdpos.
endloop
‎2006 Nov 27 3:14 PM
you can change it slightly.
REMOVE the LOOP statement and use for all entries option. use SORTED table of IT_CDPOS with KEY OBJID NON-UNIQUE.
SELECT MATNR MTART ERSDA SPART ERNAM AENAM FROM MARA INTO TABLE IT_MARA.
if SY-subrc eq 0.
SELECT * FROM cdpos INTO TABLE it_cdpos
<b>FOR ALL ENTRIES IN IT_MARA</b>
WHERE OBJECTID = it_mara-matnr.
if sy-subrc eq 0.
loop at it_mara.
loop at it_cdpos where objectid = it_mara-matnr.
write:/ it_cdpos.
endloop.
endloop.
endif.
endif.
‎2006 Nov 27 3:18 PM
Hi Priya,
Perhaps you can collect all CHANGENR field from CDHDR table using OBJECTCLAS = 'MATERIAL' and OBJECTID = IT_MARA-MATNR.
Then you can loop at internal CDHDR and read CDPOS table using OBJECTCLAS = 'MATERIAL', OBJECTID = IT_MARA-MATNR, CHANGENR = I_CDHDR-CHANGENR and FNAME = 'SPART' to get all detail CDPOS information.
Hope this will help.
Regards,
Ferry Lianto
‎2006 Nov 27 3:22 PM
Since you are selecting all materials, there's no reason to do a loop on the first table. But you need to add OBJECTCLAS to the second select:
SELECT matnr mtart ersda spart ernam aenam
FROM mara
INTO TABLE it_mara.
SELECT *
FROM cdpos
INTO TABLE it_cdpos
WHERE objectclas = 'MATERIAL'
* AND objectid = it_mara-matnr
AND tabname = 'MARA'
AND fname = 'SPART'.
You don't need to look at objectid.
Rob
Message was edited by:
Rob Burbank
‎2006 Nov 27 3:29 PM
simply this statement goes for execution of number of entries in mara table ..
if u say millions it is just out of scope.
effect of ur code is select * is executing million number of times ..
declare one more internal table it_final like it_cdpos.
tables mara, cdpos.
select-options : s_matnr for mara-matnr no-display,
s_OBJECTCLAS for cdpos-OBJECTCLAS no-display.
s_CHANGENR for cdpos-CHANGENR no-display.
SELECT * FROM cdpos INTO TABLE it_cdpos
WHERE OBJECTID IN S_MATNR
and OBJECTCLAS in s_OBJECTCLAS
and CHANGENR in s_CHANGENR
and tabname = 'MARA'
and fname = 'SPART'.
SELECT MATNR MTART ERSDA SPART ERNAM AENAM FROM MARA INTO TABLE IT_MARA.
loop at it_mara.
read table it_cdpos with key object id = it_mara-matnr.
check sy-subrc eq 0.
append it_final.
clear it_final.
endloop.
loop at it_final.
write:/it_final.
endloop.
just check this ..
its better than doing select in the loop .
hope this helps ,
regards,
vijay
‎2006 Nov 27 4:21 PM