‎2006 Sep 05 8:31 PM
Hi,
Need your help.
I have to write a select statement which should have data keeping
in mind the following details
1. production order no
2. sales order no
3. date.
and then the part no for the following programs.
I have written the following statement, but its taking too
long to execute as well as some one told me to divide the prg into 3 or 2 half.
the select statment is not working kindly help me out please.
the statement is as follows:
data:
S_SHPDATE LIKE s_date.
S_shpdate = s_date - 5.
*SELECT DISTINCT AFKOAUFNR AFKOPLNBEZ AFPOPSMNG AFPODGLTP
MARABISMT VBAKVBELN VBAKVDATU VBAPKWMENG
VBEP~MBDAT
INTO CORRESPONDING FIELDS OF ITAB
FROM AFKO
INNER JOIN AFPO ON AFPOAUFNR = AFPOAUFNR
INNER JOIN MARA ON MARAMATNR = AFKOPLNBEZ
INNER JOIN VBAP ON VBAPMATNR = MARAMATNR
INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
INNER JOIN VBEP ON VBEPVBELN = VBAPVBELN
INNER JOIN VBUK ON VBUKVBELN = VBAPVBELN
WHERE AFKO~GLTRP >= S_SHPDATE
AND AFKO~GLTRP <= S_DATE.
SELECT AFKOPLNBEZ AFKOAUFNR MARABISMT AFPOPSMNG AFPO~DGLTP
FROM AFKO
INNER JOIN AFPO ON AFPOAUFNR = AFKOAUFNR
INNER JOIN MARA ON MARAMATNR = AFKOPLNBEZ
into corresponding fields of ITAB1
where AFPO~DGLTP >= S_SHPDATE
AND AFPO~DGLTP <= S_DATE.
append itab1.
*refresh ITAB1[].
ITAB2[] = ITAB1[].
*sort ITAB2 by PLNBEZ.
delete adjacent duplicates from itab1 comparing PLNBEZ.
check not itab2[] is initial.
Select VBAKVBELN VBAKVDATU VBAPKWMENG VBAPMATNR VBEP~MBDAT
from VBAP
INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
INNER JOIN VBEP ON VBEPVBELN = VBAPVBELN
into ITAB3
for all entries in ITAB2
where VBAP~MATNR = ITAB2-MATNR.
append itab3.
‎2006 Sep 05 8:41 PM
Hi Kamlesh,
Do this way:
SELECT AFKOPLNBEZ AFKOAUFNR MARABISMT AFPOPSMNG AFPO~DGLTP
FROM AFKO
INNER JOIN AFPO ON AFPOAUFNR = AFKOAUFNR
INNER JOIN MARA ON MARAMATNR = AFKOPLNBEZ
into corresponding fields of <b>table</b> ITAB1
where AFPO~DGLTP >= S_SHPDATE
AND AFPO~DGLTP <= S_DATE.
<b>*append itab1.</b>
*refresh ITAB1[].
ITAB2[] = ITAB1[].
*sort ITAB2 by PLNBEZ.
delete adjacent duplicates from itab1 comparing PLNBEZ.
check not itab2[] is initial.
Select VBAKVBELN VBAKVDATU VBAPKWMENG VBAPMATNR VBEP~MBDAT
from VBAP
INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
INNER JOIN VBEP ON VBEPVBELN = VBAPVBELN
<b>into corresponding fields of table</b> ITAB3
for all entries in ITAB2
where VBAP~MATNR = ITAB2-MATNR.
<b>*append itab3.</b>
Hope this will help you.
Regards,
Vivek
PS: Award points if helpful
‎2006 Sep 05 8:42 PM
Kamlesh,
U are surely on the right track...
SELECT AFKOPLNBEZ AFKOAUFNR MARABISMT AFPOPSMNG AFPO~DGLTP
FROM AFKO
INNER JOIN AFPO ON AFPOAUFNR = AFKOAUFNR
INNER JOIN MARA ON MARAMATNR = AFKOPLNBEZ
into corresponding fields of table ITAB1
where AFPO~DGLTP >= S_SHPDATE
AND AFPO~DGLTP <= S_DATE.
ITAB2[] = ITAB1[].
sort ITAB2 by PLNBEZ.
delete adjacent duplicates from itab2 comparing PLNBEZ.
check not itab2[] is initial.
Select VBAKVBELN VBAKVDATU VBAPKWMENG VBAPMATNR VBEP~MBDAT
from VBAP
INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
INNER JOIN VBEP ON VBEPVBELN = VBAPVBELN
into table ITAB3
for all entries in ITAB2
where VBAP~MATNR = ITAB2-MATNR.
--Please note that if you have lots of data to fetch that it is surely going to effect the performance.
Regards
Anurag
‎2006 Sep 07 7:06 PM
Hi Anurag,
The second select statement is taking lot of time can u break it into another select statement.
or
can we write another select statement keeping in mind the same logic.
Require ur help.
Regards,
Kamlesh
‎2006 Sep 07 7:17 PM
I don't think you can fix that select the way it is written. Instead of going to VBAP, you can get the SO directly from table VAPMA.
Rob
‎2006 Sep 07 7:27 PM
So you can add something like:
TABLES: vapma.
DATA: BEGIN OF itab_mat OCCURS 0,
vbeln LIKE vapma-vbeln,
END OF itab_mat.
SELECT vbeln
FROM vapma
INTO TABLE itab_mat
FOR ALL ENTRIES IN itab2
WHERE vapma-matnr = itab2-matnr. " More critereria may be needed
CHECK NOT itab_mat[] IS INITIAL.
SELECT vbak~vbeln vbak~vdatu vbap~kwmeng vbap~matnr vbep~mbdat
FROM vbap
INNER JOIN vbak ON vbak~vbeln = vbap~vbeln
INNER JOIN vbep ON vbep~vbeln = vbap~vbeln
INTO itab3
FOR ALL ENTRIES IN itab_mat
<b>WHERE vbap~vbeln = itab_mat-vbeln</b>.
I haven't checked this, so you will have to check it thoroughly.
There was a mistake in my WHERE. I've corrected it in <b>bold</b>.
Rob
Message was edited by: Rob Burbank
‎2006 Sep 07 8:43 PM
I think you can try to get the data from VBAK/VBAP in one query and later use the particular internal table get the information from VBEP.
Select VBAKVBELN VBAKVDATU VBAPKWMENG VBAPMATNR from VBAP INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
into table ITAB3
for all entries in ITAB2
where VBAP~MATNR = ITAB2-MATNR.
SELECT VBEPVBELN VBEPPOSNR VBEP~MBDAT into itab4
from vbep
for all entries in itab3
where vbep~vbeln = itab3-vbeln
and vbep~posnr = itab3-posnr.
Regards
Anurag
OR
<b>Try and see if you can speed up using the VAPMA table</b>
Message was edited by: Anurag Bankley
Message was edited by: Anurag Bankley