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

Write into FILE 3 the contents from File 1 and file 2


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

New User


Joined: 08 Jul 2005
Posts: 31

PostPosted: Mon Jul 25, 2005 4:25 pm
Reply with quote

Hello

I have two sorted files as mentioned below

File 1 File 2
------ --------
1 2
2 3
4 4
6 5


I need a logic in COBOL to write into FILE 3 the contents from File 1 and file 2 in sorted order elminating the duplicates(as below).

File 3
-------
1
2
3
4
5
6

Can some one tell me the simplest logic in COBOL ?
Back to top
View user's profile Send private message
jyoti_sethy

New User


Joined: 20 Jun 2005
Posts: 4
Location: bangalore

PostPosted: Mon Jul 25, 2005 5:26 pm
Reply with quote

you can use it through mergesort

efore that your two af the file should be sorted one as you have given the two files are sorte dso you can use mergesort
use it

merge workfile on ascending key <field>
desceding key <filed2> using file1,file2 giving file3.

in your procedure division.

you can get the sorted out you are looking for.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Mon Jul 25, 2005 5:47 pm
Reply with quote

Hi t1nt1n,

Try this code......

Code:
//STEP1     EXEC PGM=ICETOOL                     
//TOOLMSG   DD SYSOUT=*                         
//DFSMSG    DD SYSOUT=*                         
//IN     DD DSN=RECORDS.INPUT.FIRST,DISP=SHR 
//       DD DSN=RECORDS.INPUT.SECOND,DISP=SHR 
//OUT    DD DSN=RECORDS.OUT,           
//          DISP=(,KEEP,DELETE),               
//          SPACE=(80,(10,10),RLSE)             
//TOOLIN DD *                                   
SELECT FROM(IN) TO(OUT) ON(1,1,CH) FIRST       
//   


Regards,

Priyesh.
Back to top
View user's profile Send private message
karthikuma

New User


Joined: 29 Mar 2005
Posts: 62

PostPosted: Tue Aug 02, 2005 10:09 am
Reply with quote

hi friends,

tell me the logic in cobol.i'm waiting any one to give me the syntax of cobol how to do this.

regards,
kumar
Back to top
View user's profile Send private message
shivashunmugam Muthu

Active User


Joined: 22 Jul 2005
Posts: 114
Location: Chennai

PostPosted: Tue Aug 02, 2005 11:14 am
Reply with quote

In COBOL u can do file comparison logic...

try to compare wit the key field's of the both files.. say x for file1 & y for file2

compare x &y (in sequential read), if both sorted asc

if x>y

x does nt hav y's entry
write y content in to outfile
read only y again
compare

if x=y
write again the common recd
read both x & y this time

if x<y
x content nt in y...so write x in outfile
read only x this time & compare....

proceed like this till eof for both...this is the simplest logic to avoid duplicates & merging both files
Back to top
View user's profile Send private message
shivashunmugam Muthu

Active User


Joined: 22 Jul 2005
Posts: 114
Location: Chennai

PostPosted: Tue Aug 02, 2005 11:14 am
Reply with quote

In COBOL u can do file comparison logic...

try to compare wit the key field's of the both files.. say x for file1 & y for file2

compare x &y (in sequential read), if both sorted asc

if x>y

x does nt hav y's entry
write y content in to outfile
read only y again
compare

if x=y
write again the common recd
read both x & y this time

if x<y
x content nt in y...so write x in outfile
read only x this time & compare....

proceed like this till eof for both...this is the simplest logic to avoid duplicates & merging both files
Back to top
View user's profile Send private message
shivashunmugam Muthu

Active User


Joined: 22 Jul 2005
Posts: 114
Location: Chennai

PostPosted: Tue Aug 02, 2005 11:14 am
Reply with quote

In COBOL u can do file comparison logic...

try to compare wit the key field's of the both files.. say x for file1 & y for file2

compare x &y (in sequential read), if both sorted asc

if x>y

x does nt hav y's entry
write y content in to outfile
read only y again
compare

if x=y
write again the common recd
read both x & y this time

if x<y
x content nt in y...so write x in outfile
read only x this time & compare....

proceed like this till eof for both...this is the simplest logic to avoid duplicates & merging both files
Back to top
View user's profile Send private message
shivashunmugam Muthu

Active User


Joined: 22 Jul 2005
Posts: 114
Location: Chennai

PostPosted: Tue Aug 02, 2005 11:15 am
Reply with quote

In COBOL u can do file comparison logic...

try to compare wit the key field's of the both files.. say x for file1 & y for file2

compare x &y (in sequential read), if both sorted asc

if x>y

x does nt hav y's entry
write y content in to outfile
read only y again
compare

if x=y
write again the common recd
read both x & y this time

if x<y
x content nt in y...so write x in outfile
read only x this time & compare....

proceed like this till eof for both...this is the simplest logic to avoid duplicates & merging both files
Back to top
View user's profile Send private message
sriteja

New User


Joined: 25 Jul 2005
Posts: 15
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:17 pm
Reply with quote

Dear Priyesh,

Could you please elaborate what the below command line means in the JCL you have given above and how it helps for merge sort.

SELECT FROM(IN) TO(OUT) ON(1,1,CH) FIRST

Regards
Sri
Back to top
View user's profile Send private message
sriteja

New User


Joined: 25 Jul 2005
Posts: 15
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:18 pm
Reply with quote

Dear Priyesh,

Could you please elaborate what the below command line means in the JCL you have given above and how it helps for merge sort.

SELECT FROM(IN) TO(OUT) ON(1,1,CH) FIRST

Regards
Sri
Back to top
View user's profile Send private message
sriteja

New User


Joined: 25 Jul 2005
Posts: 15
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:18 pm
Reply with quote

Dear Priyesh,

Could you please elaborate what the below command line means in the JCL you have given above and how it helps for merge sort.

SELECT FROM(IN) TO(OUT) ON(1,1,CH) FIRST

Regards
Sri
Back to top
View user's profile Send private message
sriteja

New User


Joined: 25 Jul 2005
Posts: 15
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:19 pm
Reply with quote

Dear Priyesh,

Could you please elaborate what the below command line means in the JCL you have given above and how it helps for merge sort.

SELECT FROM(IN) TO(OUT) ON(1,1,CH) FIRST

Regards
Sri
Back to top
View user's profile Send private message
sriteja

New User


Joined: 25 Jul 2005
Posts: 15
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:19 pm
Reply with quote

Dear Priyesh,

Could you please elaborate what the below command line means in the JCL you have given above and how it helps for merge sort.

SELECT FROM(IN) TO(OUT) ON(1,1,CH) FIRST

Regards
Sri
Back to top
View user's profile Send private message
sriteja

New User


Joined: 25 Jul 2005
Posts: 15
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:20 pm
Reply with quote

Dear Priyesh,

Could you please elaborate what the below command line means in the JCL you have given above and how it helps for merge sort.

"SELECT FROM(IN) TO(OUT) ON(1,1,CH) FIRST "

Regards
Sri
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 How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top