简体   繁体   English

SAP Query IMRG Measure 文档

[英]SAP Query IMRG Measure documents

I'm learning SAP queries.我正在学习 SAP 查询。

I want to get all the Measure documents from an equipement.我想从设备中获取所有测量文件。 To do that, I use 3 tables : EQUI, IMPTT, IMRG为此,我使用了 3 个表: EQUI, IMPTT, IMRG

The query works but I have all documents instead I only want to get the last one by Date .查询有效,但我拥有所有文档,而我只想last one by Date获取last one by Date But I can't do that.但我不能那样做。 I'm sure that I have to add a custom field, but I have tried but none of them works.我确定我必须添加一个自定义字段,但我已经尝试过但它们都不起作用。

For example, my last code :例如,我的最后一个代码:

select min( IMRG~INVTS ) IMRG~RECDV
  from IMRG inner join IMPTT on
  IMRG~POINT = IMPTT~POINT  into (INVTS, IMRGVAL)
  where IMRG~POINT = IMPTT-POINT AND
  IMPTT~MPOBJ = EQUI-OBJNR
    and IMRG~CANCL = '' group by IMRG~MDOCM IMRG~RECDV.
ENDSELECT.

Thanks for your help.感谢您的帮助。

You will need to get the date from IMRG, and the inverted timestamp field, so the MIN() of this will be the most recent - that looks correct.您将需要从 IMRG 中获取日期,以及倒置的时间戳字段,因此它的 MIN() 将是最新的 - 看起来是正确的。

However your GROUP BY looks wrong.但是您的 GROUP BY 看起来不对。 You should be grouping on the IMPTT~POINT field so that you get one record per measurement point.您应该在 IMPTT~POINT 字段上分组,以便每个测量点获得一个记录。 Note that one Point IMPTT can have many measurements (IMRG), so something like this:请注意,一个点 IMPTT 可以有多个测量值 (IMRG),因此如下所示:

SELECT EQUI-OBJNR, IMPTT~POINT, MIN(IMRG~IMRC_INVTS) 
...
GROUP BY EQUI-OBJNR, IMPTT~POINT

If I got you correctly, you are trying to get the freshest measurement of the equipment disregard of measurement point.如果我的理解正确,您正在尝试获得设备的最新测量值,而忽略测量点。 So you can try this query, which is not so beautiful, but it just works.所以你可以试试这个查询,它不是那么漂亮,但它确实有效。

SELECT objnr COUNT(*) MIN( invts )
  FROM equi AS eq
  JOIN imptt AS tt
  ON tt~mpobj = eq~objnr
  JOIN imrg AS ig
  ON ig~point = tt~point
  INTO (wa_objnr, count, wa_invts)
  WHERE ig~cancl = ''
  GROUP BY objnr.
  SELECT SINGLE recdv FROM imrg JOIN imptt ON imptt~point = imrg~point INTO wa_imrgval WHERE invts = wa_invts AND imptt~mpobj = wa_objnr.
  WRITE: / wa_objnr, count, wa_invts, wa_imrgval.
ENDSELECT.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM