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

Write line by line from two files


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
justjpr

New User


Joined: 03 Nov 2022
Posts: 33
Location: INDIA

PostPosted: Fri Feb 09, 2024 2:00 am
Reply with quote

Code:

File-1:   
Line-F1L1
Line-F1L2
Line-F1L3
Line-F1L4
Line-F1L5
         
File-2:   
Line-F2L1
Line-F2L2
Line-F2L3
Line-F2L4
Line-F2L5
         
Output:   
Line-F1L1
Line-F2L1           
-------------------
Line-F1L2           
Line-F2L2           
-------------------
Line-F1L3           
Line-F2L3           
-------------------
Line-F1L4           
Line-F2L4           
-------------------
Line-F1L5           
Line-F2L5           


I am hoping that the requirement is easily understandable from the above screen.

All the files are PS, FB, and LRECL=80. Both input files have equal record counts.


I am aware that we can write one by one line from both files using sequence numbers.
The idea is
File-1 : Add odd numbers at the end. ==> 1,3,5 ==> SEQNUM start from 1, increment by 2
File-2 : Add even numbers at the end. ==> 2,4,6 ==> SEQNUM start from 2, increment by 2

Now merge both files using the ascending order of sequence numbers so that line by line would be copied from both files. (SEQNO 1,2,3,4,5,6)
I don't know how to write the code for this step.

Step-2:
I have the separator line logic (80-hyphens line after every two records). The tested code is

Code:
//SYSIN    DD *                                       
  SORT FIELDS=COPY                                     
  INREC IFTHEN=(WHEN=GROUP,RECORDS=2,PUSH=(81:ID=8))   
  OUTFIL REMOVECC,BUILD=(1,80),                       
  SECTIONS=(81,8,TRAILER3=(80C'-'))                   
/*   


Thanks.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2140
Location: USA

PostPosted: Fri Feb 09, 2024 7:00 am
Reply with quote

1. Your method seems to be correct. Try to code it using SEQNUM parameters and MERGE statement of SORT utility.

2. Another way may be as follows: try to use JOINKEYS statements on extra fields added to each file by SEQNUM parameter of INREC statement.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1334
Location: Bamberg, Germany

PostPosted: Fri Feb 09, 2024 11:53 am
Reply with quote

Code:
//WHATEVER EXEC PGM=SORT                   
//SORTIN01 DD *                           
Line-F1L1                                 
Line-F1L2                                 
Line-F1L3                                 
Line-F1L4                                 
Line-F1L5                                 
/*                                         
//SORTIN02 DD *                           
Line-F2L1                                 
Line-F2L2                                 
Line-F2L3                                 
Line-F2L4                                 
Line-F2L5                                 
/*                                         
//SYSOUT   DD SYSOUT=*                     
//SORTOUT  DD SYSOUT=*                     
//SYSIN    DD *                           
  OPTION EQUALS                           
  INREC OVERLAY=(81:SEQNUM,8,BI)   
  MERGE FIELDS=(81,8,BI,A)                 
  OUTFIL FNAMES=(SORTOUT),                 
    REMOVECC,                   
    BUILD=(1,80)                           
  END                                     
/*


Code:
****** ***********************
000001 Line-F1L1             
000002 Line-F2L1             
000003 Line-F1L2             
000004 Line-F2L2             
000005 Line-F1L3             
000006 Line-F2L3             
000007 Line-F1L4             
000008 Line-F2L4             
000009 Line-F1L5             
000010 Line-F2L5             
****** ***********************
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2140
Location: USA

PostPosted: Fri Feb 09, 2024 6:46 pm
Reply with quote

Code:
//JOIN     EXEC PGM=SORT                       
//INPUT1   DD *                               
Line-F1L1                                     
Line-F1L2                                     
Line-F1L3                                     
Line-F1L4                                     
Line-F1L5                                     
/*                                             
//INPUT2   DD *                               
Line-F2L1                                     
Line-F2L2                                     
Line-F2L3                                     
Line-F2L4                                     
Line-F2L5                                     
/*                                             
//SYSOUT   DD SYSOUT=*                         
//SORTOUT  DD SYSOUT=*                         
//SYSIN    DD *                               
 JOINKEYS F1=INPUT1,                           
          FIELDS=(81,8,A),SORTED               
 JOINKEYS F2=INPUT2,                           
          FIELDS=(81,8,A),SORTED               
 REFORMAT FIELDS=(F1:1,80,                     
                  F2:1,80)                     
 SORT FIELDS=COPY                             
 OUTFIL FNAMES=(SORTOUT),                                               
        BUILD=(1,80,                                                   
            /,81,80,                                                   
            /,C'---------------------------------------------------')   
  END                                                                   
//*                                                                     
//JNF1CNTL DD *                                                         
 INREC OVERLAY=(81:SEQNUM,8,ZD)                                         
//JNF2CNTL DD *                                                         
 INREC OVERLAY=(81:SEQNUM,8,ZD)                                         
//*                                                                     

Code:
********************************* TOP OF DATA *********************
Line-F1L1                                                         
Line-F2L1                                                         
---------------------------------------------------               
Line-F1L2                                                         
Line-F2L2                                                         
---------------------------------------------------               
Line-F1L3                                                         
Line-F2L3                                                         
---------------------------------------------------               
Line-F1L4                                                         
Line-F2L4                                                         
---------------------------------------------------               
Line-F1L5                                                         
Line-F2L5                                                         
---------------------------------------------------               
******************************** BOTTOM OF DATA *******************
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1334
Location: Bamberg, Germany

PostPosted: Fri Feb 09, 2024 7:10 pm
Reply with quote

The advantage of the JOINKEYS is, that it is more understandable. Disadvantage, it requires temporary duplicate LRECL. The underestimated MERGE operator would here perform better, IMHO.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2140
Location: USA

PostPosted: Fri Feb 09, 2024 8:22 pm
Reply with quote

The major disadvantage is that the TS is not able to create any primitive part of code...
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2140
Location: USA

PostPosted: Fri Feb 09, 2024 8:32 pm
Reply with quote

Joerg.Findeisen wrote:
The advantage of the JOINKEYS is, that it is more understandable. Disadvantage, it requires temporary duplicate LRECL.

AFAIK, JFN1CNTL is handled by SORT "on the fly" - every single record is extended before it is joined. No duplicated copy of the whole input is created.
Back to top
View user's profile Send private message
justjpr

New User


Joined: 03 Nov 2022
Posts: 33
Location: INDIA

PostPosted: Thu Feb 22, 2024 5:13 pm
Reply with quote

Thanks much sergeyken and Joerg.Findeisen. Your code helped me.
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts 3 files concatenated to 1 DFSORT/ICETOOL 2
No new posts JCL sort to compare dates in two file... DFSORT/ICETOOL 2
No new posts batch SFTP job using AOPBATCH unable ... All Other Mainframe Topics 7
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files and write Matched/Unm... JCL & VSAM 8
Search our Forums:

Back to Top