Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

help on sql

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

former_member186741
Active Contributor
0 Kudos

try,

SELECT AUFKWERKS AFPOMATNR AVG( AFPO~PSMNG ) AS PSMNG

AVG( AFPO~WEMNG ) AS WEMNG

3 REPLIES 3

Former Member
0 Kudos

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.

former_member186741
Active Contributor
0 Kudos

try,

SELECT AUFKWERKS AFPOMATNR AVG( AFPO~PSMNG ) AS PSMNG

AVG( AFPO~WEMNG ) AS WEMNG

0 Kudos

Thank you so much..that did the trick..

Cheers

Rani