Chaitanya_MYK
Starting Member
1 Post |
Posted - 2014-05-21 : 04:05:00
|
Hello AllI have an open SQL code for Customer Invoice Statement which I need to convert into native SQL code(http://wiki.scn.sap.com/wiki/display/Snippets/Customer+Invoice+Statement)This is what I made of it so far. I'm stuck as it is going into an unending loop. ------------------------<code>with t_kna1 as ( select * from KNA1 ),t_knvk as ( select KUNNR,NAME1,NAMEV from KNVK ),t_bsid as ( select KUNNR,BUKRS,BLART,BELNR,BLDAT,GJAHR, case when SHKZG='H' then (WRBTR*-1) else WRBTR end WRBTR,WAERS,DMBTR,ZBD1T,ZBD2T,ZBD3T,AUGBL,AUGDT, SHKZG from BSID where BLART in ('ab','dg','dh','ds','dr','dc','rz','db','rx') ),t_bsad as ( select KUNNR,BUKRS,BLART,BELNR,BLDAT,GJAHR,WRBTR,WAERS,DMBTR,ZBD1T,ZBD2T,ZBD3T,AUGBL,AUGDT,SHKZG from BSAD ),t_vbrk as ( select VBELN,ERDAT,NETWR from VBRK v full join t_bsid t on t.BELNR=v.VBELN --where t.BLART not in ('DC','AB','DB') ),t_final as ( select KUNNR,BUKRS,BLART,BELNR,BLDAT,GJAHR, case when BLART not in ('ab','db','dc') THEN CASE WHEN B.SHKZG='H' THEN (v.NETWR*-1) else v.NETWR end else WRBTR end WRBTR,WRBTR b,WAERS,DMBTR,ZBD1T,ZBD2T,ZBD3T,AUGBL,AUGDT from t_bsid b left join t_vbrk v on v.VBELN=b.BELNR ) select *,isnull(WRBTR,0)-isnull(b,0) from t_final order by BLDAT desc</code>Please help. |
|