-2

我使用ACDOCABSIDMARAMAKT此类表创建了一个 ABAP CDS 视图。现在我的 CDS 视图包含客户列表以及他们的未完成 (FI) 文档。

针对这些客户、FI 文档和某些更多参数,我在自定义表中维护某些数据。

现在使用左外连接,我想将此 CDS 视图与自定义表连接起来。现在的问题是这个连接就像内部连接一样工作,所以如果我的自定义表是空白的,我的输出显示没有值,而它应该显示 CDS 视图,并且自定义表字段为空白。

现在基于网上类似的问题,我做了研究,发现了一些有用的点:

  1. 右表上的所有条件最多包含在 ON 连接条件中

  2. 尝试从右侧自定义表中包含空值。

  3. 尝试在连接条件上仅使用一个参数来查看结果(仍然作为内部连接工作)

这是我完整的选择语句,其中:

  1. ZPD1是我的 ABAP CDS 视图ACDOCABSDI... 表

  2. ZPD_HSL是用于客户明智 GL 金额计算的 ABAP CDS 视图。

  3. ZFI_PDRATE_MAP是我的自定义表,其中包含客户/FI 文档组合的费率。

这个声明中可能有什么失误?

SELECT
      FROM ZPD1( PBUKRS   = @BUKRS-LOW ,
                 POSTFROM = @COL_DATE-LOW ,
                 POSTTO   = @COL_DATE-HIGH ) AS A

      LEFT OUTER JOIN ZFI_PDRATE_MAP  AS F
            ON  A~PROD_CATEGORY =  F~PROD_CATEGORY
            AND A~OD_DATE       GE F~POST_DT_FROM 
            AND A~OD_DATE       LE F~POST_DT_TO
            AND F~COL_DT_FROM   GE @COL_DATE-LOW  
            AND F~COL_DT_TO     LE @COL_DATE-HIGH
            AND F~SALES_OFFICE  =  @VKBUR-LOW
            AND CASE WHEN A~ARREAR_DAYS <= 0 THEN 'NOD' 
                     WHEN A~ARREAR_DAYS > 0 THEN 'OD' 
                END             =  F~OD

      INNER JOIN KNA1 AS H 
            ON H~KUNNR = A~KUNNR

      INNER JOIN TVKBT AS I 
            ON  I~VKBUR = F~SALES_OFFICE 
            AND I~SPRAS = @SY-LANGU

      LEFT OUTER JOIN SKAT AS J 
            ON  J~SAKNR = A~HKONT 
            AND J~SPRAS = 'E' 
            AND J~KTOPL = '1000'

      LEFT OUTER JOIN MAKT AS K 
            ON  K~MATNR = A~MATNR 
            AND K~SPRAS = 'E'

      LEFT OUTER JOIN T001W AS L 
             ON L~WERKS = A~WERKS


      FIELDS
      A~RBUKRS  AS BUKRS,
      A~KUNNR,
      H~NAME1,
      F~SALES_OFFICE,
      I~BEZEI,
      A~BELNR AS COL_BELNR,
      A~GJAHR AS COL_GJAHR,
      A~HSL AS COL_AMT,
      A~BUDAT AS COL_DATE,
      A~KEY_DATE AS KEY_OS_DATE,
      A~OD_DOC AS OS_BELNR,
      A~OD_YR AS OS_GJAHR,
      A~BLART ,
      A~OD_DATE AS OS_DATE,
      CASE WHEN A~SHKZG = 'H' THEN CAST( A~WRBTR * -1 AS CURR( 12, 2 ) ) 
           ELSE A~WRBTR 
      END AS OS_AMT ,
      A~DUE_DATE,
      A~ARREAR_DAYS,
      CASE WHEN A~ARREAR_DAYS <= 0 THEN 'NOD'
           WHEN A~ARREAR_DAYS > 0 THEN 'OD'
           ELSE ' '
      END AS OD_IND,
      A~HKONT,
      J~TXT50,
      A~PROD_CATEGORY,
      A~MATNR,
      K~MAKTX,
      A~WERKS ,
      L~NAME1,
      A~BWTAR,
      A~PROFIT_CENTRE AS PRCTR,
      COALESCE( F~PD_RATE , 0 ) AS RATE,
      0 AS PD_AMT,
      CASE WHEN A~ARREAR_DAYS > 0 THEN
             CAST( 
               DIVISION( 
                 ( CAST( A~WRBTR * F~PD_RATE AS CURR( 15 ,2 ) ) ) ,
                 100 ,
                 3 ) 
               AS CURR( 15, 2 ) )
             * -1
           ELSE 
             DIVISION( 
               ( CAST( A~WRBTR * F~PD_RATE AS CURR( 15 , 2 ) ) ) , 
               100 ,
               3 ) 
      END AS ITEM_PD_AMT,  "DISCOUNT_RATE,
      0 AS ITEM_PD_AMT1,
      A~MAIN_TYPE

      WHERE A~KUNNR IN @KUNNR
        AND NOT EXISTS (
            SELECT * 
            FROM ZFI_PAYMENT_DISC 
            WHERE BELNR = A~BELNR
              AND GJAHR = A~GJAHR 
              AND BUKRS = A~RBUKRS 
              AND SALES_OFFICE = @VKBUR-LOW 
              AND A~KUNNR IN @KUNNR 
              AND OS_BELNR EQ A~OD_DOC )
        AND A~ARREAR_DAYS <= @OD
        AND ( F~COL_AMT_FROM LE ( 
            SELECT SUM( COLLECT ) 
            FROM ZPD_HSL( BUKRS     = @BUKRS-LOW ,
                          BUDATFROM = @COL_DATE-LOW ,
                          BUDATO    = @COL_DATE-HIGH ) 
            WHERE KUNNR = A~KUNNR )
        AND F~COL_AMT_TO GE ( 
            SELECT SUM( COLLECT ) 
            FROM ZPD_HSL( BUKRS     = @BUKRS-LOW ,
                          BUDATFROM = @COL_DATE-LOW ,
                          BUDATO    = @COL_DATE-HIGH ) 
            WHERE KUNNR = A~KUNNR )
      )
    
      ORDER BY A~KUNNR, A~BELNR ,A~DUE_DATE ASCENDING
    
      INTO TABLE @PROV_POST.
4

1 回答 1

2

这只是一个猜测,因为您的复杂设置使得难以重现工作示例。

我的假设是INNER JOIN TVKBT AS I ON I~VKBUR = F~SALES_OFFICE阻碍了。它与您的自定义表进行内连接,别名为F,如果连接顺序被解释错误,可能会导致记录过度减少。

我建议删除该连接并查看是否修复了基本连接结果。

无论如何,我建议添加括号并重新排序连接子句,以明确等式的“左侧”是什么,并为解释者和读者消除任何歧义。

于 2020-06-22T14:03:14.950 回答