ABAP方法的exporting类型参数,需要在方法实现最开始显式初始化么
Sent: Monday, September 23, 2013 10:59 AM
Subject: code review遺留問題: is it necessary to explicitly initialize the exporting parameter within implementation itself
像下圖里的exporting parameter需要在method 實現(xiàn)最開始時顯式CLEAR么?
答案是it depends.
pass by value checkbox默認未選中,即pass by reference,此時實參的reference直接傳到method 實現(xiàn)里,修改method里的形參即直接修改了實參。
如果是pass by value,在runtime進入method執(zhí)行時,abap runtime自動為輸入和輸出形參創(chuàng)建local object,然后把輸入實參的value copy到local object里,method里的計算都存儲在輸出形參的local object里,method執(zhí)行結(jié)束后再把local object的值copy到輸出實參。
在pass by reference的情況下,exporting參數(shù)在進入函數(shù)內(nèi)時不會自動被初始化,而仍然為傳入時實參的值,因此需要developer 自己負責(zé)去初始化,否則可能會出現(xiàn)unexpepected的behavior。
什么時候用pass by reference,什么時候用pass by value?
Pass by reference性能更好,但需要developer自己在實現(xiàn)里初始化exporting parameter
如果期望輸出參數(shù)僅當(dāng)method 成功執(zhí)行之后才返回給caller,用pass by value
如果參數(shù)是一個很復(fù)雜的structure,比如nested table,或者按照abap help里面的建議值—超過100bytes后最好用pass by reference。
二者更詳細的區(qū)別參考abap help。
Extended check會自動把所有違反規(guī)則的code 列出來,比如CL_CRM_SOC_FND_ACCESS_IMPL 有17處:
這些issue被categorize成programming guideline violation,不會算作ATC error。
要獲取更多Jerry的原創(chuàng)文章,請關(guān)注公眾號"汪子熙":
總結(jié)
以上是生活随笔為你收集整理的ABAP方法的exporting类型参数,需要在方法实现最开始显式初始化么的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【转】互联网网页响应速度测试标准
- 下一篇: what is conversion e