IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Query on Array: get the unique value from Field A


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Wed Aug 29, 2007 9:13 am
Reply with quote

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
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Wed Aug 29, 2007 9:41 am
Reply with quote

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
View user's profile Send private message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Wed Aug 29, 2007 10:11 am
Reply with quote

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
View user's profile Send private message
Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Wed Aug 29, 2007 10:28 am
Reply with quote

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
View user's profile Send private message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Wed Aug 29, 2007 10:38 am
Reply with quote

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
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Wed Aug 29, 2007 10:55 am
Reply with quote

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.. icon_confused.gif I don't think so...
What does ws-add1 and ws-comp doing in your code?
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Wed Aug 29, 2007 11:01 am
Reply with quote

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
View user's profile Send private message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Wed Aug 29, 2007 11:12 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
Search our Forums:

Back to Top