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

how to add the amount for duplicate records and write


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
SRUTHI DRAVIDAMANI

New User


Joined: 31 Jan 2018
Posts: 7
Location: INDIA

PostPosted: Wed Feb 21, 2018 7:21 pm
Reply with quote

how to add the amount for duplicate records and write it in a single record in cobol program?
For ex:
Inp:
1)empid15 account15 amt100
2)empid15 account15 amt100

Out:
1)empid15 account15 amt200
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2454
Location: Hampshire, UK

PostPosted: Wed Feb 21, 2018 7:26 pm
Reply with quote

Easy - what is your problem? And why use COBOL when you could use your sort product?
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8794
Location: Welsh Wales

PostPosted: Wed Feb 21, 2018 7:56 pm
Reply with quote

Maybe a candidate for the rookie forum ?
Back to top
View user's profile Send private message
SRUTHI DRAVIDAMANI

New User


Joined: 31 Jan 2018
Posts: 7
Location: INDIA

PostPosted: Wed Feb 21, 2018 8:41 pm
Reply with quote

because i have five files and im converting that into ten files as header and detail records separately. So i need to do this process for all ten files.
Back to top
View user's profile Send private message
SRUTHI DRAVIDAMANI

New User


Joined: 31 Jan 2018
Posts: 7
Location: INDIA

PostPosted: Wed Feb 21, 2018 10:22 pm
Reply with quote

Can someone tell the program logic? i need to do this in COBOL only that is the requirement.
Back to top
View user's profile Send private message
enrico-sorichetti

Senior Moderator


Joined: 14 Mar 2007
Posts: 10716
Location: italy

PostPosted: Wed Feb 21, 2018 10:44 pm
Reply with quote

Quote:
how to add the amount for duplicate records and write it in a single record in cobol program?


Quote:
because i have five files and im converting that into ten files as header and detail records separately.


unless the TS comes up with a reasonable description of the requirement the topic will be locked
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2575
Location: NYC,USA

PostPosted: Thu Feb 22, 2018 1:10 am
Reply with quote

Code:

set first-record-read to true
initialize ws-amt

Read input DS until end
if not end of DS
  If first-record-read
     move ws-in-empid to ws-previous-empid
     move ws-in-empid  to ws-current-empid
  else
     move ws-in-empid  to ws-current-empid
  end-if
   if  ws-previous-empid = ws-current-empid
           compute ws-amt = ws-amt+ amt100
           second-record-read to true
   else
     write out DS based on ws-previous-empid and ws-amt
     move ws-in-emp id to ws-previous-empid
     initialize ws-amt
     compute ws-amt = ws-amt+ amt100
   end-if
else
    If second-record-read
       write out DS based on ws-previous-empid and ws-amt
    end-if
end-if
     
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Sat Jun 30, 2018 2:43 am
Reply with quote

Rohit Umarjikar wrote:
Code:

set first-record-read to true
initialize ws-amt

Read input DS until end
if not end of DS
  If first-record-read
     move ws-in-empid to ws-previous-empid
     move ws-in-empid  to ws-current-empid
  else
     move ws-in-empid  to ws-current-empid
  end-if
   if  ws-previous-empid = ws-current-empid
           compute ws-amt = ws-amt+ amt100
           second-record-read to true
   else
     write out DS based on ws-previous-empid and ws-amt
     move ws-in-emp id to ws-previous-empid
     initialize ws-amt
     compute ws-amt = ws-amt+ amt100
   end-if
else
    If second-record-read
       write out DS based on ws-previous-empid and ws-amt
    end-if
end-if
     


Can someone tell me whether any other better logic in cobol to achieve this scenario...
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Sat Jun 30, 2018 3:02 am
Reply with quote

[quote="Rohit Umarjikar[/quote]

This logic will not work for all the scenarios icon_sad.gif
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2454
Location: Hampshire, UK

PostPosted: Sat Jun 30, 2018 3:34 pm
Reply with quote

Quote:
This logic will not work for all the scenarios

How does it not work for the scenario that it was designed for?

If your scenario is the same then the logic should work. If your scenario is different then, of course, it will not work - you need a different algorithm.

But as you have just tagged onto an old topic with no details what do you expect in the way of help?
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 Merging more than two records DFSORT/ICETOOL 15
No new posts Matching and non matching records usi... DFSORT/ICETOOL 11
This topic is locked: you cannot edit posts or make replies. Write Character to Hexadecimal file w... COBOL Programming 8
No new posts REMOVE DUPLICATE RECORDS BASED ON A S... DFSORT/ICETOOL 4
No new posts Using sort on VB records based on off... DFSORT/ICETOOL 6
Search our Forums:

Back to Top