1. 現狀
由于收到一個ATC issue:
image
在ADT中查看該CDS view的dependency analyzer:
image
access的db table 多達220!
image
超出了VDM CDS Metadata Checks (POC_ANNOTA) rule:
“Consumption view selects from 224 used tables (max allowed 100)”。
不過根據經驗,猜測只有當access db超過200時才會報atc issue。
2.分析
當前cds 的架構如圖:
CDS architecture.PNG
P_TW_TaxItemReversal 由P_TW_TaxItemConsume 和I_TW_TaxItemCube join而來。而 I_TW_TaxItemCube 本身又是從P_TW_TaxItemConsume 推演出來的,P_TW_TaxItemConsume 的復雜度被放大了2倍。
仔細看下業務邏輯:
- P_TW_TaxItemReversal是為了按document class匯總生成pdf提供數據。
- I_TW_TaxItemCube經過底層的計算已經得到了比較準確的document class以及其它一些信息,故可以保留這個cds view。但此cds view里面的憑證可能是reversal憑證,并不知道對應的原始憑證
- join 另一邊的P_TW_TaxItemConsume其實只是為了拿到reversal憑證對應的原始憑證。
因此可以看出,P_TW_TaxItemConsume的目的只是為了帶出bset中行項目上的ReverseDocument。這完全可以從bset 和bkpf推演出來而不用再去重復一遍P_TW_TaxItemConsume繁雜的推演邏輯。
解決
新的架構如下:
new CDS architecture.PNG
修改P_TW_TaxItemConsume:
define view P_TW_TaxItemConsume
as select from I_TaxItem
{
key CompanyCode,
key AccountingDocument,
key FiscalYear,
key AccountingDocumentItem,
case _AccountingDocument.IsReversal
when 'X'
then _AccountingDocument.ReverseDocument
else _AccountingDocument.AccountingDocument
end as OriginalDocument,
case _AccountingDocument.IsReversal
when 'X' then cast((cast(_AccountingDocument.ReverseDocumentFiscalYear as abap.int4) - 1911) as sstring)
else cast((cast(_AccountingDocument.FiscalYear as abap.int4) - 1911) as sstring)
end
as OriginalDocumentTWYear,
cast(decimal_shift( amount => TaxAmountInCoCodeCrcy,
currency => CompanyCodeCurrency ) as abap.dec(12, 0)) as TaxAmount, // 9. Tax Amount
cast(decimal_shift( amount => TaxBaseAmountInCoCodeCrcy,
currency => CompanyCodeCurrency ) as abap.dec(12, 0)) as TaxBaseAmount
}
修改P_TW_TaxItemReversal, 去掉P_TW_TaxItemConsume的參數
define view P_TW_TaxItemReversal
with parameters
P_StatryRptgEntity : srf_reporting_entity,
P_StatryRptCategory : srf_rep_cat_id,
P_StatryRptRunID : srf_report_run_id,
P_StatryRptRunType : srf_report_run_type
as select from P_TW_TaxItemConsume as taxItem
inner join I_TW_TaxItemCube(
P_StatryRptgEntity :$parameters.P_StatryRptgEntity ,
P_StatryRptCategory :$parameters.P_StatryRptCategory,
P_StatryRptRunID :$parameters.P_StatryRptRunID,
P_StatryRptRunType :$parameters.P_StatryRptRunType
)
as cube on taxItem.CompanyCode = cube.CompanyCode
and taxItem.OriginalDocumentTWYear = cube.TaiwaneseCalendarYear
and taxItem.OriginalDocument = cube.AccountingDocument
and taxItem.AccountingDocumentItem = cube.AccountingDocumentItem
{
...
}
經過此次修改,dependency analyzer中查看cds C_TW_VATDeclarationItem 復雜度從220降為了119,應該可以通過atc check了
dependency AFTER.png