View previous topic :: View next topic
|
Author |
Message |
t1nt1n
New User
Joined: 08 Jul 2005 Posts: 31
|
|
|
|
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 |
|
|
jyoti_sethy
New User
Joined: 20 Jun 2005 Posts: 4 Location: bangalore
|
|
|
|
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 |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
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 |
|
|
karthikuma
New User
Joined: 29 Mar 2005 Posts: 62
|
|
|
|
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 |
|
|
shivashunmugam Muthu
Active User
Joined: 22 Jul 2005 Posts: 114 Location: Chennai
|
|
|
|
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 |
|
|
shivashunmugam Muthu
Active User
Joined: 22 Jul 2005 Posts: 114 Location: Chennai
|
|
|
|
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 |
|
|
shivashunmugam Muthu
Active User
Joined: 22 Jul 2005 Posts: 114 Location: Chennai
|
|
|
|
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 |
|
|
shivashunmugam Muthu
Active User
Joined: 22 Jul 2005 Posts: 114 Location: Chennai
|
|
|
|
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 |
|
|
sriteja
New User
Joined: 25 Jul 2005 Posts: 15 Location: Hyderabad
|
|
|
|
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 |
|
|
sriteja
New User
Joined: 25 Jul 2005 Posts: 15 Location: Hyderabad
|
|
|
|
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 |
|
|
sriteja
New User
Joined: 25 Jul 2005 Posts: 15 Location: Hyderabad
|
|
|
|
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 |
|
|
sriteja
New User
Joined: 25 Jul 2005 Posts: 15 Location: Hyderabad
|
|
|
|
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 |
|
|
sriteja
New User
Joined: 25 Jul 2005 Posts: 15 Location: Hyderabad
|
|
|
|
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 |
|
|
sriteja
New User
Joined: 25 Jul 2005 Posts: 15 Location: Hyderabad
|
|
|
|
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 |
|
|
|