‎2011 Aug 31 8:16 PM
Hi,
I am selecting the data from COSP table. When processing the data I have to go thourgh the fields from WTG001 to WKF016 (which are 64 fields) and add up all the values into a variable. I was wondering if there is a way to find out the fields which are NOT NULL and directly sum up the values into variable.
Currently the code is:
data: gt_cosp TYPE STANDARD TABLE OF cosp,
wa_cosp LIKE LINE OF gt_cosp.
select *
into table gt_cosp
from cosp
where objnr = lv_objnr.
loop at gt_cosp into wa_cosp.
lv_value = wa_cosp-WTG001 + wa_cosp-WTG002 + .....wa_cosp-WKF016
..........
..........
endloop.
What I am trying to do is, if there are only 3 fields with values, let's say WTG004, WTG006, WTG009. Then I want to sum up only these 3 fields into lv_value. Is there anything that can be used to find this out dynamically. I was thinking of using Field Symbols. Nut sure how I can do that though.
Please let me know. Appreciate your help. Thanks.
Edited by: sey ni on Aug 31, 2011 3:16 PM
‎2011 Aug 31 8:26 PM
Hi
Try using SUM statement inside the loop.
http://www.abapprogramming.net/2007/06/lesson-22-internal-table-operations.html
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/content.htm
Shiva
‎2011 Aug 31 8:26 PM
Hi
Try using SUM statement inside the loop.
http://www.abapprogramming.net/2007/06/lesson-22-internal-table-operations.html
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb381a358411d1829f0000e829fbfe/content.htm
Shiva
‎2011 Aug 31 9:11 PM
Don't know why this is a problem.... those fields are all curr, so will all have zero or non-zero value....a simple addition will get your the results.... you could do the hard way....
if wa_cosp-WTG001 ne 0.
lv_value = lv_value + wa_cost_WTG001.
endif.
if wa_costp-wtg002 ne 0.
lv_value = lv_value + wa-cosp-wtg002.
endif.
etc.
‎2011 Aug 31 9:32 PM
I know it is a little bit of programming and writing a line of code with all these 64 fields in it. But was just wondering if there is a better way of doing this which I am not aware of. Thanks for the responses though.
‎2011 Aug 31 9:34 PM