如何获取最新的MBEWH〜LBKUM值?

问题描述 投票:0回答:1

该程序实际上是用于计算从过帐日期(MATDOC-BUDAT)开始有限制的总库存。但是我在确定初始存量时遇到问题。初始库存(MBEWH-LBKUM)从发布日期的前一个月开始获取。但是在我制作的程序中,出现的初始库存数据(MBEWH-LBKUM)没有得到应有的更新。同时,如果提到过帐日期(matdoc-budat /我加入到matdoc表中的查询),那么应该显示的初始库存数据就不是这样。

但是,如果我仅在短时间内选择发布日期,则显示的结果是正确的

我的查询是:

FORM F_GETDT .

  REFRESH: IT_ZVBR.

    SELECT DISTINCT MARA~MATNR
                    MATDOC~BUDAT
                    MATDOC~BWART
                    MATDOC~SHKZG
                    MATDOC~WERKS
                    MATDOC~MENGE AS TOTAL
    FROM MARA
    INNER JOIN MATDOC ON MARA~MATNR = MATDOC~MATNR
    INTO CORRESPONDING FIELDS OF TABLE IT_ZVBR
    WHERE MATDOC~WERKS = P_WERKS AND
          MATDOC~BUDAT IN P_BUDAT AND
          MARA~MATKL IN ('E001', 'E002', 'E003', 'E005', 'E006', 'E007', 'E008', 'E009', 'E010', 'E011', 'E012', 'E014').
ENDFORM.

这是我的代码,用于填充内部表IT_PRINT,稍后将显示它:

FORM F_LSTDT.

  CLEAR: WA_ZVBR, WA_PRINT, V_TEMP, V_DATE, V_MONTH, V_MONTHMIN, V_YEAR.

  SORT IT_ZVBR BY MATNR.
  IT_TEMP = IT_ZVBR.
  DELETE ADJACENT DUPLICATES FROM IT_ZVBR COMPARING MATNR.

  LOOP AT IT_ZVBR INTO WA_ZVBR.

    WA_PRINT-PSTAR = P_BUDAT-LOW.
    WA_PRINT-PFINS = P_BUDAT-HIGH.
    WA_PRINT-MATNR = WA_ZVBR-MATNR.

    SELECT SINGLE MAKTX FROM MAKT
    INTO WA_PRINT-MAKTX
    WHERE MATNR = WA_PRINT-MATNR.

    LOOP AT IT_TEMP INTO WA_TEMP WHERE MATNR = WA_ZVBR-MATNR.

      CLEAR: V_TEMP.
      V_TEMP = WA_TEMP-BUDAT+6(2).
      V_DATE = V_TEMP.

      CLEAR: V_TEMP.
      V_TEMP = WA_TEMP-BUDAT+4(2).
      V_MONTH = V_TEMP.
      V_MONTHMIN = V_MONTH - 1.

      CLEAR: V_TEMP.
      V_TEMP = WA_TEMP-BUDAT+0(4).
      V_YEAR = V_TEMP.

      BLN_SBLM = 12.
      THN_SBLM = V_YEAR - 1.

      IF V_MONTH = 1.
        SELECT SINGLE LBKUM FROM MBEWH
          INTO WA_PRINT-LBKUM
          WHERE MATNR = WA_PRINT-MATNR AND
            LFMON = BLN_SBLM AND
            LFGJA = THN_SBLM AND
            BWKEY = WA_ZVBR-WERKS.
      ELSE.
        SELECT SINGLE LBKUM FROM MBEWH
          INTO WA_PRINT-LBKUM
          WHERE MATNR = WA_PRINT-MATNR AND
            LFMON = V_MONTHMIN AND
            LFGJA =  V_YEAR AND
            BWKEY = WA_ZVBR-WERKS.
      ENDIF.

     //Logic to swap to the latest value  
      IF WA_PRINT-LBKUM = WA_PRINT-TEMP.
          WA_PRINT-TEMP = WA_PRINT-LBKUM.
      ELSEIF WA_PRINT-LBKUM <> WA_PRINT-TEMP AND WA_PRINT-LBKUM > 0.
          CLEAR: WA_PRINT-TEMP.
          WA_PRINT-TEMP = WA_PRINT-LBKUM.
      ENDIF.

  WA_PRINT-LBKUM = WA_PRINT-TEMP.

    ENDLOOP.
    APPEND WA_PRINT TO IT_PRINT.
    SORT IT_PRINT BY MATNR.
    CLEAR: WA_ZVBR, WA_PRINT, WA_TEMP, V_TEMP, V_DATE, V_MONTH, V_MONTHMIN, V_YEAR.
  ENDLOOP.
ENDFORM.

它应该获取下面图片中的数据(tcode se16n):

“必须作为输出的数据”“>

因为在matdoc表中,所以有最新的交易过帐日期(BUDAT)。

“基于matdoc中发布日期的数据”“ >>

而且我实际得到的数据是先前的数据。

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS92VzZYWC5wbmcifQ==” alt =“带下划线的蓝色” >>>

如何解决这个问题?我已经在这个问题上坚持了很长时间。之前谢谢。

该程序实际上是用于计算从过帐日期(MATDOC-BUDAT)开始有限制的总库存。但是我在确定初始存量时遇到问题。初始库存(MBEWH-LBKUM)是...

在您的可怕摘录中,您进行了排序,使您的想法全盘混乱:

SORT it_zvbr BY matnr.
it_temp = it_zvbr.

这使BUDAT在每个MATNR组中都降序排列,并用LBKUM破坏了您的想法,在循环的每次迭代中,ELSE之后的SELECT LBKUM都得到了[[overwrite

,因此它总是按照itab排序顺序进行覆盖,因此最早出现在最后。要解决此问题,请在分配it_temp = it_zvbr后更换并放入SORT。

[全面来说,这整个都是一团糟,应该从头开始重写。只是在这里推测您的需求:

如果您需要MATDOC值中的总库存以将其添加到BUDAT月份之前的MBEWH的初始库存中,则可能需要:

SELECT DISTINCT m~matnr, x~maktx, mdoc~mjahr AS initial_year, ew~lfmon AS initial_month, SUM( lp~menge ) AS total, MAX( ew~lbkum ) AS initial_stock FROM mara AS m INNER JOIN makt AS x ON m~matnr = x~matnr INNER JOIN matdoc AS mdoc ON lp~matnr = m~matnr LEFT OUTER JOIN mbewh AS ew ON ew~matnr = m~matnr INTO TABLE @DATA(it_stock) WHERE mdoc~WERKS = p_werks AND AND mdoc~budat IN p_budat AND m~matkl IN ('E001', 'E002', 'E003', 'E005', 'E006', 'E007', 'E008', 'E009', 'E010', 'E011', 'E012', 'E014'). AND ew~lfmon = ( SELECT MAX( lfmon ) FROM mbewh AS h WHERE h~matnr = m~matnr AND h~lfgja = mdoc~mjahr AND h~lfmon <> ( SELECT MAX( lfmon ) FROM mbewh WHERE matnr = h~matnr AND lfgja = h~lfgja ) ) GROUP BY mara~matnr, makt~maktx, , mdoc~mjahr, ew~lfmon.

我将MJAHR用于子查询,因为它通常等于BUDAT的前4个字符。 

此解决方案使用MBEWH的嵌套子查询在每个评估期内查找之前到最后的值,这看起来也很丑陋,但总之比原始数据短。

sap abap opensql
1个回答
0
投票

在您的可怕摘录中,您进行了排序,使您的想法全盘混乱:

© www.soinside.com 2019 - 2024. All rights reserved.