MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Merging two files into one file at different positions

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Thu Jul 01, 2021 11:31 am    Post subject: Merging two files into one file at different positions Reply with quote

Hi All,

I have two files as below

File1: Rec len - 300
key1 - 1,5

File2; Rec len - 200
key2 - 6,5

I want to have single file as below. no matching need to be done.
Output file structure:
1st byte - A - for file1 record/B for file2 record
2 to 4 - AAA if Key1 is 111 for file1 record(mutiple keys and mapping is there)/BBB if Key2 for file2(mutiple keys and mapping is there)
5 to 304 - Place file 1 records in this position
305 to 504 - Place file 2 records in this position.

to explain the process first file1 records need to be written into output file
with
1 - A
2 to 4 - AAA
5 to 304 - file1 record
305 to 504 - spaces

then file2 records need to be written into output file as below
1 - B
2 to 4 - BBB
5 to 304 - spaces
305 to 504 - file2 record.

Please help me with suitable job if this can be done in SORT.
Sorry if this is duplicate post and similar problem is already answered, please guide me to the post, I already searched but couldn't find any such.

Thank you
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu Jul 01, 2021 12:54 pm    Post subject: Re: Merging two files into one file at different positions Reply with quote

psmadhusudhan wrote:
Hi All,
I want to have single file as below. no matching need to be done.
Output file structure:
1st byte - A - for file1 record/B for file2 record
2 to 4 - AAA if Key1 is 111 for file1 record(mutiple keys and mapping is there)/BBB if Key2 for file2(mutiple keys and mapping is there)
5 to 304 - Place file 1 records in this position
305 to 504 - Place file 2 records in this position.


psmadhusudhan,

Your requirement does NOT make any sense. You preface your requirement with NO matching need to be done, but then your desired output mentions that you need a single Long file of 504 bytes with contents from file 1 + File-2

Output record = 504
Code:

file-1 data | file-2 data


So without a MATCHING how do you plan to append the file-1 record to file-2 record?

is the match on record by record basis? ie. 1st record of file-1 will be merged with 1st record of file-2 and 2nd with 2nd record and so on?

or do you merge every record of file-1 with every record of file-2 which will result in a Cartesian join? like file-1 has 10 records and file-2 has 10 records then the output will be 10 X 10 = 100 records.

You initially specify a key but then it is not used any where. Do you need to match on key?

What is the RECFM of File-1 and file-2 ?

Can you also show an sample input and desired output?
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Fri Jul 02, 2021 2:15 am    Post subject: Reply with quote

I am sorry Kolusu if my wordings didn't explain my requirments clearly.
So I am writing control cards below through which I haave achieved the results but in 3 steps,
these can give an idea about my requirement.

On file1 I ran below card in Step1
Code:
SORT FIELDS=COPY                             
OUTREC IFTHEN=(WHEN=(1,5,CH,EQ,C'111'),
       BUILD=(C'F1',C'AAA',1,300,200X)),
       IFTHEN=(WHEN=NONE,                     
       BUILD=(C'F1',C'ZZZ',1,300,200X))


on file2 I ran below card in Step2
Code:
SORT FIELDS=COPY                             
OUTREC IFTHEN=(WHEN=(1,5,CH,EQ,C'111'),
       BUILD=(C'F2',C'BBB',300X,1,200)),
       IFTHEN=(WHEN=NONE,                     
       BUILD=(C'F2',C'ZZZ',300X,1,200))


later I merged both files in Step3 to get final output

this process is taking 3 steps for me.
Is it possible to do all this single step
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Jul 02, 2021 10:08 am    Post subject: Reply with quote

psmadhusudhan,

Sigh ! I sincerely wish you paid attention to the questions posted earlier. I asked about the RECFM of the file and a sample data, however you did not provide either of them.

Either way use the following DFSORT JCL which will give you the results assuming that the input files have RECFM=FB

Code:

//STEP0100 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//INA      DD DISP=SHR,DSN=Your Input file of LRECL 300   
//INB      DD DISP=SHR,DSN=Your Input file of LRECL 200           
//SORTOUT  DD DSN=Your output file LRECL 510,
//            DISP=(NEW,CATLG,DELETE),
//            SPACE=(CYL,(X,Y),RLSE)
//SYSIN    DD *                                                   
  OPTION COPY                                                     
  JOINKEYS F1=INA,FIELDS=(1,2,A),SORTED,NOSEQCK                   
  JOINKEYS F2=INB,FIELDS=(1,2,A),SORTED,NOSEQCK                   
  JOIN UNPAIRED                                                   
  REFORMAT FIELDS=(F1:001,305,                    $ FILE-1 RECORD 
                   F2:001,205,                    $ FILE-2 RECORD 
                   ?)                             $ MATCH IND     
                                                                   
  INREC IFOUTLEN=510,                                             
  IFTHEN=(WHEN=(511,1,CH,EQ,C'2'),                                 
         BUILD=(001:306,05,                                       
                306:311,200))                                     
/*                                                                 
//JNF1CNTL DD *                                                   
  INREC IFTHEN=(WHEN=(1,5,CH,EQ,C'111'),                           
         BUILD=(C'F1',C'AAA',1,300)),                             
         IFTHEN=(WHEN=NONE,                                       
         BUILD=(C'F1',C'ZZZ',1,300))                               
/*                                                                 
//JNF2CNTL DD *                                                   
  INREC IFTHEN=(WHEN=(1,5,CH,EQ,C'111'),                           
         BUILD=(C'F2',C'BBB',1,200)),                             
         IFTHEN=(WHEN=NONE,                                       
         BUILD=(C'F2',C'ZZZ',1,200))                               
/*                 

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group