Merge two files



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

Merge two files

Postby kbabu » Sat Mar 13, 2021 6:10 pm

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.
kbabu
 
Posts: 4
Joined: Sat Mar 13, 2021 5:40 pm
Has thanked: 2 times
Been thanked: 0 time

Re: Merge two files

Postby sergeyken » Sat Mar 13, 2021 8:21 pm

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
Javas come and go, but JCL stays forever.
User avatar
sergeyken
 
Posts: 170
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 3 times
Been thanked: 17 times

Re: Merge two files

Postby kbabu » Sat Mar 13, 2021 8:37 pm

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
kbabu
 
Posts: 4
Joined: Sat Mar 13, 2021 5:40 pm
Has thanked: 2 times
Been thanked: 0 time

Re: Merge two files

Postby sergeyken » Sun Mar 14, 2021 7:49 am

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
Javas come and go, but JCL stays forever.

These users thanked the author sergeyken for the post:
kbabu (Mon Mar 15, 2021 8:25 am)
User avatar
sergeyken
 
Posts: 170
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 3 times
Been thanked: 17 times

Re: Merge two files

Postby willy jensen » Sun Mar 14, 2021 4:09 pm

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.

These users thanked the author willy jensen for the post:
kbabu (Mon Mar 15, 2021 8:25 am)
willy jensen
 
Posts: 342
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 46 times

Re: Merge two files

Postby willy jensen » Sun Mar 14, 2021 4:21 pm

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
willy jensen
 
Posts: 342
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 46 times

Re: Merge two files

Postby sergeyken » Sun Mar 14, 2021 7:30 pm

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
Javas come and go, but JCL stays forever.
User avatar
sergeyken
 
Posts: 170
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 3 times
Been thanked: 17 times

Re: Merge two files

Postby kbabu » Mon Mar 15, 2021 8:20 am

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
kbabu
 
Posts: 4
Joined: Sat Mar 13, 2021 5:40 pm
Has thanked: 2 times
Been thanked: 0 time

Re: Merge two files

Postby kbabu » Mon Mar 15, 2021 8:25 am

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.
kbabu
 
Posts: 4
Joined: Sat Mar 13, 2021 5:40 pm
Has thanked: 2 times
Been thanked: 0 time


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post