Query de antigüedad no trae el abono a futuro

Hola amigos buen día, acudo a ustedes ya que tengo un detalle:

Tengo el siguiente Query de Antigüedad por tramos pero me gustaría que me trajera una linea adicional que es la de Abono a futuro esta es la que trae la antigüedad de saldos nativa de SAP. Sera que me podrían orientar ya que no he podido lograrlo.

SELECT
T2."CardCode" AS "Cliente",T2."RangeOfDaysOutStanding" AS "Rango",
IFNULL(T3."OverdueLC",0) AS "Saldo (ML)" 
FROM ((select "RangeOfDaysOutStanding", "CardCode" from (select '0-30' as "RangeOfDaysOutStanding"  
FROM DUMMY union all select '31-60' as "RangeOfDaysOutStanding" from DUMMY union all select '61-90' as "RangeOfDaysOutStanding" from DUMMY union all select '91-120' as "RangeOfDaysOutStanding" 
FROM DUMMY union all select '>120' as "RangeOfDaysOutStanding" from DUMMY) T0 cross join (select "CardCode" as "CardCode" 
FROM OCRD where "CardType" = 'C') T1) T2 
LEFT JOIN (SELECT "BusinessPartnerCode", sum("OverdueLC") AS "OverdueLC", "AgingBucket" 
FROM "_SYS_BIC"."sap.sbonavprod.ar.case/CustomerReceivableAgingQuery" ('PLACEHOLDER' = ('$$P_AgingBucketSize$$', '30')) GROUP BY "BusinessPartnerCode", "AgingBucket") T3 ON T2."RangeOfDaysOutStanding" = (CASE WHEN T3."AgingBucket" = '120+' THEN '>120' ELSE T3."AgingBucket" END) AND T2."CardCode" = T3."BusinessPartnerCode")
ORDER BY T2."CardCode", T2."RangeOfDaysOutStanding"

Saludos!

Hola… el otro día habilite el sql profiler para interceptar la consulta que hace el sistema cuando emites el reporte nativo de SAP.

Te lo comparto por si te ayuda.

SELECT T0.[TransId], T0.[Line_ID], MAX(T0.[Account]), MAX(T0.[ShortName]), MAX(T0.[TransType]), MAX(T0.[CreatedBy]), MAX(T0.[BaseRef]), MAX(T0.[SourceLine]), 
MAX(T0.[RefDate]), MAX(T0.[DueDate]), MAX(T0.[TaxDate]), MAX(T0.[BalDueCred]) - MAX(T0.[BalDueDeb]), MAX(T0.[BalFcCred]) - MAX(T0.[BalFcDeb]), MAX(T0.[BalScCred]) - MAX(T0.[BalScDeb]), 
MAX(T0.[LineMemo]), MAX(T1.[FolioPref]), MAX(T1.[FolioNum]), MAX(T0.[Indicator]), MAX(T2.[CardName]), MAX(T3.[CardCode]), MAX(T3.[CardName]), MAX(T2.[Balance]), MAX(T3.[NumAtCard]), 
MAX(T3.[SlpCode]), MAX(T0.[Project]), MAX(T0.[Debit]) - MAX(T0.[Credit]), MAX(T0.[FCDebit]) - MAX(T0.[FCCredit]), MAX(T0.[SYSDeb]) - MAX(T0.[SYSCred]), MAX(T2.[PymCode]), 
MAX(T3.[BlockDunn]), MAX(T3.[DunnLevel]), MAX(T3.[TransType]), MAX(T3.[IsSales]), MAX(T2.[Currency]), MAX(T0.[FCCurrency]), T0.[TransId], MAX(T2.[DunTerm]), 
MAX(T0.[DunnLevel]), T0.[BPLName], MAX(T2.[ConnBP]), MAX(T2.[CardCode]), T0.[TransId], MAX(T1.[AgrNo]) 
FROM  [dbo].[JDT1] T0  
INNER  JOIN [dbo].[OJDT] T1  ON  T1.[TransId] = T0.[TransId]   
INNER  JOIN [dbo].[OCRD] T2  ON  T2.[CardCode] = T0.[ShortName]    
LEFT OUTER  JOIN [dbo].[B1_JournalTransSourceView] T3  ON  T3.[ObjType] = T0.[TransType]  AND  T3.[DocEntry] = T0.[CreatedBy]  AND  
(T3.[TransType] <> 'I'  OR  (T3.[TransType] = 'I'  AND  T3.[InstlmntID] = T0.[SourceLine] ))  
WHERE T0.[RefDate] <= '20220214'  AND  T0.[RefDate] <= '20220214'  AND  T2.[CardType] = 'C'  AND  T2.[Balance] <> 0 
 AND  T2.[CardCode] >= 'C00624'  AND  T2.[CardCode] <= 'C00624'  AND  (T0.[BalDueCred] <> T0.[BalDueDeb]  OR  T0.[BalFcCred] <> T0.[BalFcDeb] ) 
 AND   NOT EXISTS (SELECT U0.[TransId], U0.[TransRowId] FROM  [dbo].[ITR1] U0  INNER  JOIN [dbo].[OITR] U1  ON  U1.[ReconNum] = U0.[ReconNum]   
 WHERE T0.[TransId] = U0.[TransId]  AND  T0.[Line_ID] = U0.[TransRowId]  AND  U1.[ReconDate] > '20220214'   
 GROUP BY U0.[TransId], U0.[TransRowId])   
 GROUP BY T0.[TransId], T0.[Line_ID], T0.[BPLName],T0.[RefDate],T0.[RefDate], T2.[CardType], T2.[Balance], T2.[CardCode], T2.[CardCode]
1 me gusta

Este tema se cerró automáticamente 30 días después de la última publicación. No se permiten nuevas respuestas.