Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Query on Array: get the unique value from Field A

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 50
Location: London

PostPosted: Wed Aug 29, 2007 9:13 am    Post subject: Query on Array: get the unique value from Field A
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: 686
Location: Earth

PostPosted: Wed Aug 29, 2007 9:41 am    Post subject:
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: 50
Location: London

PostPosted: Wed Aug 29, 2007 10:11 am    Post subject: Reply to: Query on Array
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    Post subject: Reply to: Query on Array
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: 50
Location: London

PostPosted: Wed Aug 29, 2007 10:38 am    Post subject: Reply to: Query on Array
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: 686
Location: Earth

PostPosted: Wed Aug 29, 2007 10:55 am    Post subject:
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: 686
Location: Earth

PostPosted: Wed Aug 29, 2007 11:01 am    Post subject:
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: 50
Location: London

PostPosted: Wed Aug 29, 2007 11:12 am    Post subject: Reply to: Query on Array
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts outrec field outside range Danielle.Filteau SYNCSORT 10 Sat Mar 04, 2017 2:37 am
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us