01-17-2006 1:53 AM
Can anyone help me why this SQL isn't working..PSMNG and WEMNG always have zeros even though the database tables so have values
Structure of T_ORDER
DATA: BEGIN OF T_ORDER OCCURS 0,
WERKS LIKE AUFK-WERKS,
MATNR LIKE AFPO-MATNR,
PSMNG LIKE AFPO-PSMNG,
WEMNG LIKE AFPO-WEMNG,
ACTSCRAP LIKE MARC-AUSSS,
DIFF LIKE MARC-AUSSS,
END OF T_ORDER.
LOOP AT T_ACTIVE.
SELECT AUFKWERKS AFPOMATNR AVG( AFPO~PSMNG )
AVG( AFPO~WEMNG )
APPENDING CORRESPONDING FIELDS OF TABLE T_ORDER
FROM AUFK INNER JOIN AFPO
ON AUFKAUFNR EQ AFPOAUFNR
WHERE AUFK~WERKS EQ T_ACTIVE-PLWRK
AND AUFK~IDAT2 LT SY-DATUM
AND AUFK~IDAT2 GE W-MDATE
AND AFPO~MATNR EQ T_ACTIVE-MATNR
GROUP BY AUFKWERKS AFPOMATNR.
ENDLOOP.
01-17-2006 2:36 AM
try,
SELECT AUFKWERKS AFPOMATNR AVG( AFPO~PSMNG ) AS PSMNG
AVG( AFPO~WEMNG ) AS WEMNG
01-17-2006 2:24 AM
I am guessing that you need to take out the word CORRESPONDING. Just use APPENDING FIELDS OF TABLE.
I do not think the target fields have the same names when you use SQL aggregate functions.
01-17-2006 2:36 AM
try,
SELECT AUFKWERKS AFPOMATNR AVG( AFPO~PSMNG ) AS PSMNG
AVG( AFPO~WEMNG ) AS WEMNG
01-18-2006 11:49 PM