# Write line by line from two files

Author Message
justjpr

New User

Joined: 03 Nov 2022
Posts: 25
Location: INDIA

Posted: Fri Feb 09, 2024 2:00 am

 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.
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 2115
Location: USA

 Posted: Fri Feb 09, 2024 7:00 am 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.
Joerg.Findeisen

Senior Member

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

Posted: Fri Feb 09, 2024 11:53 am

 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              ****** ***********************
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 2115
Location: USA

Posted: Fri Feb 09, 2024 6:46 pm

 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 *******************
Joerg.Findeisen

Senior Member

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

 Posted: Fri Feb 09, 2024 7:10 pm 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.
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 2115
Location: USA

 Posted: Fri Feb 09, 2024 8:22 pm The major disadvantage is that the TS is not able to create any primitive part of code...
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 2115
Location: USA

Posted: Fri Feb 09, 2024 8:32 pm

 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.
justjpr

New User

Joined: 03 Nov 2022
Posts: 25
Location: INDIA

 Posted: Thu Feb 22, 2024 5:13 pm Thanks much sergeyken and Joerg.Findeisen. Your code helped me.
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics Compare 2 files and retrive records f... DFSORT/ICETOOL 3 Compare 2 files and write Matched/Unm... JCL & VSAM 8 Compare only first records of the fil... SYNCSORT 7 Merge two VSAM KSDS files into third ... JCL & VSAM 6 Joinkeys - 5 output files DFSORT/ICETOOL 7
Search our Forums:

 IBMMainframes.com is not an official and/or affiliated with IBM® in anyway Board Rules | FAQ | Downloads | Wiki | SiteMap | Contact Us