‎2007 Jul 03 3:36 AM
In the selection screen if the user enters any number from 01 - 20 in a particular field 'A'
Let's say the user enters n (1-20)
Based on that in the select query I have to extract A1,A2,A3,...,An and add all these into a single field a.
How can achieve it???
‎2007 Jul 03 3:50 AM
Hi,
Try this.
data c1(10).
data a1 type i.
select-options s1 for c1.
loop at s1.
concatenate 'A' s1-low into s1-low.
concatenate 'A' s1-high into s1-high.
modify s1 index sy-tabix transporting low high.
endloop.
select sum (f1) from db into A where f1 in s1.
‎2007 Jul 03 3:50 AM
Please create an dataelement and domain ... that domain should have the value table ... in the value table (1-20) -> (A1-A20) ... so that if you se this dataelement as parameter in the Program then you will get it as you want .
So
dataelement : ztest
domain : ztest -> value table with key and text as (1-20) & (A1-A20) .
so in program :
parameters : s_test for table-ztest .
reward points if it is usefull .....
Girish
‎2007 Jul 03 3:58 AM
karthik,
Say
DATA : A type i.
Parameters : v_num type i.
START-OF-SELECTION.
Select A1,A2,A3,...,An from source and a structure(v_struc) which is having the same structure of A1,A2,A3,...,An and
A = v_struc-A1 + v_struc-A2 + v_struc-A3 ................ v_struc-An.
Don't forget to reward if useful.....
‎2007 Jul 03 4:01 AM
‎2007 Jul 03 4:06 AM
Hi Karthik,
Whethere the n will be a parameter or select-option on the screen. As you written it as parameter? then at any time it will have a single value so no need to sum A<i><b>n</b></i> into another variable.
Regards,
Atish
‎2007 Jul 03 4:09 AM
let'ss say n is 5 then I have to add a1a2ab3a4a5. display this sum.
‎2007 Jul 03 4:17 AM
Hi Karthik,
try something like this,
lv_test type <A1>,
lv_test type <A1>.
parameters p_no TYpe char2.
concatenamet 'A' p_no into lv_test.
select * from DBtable into itab
where <a* varibale> between A1 AND lv_test.
Now
loop at itab.
lv_sum = lv_sum + itab<afield>.
endloop.
Regards,
Atish
‎2007 Jul 03 4:46 AM
Hi,
parameters:n type i.
data:res type i.
data:begin of itab,
a1 type i,
a2 type i,
a3 type i,
...
...
a20 type i.
end of itab.
itab-a1 = 3.
itab-a2 = 4.
itab-a3 = 5.
FIELD-SYMBOLS: <wa> TYPE ANY,
<comp> TYPE ANY.
ASSIGN itab TO <wa>.
do n times.
ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <comp>.
res = res + <comp>.
enddo.
write:/ res.
rgds,
bharat.