使用左外部联接时如何处理空的第二张表?

2020-08-16 20:03发布

点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)嗨, 我正在使用左外部联接联接...

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


嗨,

我正在使用左外部联接联接两个表,其中第一个表说A包含客户和财务单据,过帐日期

而第二个表(z表)包含针对客户,日期范围和金额范围的组合的费率。

现在在测试时,表A包含值,而自定义表可以说B未被维护-因此没有值,但是输出变为空白。

我尝试使用Google搜索问题,并尝试了如图所示的解决方案

1:ON子句中提到了左外部连接的所有可能条件

2:尝试在where子句中包含NULL值。

因此,无论是否在表B中找到值,所需的输出都应显示表A中的所有值

从ZPD1中选择(PBUKRS = @ BUKRS-LOW,POSTFROM = @ COL_DATE-LOW,POSTTO = @ COL_DATE-HIGH)AS

       左外连接
       ZCUSTOM_TABLE 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
       当A〜ARREAR_DAYS <= 0然后'NOD'并且在A〜ARREAR_DAYS> 0 THEN'OD'END = F〜OD 
的情况下,这里ZPD1是作为表A创建的视图,而ZCUSTOM_TABLE是作为表B创建的,

VKBUR-LOW-选择屏幕元素

COL_DATE-LOW和COL_DATE_HIGH-选择屏幕元素

其中子句包含...

 @KUNNR中的A〜KUNNR
     AND NOT EXISTS(SELECT * FROM ZFI_PAYMENT_DISC WHERE BELNR = A〜BELNR
     和GJAHR = A〜GJAHR和BUKRS = A〜RBUKRS和SALES_OFFICE = @ VKBUR-LOW和A〜KUNNR在@KUNNR和OS_BELNR EQ A〜OD_DOC)
     AND A〜ARREAR_DAYS <= @OD
     AND(F〜COL_AMT_FROM LE(从ZPD_HSL选择SUM(COLLECT)(BUKRS = @ BUKRS-LOW,BUDATFROM = @ COL_DATE-LOW,BUDATO = @ COL_DATE-HIGH)WUNE KUNNR = A〜KUNNR)
     和F〜COL_AMT_TO GE(从ZPD_HSL选择SUM(COLLECT)(BUKRS = @ BUKRS-LOW,BUDATFROM = @ COL_DATE-LOW,BUDATO = @ COL_DATE-HIGH)WUNR = A〜KUNNR)
   )
 

这里ZPF_HSL也是一个视图

@之后的所有元素都是选择屏幕元素

我什至尝试评论where子句的这一部分

 @KUNNR中的A〜KUNNR
     AND NOT EXISTS(SELECT * FROM ZFI_PAYMENT_DISC WHERE BELNR = A〜BELNR
     和GJAHR = A〜GJAHR和BUKRS = A〜RBUKRS和SALES_OFFICE = @ VKBUR-LOW和A〜KUNNR在@KUNNR和OS_BELNR EQ A〜OD_DOC)
     AND A〜ARREAR_DAYS <= @OD
 * AND(F〜COL_AMT_FROM LE(从ZPD_HSL选择和(COLLECT)(BUKRS = @ BUKRS-LOW,BUDATFROM = @ COL_D * ATE-LOW,BUDATO = @ COL_DATE-HIGH)WUNR = A〜KUNNR)
 * AND F〜COL_AMT_TO GE(从ZPD_HSL中选择和(COLLECT)(BUKRS = @ BUKRS-LOW,BUDATFROM = @ COL_DA * TE-LOW,BUDATO = @ COL_DATE-HIGH)WUNE KUNNR = A〜KUNNR)
 *)
 

静止输出变为空白...

致谢

5条回答
能不能别闹
2020-08-16 20:42

嗨,迈克尔,

我确实尝试了您的建议,并且它适用于标准表,因为ZPD1是具有ACDOCA,BSID,MARA等的ABAP CDS视图

共享完整的select语句...

 *这里ZPD1是ACDOCA左连接BSAD,MAKT等的视图
 从ZPD1选择(PBUKRS = @ BUKRS-LOW,POSTFROM = @ COL_DATE-LOW,POSTTO = @ COL_DATE-HIGH)

       左外连接
       ZCUSTOM_TABLE 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
       当A〜ARREAR_DAYS <= 0然后'NOD'并且在A〜ARREAR_DAYS> 0 THEN'OD'结束时= F〜OD

       内联接KNA1 AS H ON H〜KUNNR = A〜KUNNR
       像我一样在TVKBT上加入内部音乐〜VKBUR = F〜SALES_OFFICE和I〜SPRAS = @ SY-LANGU

       J〜SAKNR = A〜HKONT和J〜SPRAS ='E'并且J〜KTOPL ='1000'
       K〜MATNR = A〜MATNR和K〜SPRAS ='E'
       左外接头T001W AS L ON L〜WERKS = A〜WERKS


       领域
       A〜RBUKRS作为BUKRS,
       A〜KUNNR,
       H〜NAME1,
       F〜SALES_OFFICE,
       我〜贝芝
       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,
       当A〜SHKZG ='H'时的情况为CAST(A〜WRBTR * -1 AS CURR(12,2))ELSE A〜WRBTR END AS OS_AMT,
       A〜DUE_DATE,
       A〜ARREAR_DAYS,
       A〜ARREAR_DAYS <= 0 THEN'NOD'时的情况
       当A〜ARREAR_DAYS> 0 THEN'OD'
       ELSE''END AS OD_IND,
       A〜HKONT,
       J〜TXT50,
       A〜PROD_CATEGORY,
       A〜MATNR,
       K〜MAKTX,
       ~~ WERKS,
       L〜NAME1,
       A〜BWTAR,
       A〜PROFIT_CENTRE AS PRCTR,
       COALESCE(F〜PD_RATE,0)为RATE,
       0 AS PD_AMT,
       当A〜ARREAR_DAYS> 0时的情况然后CAST(除法((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,

      A〜MAIN_TYPE

     @KUNNR中的A〜KUNNR
     AND NOT EXISTS(SELECT * FROM ZFI_PAYMENT_DISC WHERE BELNR = A〜BELNR
     和GJAHR = A〜GJAHR和BUKRS = A〜RBUKRS和SALES_OFFICE = @ VKBUR-LOW和A〜KUNNR在@KUNNR和OS_BELNR EQ A〜OD_DOC)
     AND A〜ARREAR_DAYS <= @OD
     AND(F〜COL_AMT_FROM LE(从ZPD_HSL选择SUM(COLLECT)(BUKRS = @ BUKRS-LOW,BUDATFROM = @ COL_DATE-LOW,BUDATO = @ COL_DATE-HIGH)WUNE KUNNR = A〜KUNNR)
     和F〜COL_AMT_TO GE(从ZPD_HSL选择SUM(COLLECT)(BUKRS = @ BUKRS-LOW,BUDATFROM = @ COL_DATE-LOW,BUDATO = @ COL_DATE-HIGH)WUNR = A〜KUNNR)
   )

   按A〜KUNNR,A〜BELNR,A〜DUE_DATE升序排列
   插入表@PROV_POST。
    

此致

一周热门 更多>