View previous topic :: View next topic
|
Author |
Message |
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
Hi,
Follwing is the scenario
An array which occurs 10 times has two fileds Field A X(3) and Field B 9(2)
Following are the values in array
AAA 10
AAA 20
AAA 30
ABC 01
ABC 02
ABC 03
CCC 05
CCC 10
Desired O/p
AAA 60
ABC 06
CCC 15
get the unique value from Field A and Other should have the Summation of the corresponding values.
Please help me out in this.
Thanks,
Sree |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
It is fairly simple logic with a perform loop and maybe 1 or 2 add statements. Let us know where are you facing problems in this..? |
|
Back to top |
|
|
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
Hi agkshirsagar,
Thanks for the reply.
we tried to put the following logic
feld A - a
Field B- b
perform varying i from 1 to 1 until i > 10
if a(i) EQ a (i+1)
compute ws-add = b (i) to b(i+1)
else
move a(i) to ws-comp
move ws-add to ws-add1
end-if
end-perform.
problem- ws-add ,the sum total will not correct.
thanks,
sree |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
Please check this one.
perform ....
if a(i) = a(i+1)
add b(i) to ws-sum
end-if
if a(i) not = a(i+1)
add b(i) to ws-sum
display a(i) ws-sum
move zeros to ws-sum
end-if
end-perform.
Aji |
|
Back to top |
|
|
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
Hi Aji,
Thanks alot for the reply..
and i modified the code in the following way
perform varying i from 1 to 1 until i > 10
if a(i) NE a (i+1)
add b(i) to ws-add
move a(i) to ws-comp
move ws-add to ws-add1
move zeroes to ws-add
else
add B(i) to ws-add
end-if
end-perform.
thanks,
sree |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
SREE,
Are you able to understand the implications of the code you have written?
Are you getting o/p as mentioned in the first post.. I don't think so...
What does ws-add1 and ws-comp doing in your code? |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Is your array always in sorted order? (I can see that but just for the sake of asking.. ) If 'yes' then with some modifications you can use logic posted by Aji. Waiting for more inputs from you.. |
|
Back to top |
|
|
sreekusr Warnings : 1 New User
Joined: 28 Aug 2006 Posts: 54 Location: Madrid
|
|
|
|
Hi agkshirsagar,
Sorry for the delay.
Yes the i/p array is in sorted order and the variable ws-add1 and ws-comp i mistakingly added.
yes as per the code we will get the desired o/p.
thanks,
sree |
|
Back to top |
|
|
|