Page 1 of 1

Merge two files

PostPosted: Sat Mar 13, 2021 6:10 pm
by kbabu
Hi Forum,

I am a newbie here but not to MF. I keep coming here for suggestions and tricks. But this is my first post.

I have a unique usecase where I have to prepare the SYSIN card for an IEBCOPY job. I create two temp files - one for the 'copy operation statement' and the other one for the 'select member' statements. Below are the steps.

//STEP010 EXEC PGM=SORT
//SORTIN DD *
COPYGRP INDD=IN0007,OUTDD=OUT0007
//SORTOUT DD DISP=(,PASS),DSN=&&CPYSTMT
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
//*
//STEP020 EXEC PGM=SORT
//SORTIN DD DISP=SHR,DSN=XXX.XXX.XXX
//OXXX DD DISP=(,PASS),DSN=&&CPYLST
//SYSIN DD *
OPTION COPY
OUTFIL FNAMES=OXXX,
INCLUDE=(15,4,CH,EQ,C'XXXX'),
OUTREC=(1:5X,6:C'S M=((YYYY,',17:1,8,25:C'))',27:54X)

I have to merge these two files to prepare the sysin file that should look like below

COPYGRP INDD=IN0007,OUTDD=OUT0007
S M=((YYYY,AAAAAA))
COPYGRP INDD=IN0007,OUTDD=OUT0007
S M=((YYYY,BBBBBB))

I do not know how to achieve this as the first file has only one record and second file has multiple(it will vary) records. I know how to merge records using SEQNUM technique but that'll give a useful output only if the first file has equal no of records as that of the second one. And simple merge won't help either.

Can someone help please?

Side note : For a specific reason I have to copy the content of YYYY member from one dataset to another and rename it to a valid member name. IEBCOPY says that there should be an operation for every copy & rename and that's the reason I need the COPYGRP operation for all members.

Apologies if it seems to be a naïve ask.

Re: Merge two files

PostPosted: Sat Mar 13, 2021 8:21 pm
by sergeyken
1. Learn how to use the code tags in your code samples.

2. Try to understand the SORT terminology, to distinguish between MERGE, JOIN, and CONCATENATE operations. They are ABSOLUTELY different. What exactly do you need??

3. Prior to presenting the code to perform an operation you don’t know about, please, present examples of your data, with a minor explanation of your goal:
- input data
- desired conversion rules
- desired output data

Re: Merge two files

PostPosted: Sat Mar 13, 2021 8:37 pm
by kbabu
Hi Sergeyken,

Thanks for your reponse.

Basically I have to JOIN these two files

Input file 1 has only one record :

COPYGRP INDD=IN0007,OUTDD=OUT0007


Input file 2 has 5126 records:

S M=((YYYY,AAAAAA ))
S M=((YYYY,BBBBBB ))
.....................
.....................
.....................


My output file should have:

COPYGRP INDD=IN0007,OUTDD=OUT0007
S M=((YYYY,AAAAAA))            
COPYGRP INDD=IN0007,OUTDD=OUT0007
S M=((YYYY,BBBBBB))            
...........................
...........................
...........................


Tia
kbabu

Re: Merge two files

PostPosted: Sun Mar 14, 2021 7:49 am
by sergeyken
This is neither JOIN, nor MERGE, nor CONCATENATE. I even can hardly understand the goal: what the benefit of this result might be?
So far, I don’t care about your goal...

You can combine your lines, for instance in this manner. There is absolutely no reason to complicate the task when one of your “files” is just a constant string.
//COMBO EXEC PGM=SORT
. . . . .
//SORTIN DD *
S M=((YYYY,AAAAAA ))
S M=((YYYY,BBBBBB ))
.....................
.....................
.....................
//SYSIN DD *
 SORT FIELDS=COPY
 OUTFIL BUILD=(C’ COPYGRP INDD=IN0007,OUTDD=OUT0007’,
              /,1,80)
 END

Re: Merge two files

PostPosted: Sun Mar 14, 2021 4:09 pm
by willy jensen
I might be missing something here.
With IEBCOPY you can have several select statements for a single COPY statement, like:
COPYGRP INDD=IN0007,OUTDD=OUT0007
  S M=((YYYY,AAAAAA))            
  S M=((YYYY,BBBBBB))

