Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Write into FILE 3 the contents from File 1 and file 2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL
Author Message
t1nt1n

New User


Joined: 08 Jul 2005
Posts: 31

PostPosted: Mon Jul 25, 2005 4:25 pm    Post subject: Write into FILE 3 the contents from File 1 and file 2
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
References
jyoti_sethy

New User


Joined: 20 Jun 2005
Posts: 4
Location: bangalore

PostPosted: Mon Jul 25, 2005 5:26 pm    Post subject:
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

Global Moderator


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

PostPosted: Mon Jul 25, 2005 5:47 pm    Post subject: Re: File logic
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

Active User


Joined: 29 Mar 2005
Posts: 65

PostPosted: Tue Aug 02, 2005 10:09 am    Post subject: Re: File logic
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    Post subject: Re: File logic
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    Post subject: Re: File logic
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    Post subject: Re: File logic
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    Post subject: Re: File logic
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: 14
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:17 pm    Post subject:
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: 14
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:18 pm    Post subject:
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: 14
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:18 pm    Post subject: Sort syntax
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: 14
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:19 pm    Post subject: Sort syntax
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: 14
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:19 pm    Post subject: Sort syntax
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: 14
Location: Hyderabad

PostPosted: Tue Aug 02, 2005 12:20 pm    Post subject: Sort syntax
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
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL All times are GMT + 6 Hours
Page 1 of 1