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

Cobol code for sorting into two seperate output files


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

New User


Joined: 04 Jan 2007
Posts: 4
Location: CHENNAI

PostPosted: Thu Jan 04, 2007 2:45 pm
Reply with quote

hi...


actually i want to know how to create a cobol code for sorting a given file say on the basis of ssn.

Ex: Suppose the file has information regarding two individuals(ie 2 ssn)
now how to sort this and then details regarding each individual is put into two seperate output files.Can someone help me with this code....
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Jan 04, 2007 2:51 pm
Reply with quote

Hi back,
manoj84 wrote:
i want to know how to create a cobol code for sorting a given file say on the basis of ssn.
Ex: Suppose the file has information regarding two individuals(ie 2 ssn)
now how to sort this and then details regarding each individual is put into two seperate output files.Can someone help me with this code....
Sorting is simple in COBOL, but I'm not sure I understand your intended result...Suppose the file had 4 SSNs, would you want 4 output files?

Awaiting your reply,

Bill
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Thu Jan 04, 2007 3:00 pm
Reply with quote

Hi manoj84,

Quote:
Ex: Suppose the file has information regarding two individuals(ie 2 ssn)
now how to sort this and then details regarding each individual is put into two seperate output files.Can someone help me with this code....


This can be easily done through SORT( DFSORT/SYNCSORT)

Code:
SORT FIELDS=(1,5,CH,A)               
OUTFIL FILES=1,
      INCLUDE=(1,5,CH,EQ,C'AAAAA')       
OUTFIL FILES=2,
      INCLUDE=(1,5,CH,EQ,C'BBBBB')
here i am assuming that ssn field is in first 5 bytes

Why u want to go for cobol code?
Back to top
View user's profile Send private message
manoj84

New User


Joined: 04 Jan 2007
Posts: 4
Location: CHENNAI

PostPosted: Thu Jan 04, 2007 3:10 pm
Reply with quote

hi.

Actually sorry for not being clear in my query.This is what i am supposed to do...



- The details of transactions for 2 account number that happened in one day need to be
Processed and loaded into separate files.
- The input file needs to be sorted based on the ssn.
- The first output file will have all the records belonging to account number 1 and the second output file that of account number 2.
- After writing the records into the output file for the account numbers write another record at the end which has the entire amount for that account number summed up.

Another report file has to be generated, which should have the following details
- Counts of total number of records read and the total amount.
- Counts of total number of records written for account number 1 and the total amount for that account.
- Counts of total number of records written for account number 2 and the total amount for that account


...thank you for your quick replies...
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Thu Jan 04, 2007 3:15 pm
Reply with quote

Hi There,

That can be done throgh sort also ..
Please have a look at Frank's " Smart DFSORT Trick at:

http://.ibm.com/servers/storage/support/software/sort/mvs/tricks/
Back to top
View user's profile Send private message
manoj84

New User


Joined: 04 Jan 2007
Posts: 4
Location: CHENNAI

PostPosted: Thu Jan 04, 2007 3:26 pm
Reply with quote

hi. william;;


ya if there are 4 such ssns u will be puttin it into four output files...actually there are other records like tel-no,add ..etc in the input file relate to each ssn,so after sortin suppose to move relevant details to corresponding output file
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Jan 04, 2007 3:27 pm
Reply with quote

In general, this is how it could be done...
Code:
one input file: in1
two output files: out1 & out2
one sort file: sort

Sort input the file
Sort output procedure:
Return sort
if ssn1
   add 1 to cnt1
   add $ to $1
   write out1 from sort
else
   add 1 to cnt2
   add $ to $2
   write out2 from sort
endif

After the sort ends, report on both cnts and $s and the sum of them.

If there might be assitional SSNs:
if 1
  process
else
  if 2
    process
  endif
endif
Hope it helps....
Back to top
View user's profile Send private message
manoj84

New User


Joined: 04 Jan 2007
Posts: 4
Location: CHENNAI

PostPosted: Thu Jan 04, 2007 4:57 pm
Reply with quote

Thanks for the pseudo code....


Anyways ..Can u send me JCL code for the above program to execute..
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Jan 04, 2007 5:08 pm
Reply with quote

manoj84 wrote:
Anyways ..Can u send me JCL code for the above program to execute..
It would just be an execute, a DD for the input and two allocating DDs for output...quite location dependant....
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 TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Write line by line from two files DFSORT/ICETOOL 7
Search our Forums:

Back to Top