So as long as you copy between the same 2 libraries I cannot see the need for more then the first COPYGRP.

Re: Merge two files

PostPosted: Sun Mar 14, 2021 4:21 pm
by willy jensen
So your job could look something like this:
//STEP020 EXEC PGM=SORT
//SORTIN   DD DISP=SHR,DSN=XXX.XXX.XXX
//OXXX     DD DISP=(,PASS),DSN=&&CPYLST
//SYSIN    DD *
 OPTION COPY
 OUTFIL FNAMES=OXXX,
 INCLUDE=(15,4,CH,EQ,C'XXXX'),
 OUTREC=(1:5X,6:C'S M=((YYYY,',17:1,8,25:C'))',27:54X)
//C      EXEC PGM=IEBCPY
//SYSPRINT DD SYSOUT=*
//INLIB    DD DISP=SHR,DSN=...
//OUTLIB   DD DISP=SHR,DSN=...
//SYSIN    DD *
 COPYGRP INDD=INLIB,OUTDD=OUTLIB
//         DD DISP=OLD,DSN=&&CPYLST

Re: Merge two files

PostPosted: Sun Mar 14, 2021 7:30 pm
by sergeyken
Since the original question about SORT has been transferred into the question about COPY utility, then I may suggest the most straightforward approach:
//COPYSTEP EXEC PGM=IEBCOPY
//SYSPRINT DD SYSOUT=*
//INLIB    DD DISP=SHR,DSN=...
//OUTLIB   DD DISP=SHR,DSN=...
//SYSIN    DD *
 COPYGRP INDD=INLIB,OUTDD=OUTLIB
//         DD DISP=SHR,DSN=XXX.XXX.XXX

Re: Merge two files

PostPosted: Mon Mar 15, 2021 8:20 am
by kbabu
willy jensen wrote:I might be missing something here.
With IEBCOPY you can have several select statements for a single COPY statement, like:
COPYGRP INDD=IN0007,OUTDD=OUT0007
  S M=((YYYY,AAAAAA))            
  S M=((YYYY,BBBBBB))

So as long as you copy between the same 2 libraries I cannot see the need for more then the first COPYGRP.


Hi Willy, Thanks for your inputs. I tried this already but IEBCOPY doesn't allow this construct. Please see the error below

PDSMAN FASTCOPY PROCESSING ACTIVE     2021074      03:44:26  JOBNAME SY3
    COPYGRP INDD=IN0001,OUTDD=OUT0001                                  
    S M=((YYYY,AAAAAAAA))                                              
    S M=((YYYY,BBBBBBBB))                                              
COPYING TO   PDS   OUTDD=OUT0001  VOL=DVT01D DSN=XXX.XXX.XXX      
        FROM PDSE   INDD=IN0001   VOL=DVT00A DSN=ZZZ.ZZZ.ZZZ
RECFM/LRECL/BLKSIZE  INPUT: FB,80,6160      OUTPUT: FB,80,27920        
REBLOCKING IS BEING PERFORMED                                          
CANNOT SPECIFY DUPLICATE MEMBER NAME YYYY     FOR SELECT/EXCLUDE/RENAME

Re: Merge two files

PostPosted: Mon Mar 15, 2021 8:25 am
by kbabu
sergeyken wrote:This is neither JOIN, nor MERGE, nor CONCATENATE. I even can hardly understand the goal: what the benefit of this result might be?
So far, I don’t care about your goal...

You can combine your lines, for instance in this manner. There is absolutely no reason to complicate the task when one of your “files” is just a constant string.
//COMBO EXEC PGM=SORT
. . . . .
//SORTIN DD *
S M=((YYYY,AAAAAA ))
S M=((YYYY,BBBBBB ))
.....................
.....................
.....................
//SYSIN DD *
 SORT FIELDS=COPY
 OUTFIL BUILD=(C’ COPYGRP INDD=IN0007,OUTDD=OUT0007’,
              /,1,80)
 END


Yes sergeyken. Your solution worked like a charm. Thanks a lot for your time.