BW 代码优化

56 篇文章 0 订阅

This blog describes the basic best ABAP coding practices which would be helpful for BW/BI consultants.


I have written it from Start, End & field routine perspective.


Assumption:  DB_tab is database table with field names as field1 field2 field3 field4 field5.

                          itab is an internal table with field names as field1 field2 field3 field4

 

1) Begin End routine with


IF RESULT_PACKAGE[] IS NOT INITIAL.


This is useful because if result package does not have any value and if there is a statement like


select field1 field 2 from DB_tab into table itab FOR ALL ENTRIES IN RESULT_PACKAGE

where  field3 = <result-package>-field3 AND field4 = <result-package>-field4.

 

it will hit the database table to check blank values (and will fetch value against blank field3 field4 from DB table into itab. This is undesirable most of the times). Thus we can save this fruitless DB_tab hit by checking this condition.

 

Same is the case with Source package.


2) Do not use Select * from


  Copy only required fields (columns) from database table into internal table do not copy all database table into your internal table unless it is necessary.

 

3) It's better to avoid use of into corresponding fields of

  Consider below example,


3.a Select field2 field3 field1 from DB_tab  into corresponding fields of itab WHERE ....

 

instead of it, use

 


3.b Select field1 field2 field3 from DB_tab into itab WHERE ...

 

This means, Define itab's columns in same order as that of database table. Also, Write into itab in same order.

In above examples performance of 3.b is much better than 3.a


4) Always use for all entries in result-package


  consider below example,


select field1 field 2 from DB_tab into table itab FOR ALL ENTRIES IN RESULT_PACKAGE

  where field3 = <result-package>-field3

     AND field4 = <result-package>-field4.


This will bring only those records from DB_tab into itab  whose fields3 & field4 values  present in result package.


This means, if result package contains only one entry with field3 = 6000 and field4 = NY

then above select statement only bring records from DB_tab with field3=6000 & field4 = NY into itab.


5) Use WHERE condition on Loop statement wherever possible.


Suppose you want to perform specific operation only for field4 = 'LA'.


LOOP AT RESULT-PACKAGE assigning <RESULT_FIELDS> WHERE field4 = 'LA'.

" code logic

ENDLOOP.


This can avoid useless loops for remaining values of field4.


6) Use SORT carefully.


If you have to compare field3 & field4 then sort itab by those fields only.

Use only those fields in Binary search and Delete adjucent duplicates.


  i.e   SORT itab by field3 field4.


  Then use  READ table itab into wa comparing field3 = <result_fields>-field3

                                                                                       field4 = <result_fields>-field4.

or Delete adjacent duplicates from itab comparing field3 field4.


Also, avoid use of sort on result_package as it requires considerable time to sort millions of records.


7) Don't forget to use IF SY-SUBRC.


Always use SY-SUBRC = 0 (success) check for SELECT & READ operations to avoid any runtime errors or  unintended result values.


0 stands for success

4 stands for failure, that is no key found

8 stands for failure but it means no further keys available.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值