在SAP中,以下请求运行良好,但结果是我获得了3000万种材料(MATNR)的#5000000行:

SELECT  k~bldat a~matnr k~bldat e~maktx a~mtart a~brgew
   a~ntgew a~gewei a~volum a~laeda mseg~bwart k~budat
INTO CORRESPONDING FIELDS OF TABLE itab
   FROM mseg
     INNER JOIN makt AS e ON e~matnr   = mseg~matnr
      INNER JOIN mara AS a ON a~matnr = mseg~matnr
       INNER JOIN mkpf AS k ON k~mblnr = mseg~mblnr
     WHERE a~mtart in ('ZRSV','ZVTP').


但是,如果我只想要每个MATNR的最后移动/日期,则以下请求将返回此错误:
表名称或表别名名称错误表别名名称“(SELECT MAX(T”.。

SELECT k~bldat a~matnr k~bldat e~maktx a~mtart a~brgew
   a~ntgew a~gewei a~volum a~laeda mseg~bwart k~budat
INTO CORRESPONDING FIELDS OF TABLE itab
   FROM mseg
     INNER JOIN makt AS e ON e~matnr   = mseg~matnr
      INNER JOIN mara AS a ON a~matnr = mseg~matnr
       INNER JOIN mkpf AS k ON k~mblnr = mseg~mblnr
     WHERE a~mtart in ('ZRSV','ZVTP')
         AND k~bldat = (SELECT MAX( t~bldat ) FROM mkpf AS t
                WHERE t~mblnr = mesg~mblnr).


对语法问题有任何想法吗?
提前致谢。

最佳答案

您需要在sub- SELECT语句之前添加空格:

AND k~bldat = ( SELECT MAX ... = ~mblnr ).
               ^ HERE         AND HERE ^

08-03 20:02