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 

Merge 2 files unconditionally

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


Joined: 15 Jan 2016
Posts: 20
Topics: 7

PostPosted: Tue Jan 19, 2016 5:12 am    Post subject: Merge 2 files unconditionally Reply with quote

Hi,
I have 1 input file (A) with 2 dates (1 record) and another file (B) with 2M records.
I just want to copy (merge) A into file B (creating sysout (C))
eg :

Code:
2016-01-01 2016-01-31 (A)

Code:
record1 ..... abcdefghij ...(B)
record2 ..... abcdefghij ...(B)
record3 ..... abcdefghij ...(B)


Output (C) =
Code:
record1 ..... abcdefghij ...2016-01-01 2016-01-31
record2 ..... abcdefghij ...2016-01-01 2016-01-31
record3 ..... abcdefghij ...2016-01-01 2016-01-31


I can't get it right with dfsort and joinkeys. any suggestions?
Thanks.
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Tue Jan 19, 2016 5:52 am    Post subject: Reply with quote

JOINKEYS is a resource-hungry way to do it. In the JNFnCNTL files you temporarily extend the records to include a one-byte "key", on both files, all records, with the same value.

You specify the key on both the JOINKEYS (at least you can add SORTED and NOSEQCK) and you get a "cartesian join", each record on F1 is matched to each (which happens to be the only) record on F2, and you can define your final output on the REFORMAT statement.

You could also define separate values on the two files, the lower value on the single-record file, and use JOIN UNPAIRED,ONLY and then identify the unmatched F2 (use the match-marker, a "?" in the REFORMAT statement) with WHEN=GROUP and PUSH the data you need from the reformat record to all records in the position you want.

The resource efficient way to do it is a two-step solution.

First step, use SORT to format the single-record file as a DFSORT symbol, fixed-length of 80 bytes is important.

Second step, include the dataset created above as a SYMNAMES DD. Good to always include a SYMNOUNT DD going to SYSOUT.

Then your SORTIN is the actual data, and you use INREC OVERLAY/BUILD to include the data, by using the symbol-name, on all your records.
Back to top
View user's profile Send private message
Gerd Hofmans
Beginner


Joined: 15 Jan 2016
Posts: 20
Topics: 7

PostPosted: Tue Jan 19, 2016 6:02 am    Post subject: Reply with quote

Thanks Bill !! sounds good Smile
Back to top
View user's profile Send private message
Gerd Hofmans
Beginner


Joined: 15 Jan 2016
Posts: 20
Topics: 7

PostPosted: Tue Jan 19, 2016 8:57 am    Post subject: Reply with quote

where i read the date, and after finding the begin- and end date, i write all the symnames + dates into the file that i use in a second step to select certain records. Works perfect! thanks for the hint on the symnames file.
Cheers, Gerd.
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: Tue Jan 19, 2016 10:17 am    Post subject: Reply with quote

Gerd Hofmans wrote:
where i read the date, and after finding the begin- and end date, i write all the symnames + dates into the file that i use in a second step to select certain records. Works perfect! thanks for the hint on the symnames file.
Cheers, Gerd.


Glad you got it working. However you do remember that if you ever have more than 1 record in your date file you may need to generate symbols numbering them.

As for 2 steps about finding the begin dates and end dates you probably could everything done in a single step itself.

If you post your detailed Final requirement, I may show you a way to do it.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Gerd Hofmans
Beginner


Joined: 15 Jan 2016
Posts: 20
Topics: 7

PostPosted: Wed Jan 20, 2016 1:54 am    Post subject: Reply with quote

Code:
//S81      EXEC DFSORT                                                 
//SORTIN     DD *                                                     
20160119                                                               
//SORTOUT    DD DISP=SHR,DSN=X.XXXXX.DATE1                           
//SYSIN      DD *                                                     
 SORT FIELDS=COPY                                                     
 INREC IFTHEN=(WHEN=INIT,                                             
                   OVERLAY=(81:1,8,Y4T(-),                             
                            93:1,4,C'-01-01',                         
                           117:1,8,Y4T,SUBMONS,+1,TOGREG=Y4T)),       
       IFTHEN=(WHEN=(86,2,ZD,EQ,1),                                   
                   OVERLAY=(93:81,4,ZD,SUB,+1,EDIT=(TTTT),C'-01-01',   
                           150:81,4,ZD,SUB,+1,EDIT=(TTTT),C'-12-31')),
       IFTHEN=(WHEN=NONE,                                             
                   OVERLAY=(150:117,8,Y4T,LASTDAYM,TOGREG=Y4T(-)))     
*                                                                     
 OUTFIL OUTREC=(1:C'DA1;',C'C''',81,10,C'''',/,                       
                1:C'DA2;',C'C''',93,10,C'''',/,                       
                1:C'DA3;',C'C''',150,10,C'''',/,                       
                1:C'COUNTRY;44,10,CH',/,                               
                1:C'INFONET;54,10,CH',/,                               
                1:C'PSPO;114,8,CH',/,           
                1:C'DUITVDATE;222,10,CH',/,                           
                1:C'NUMBER_1;296,20,SFF',/,     
                1:C'LACCNUM001;316,34,CH',/,   
                1:C'NATOP;350,3,CH',                     
               80:X)                                     
/*                                                       
//S82      EXEC DFSORT                                   
//SORTIN     DD DISP=SHR,DSN=XXXX.XXXXX.XXXXX
//SYMNAMES   DD DISP=SHR,DSN=X.XXXXX.DATE1               
//SYMNOUT    DD SYSOUT=X                                 
//SORTOUT    DD DISP=SHR,DSN=X.XXXXX.OUT
//SORTMSG    DD SYSOUT=X                                 
//SYSIN      DD *                                         
 SORT FIELDS=COPY                                         
 INCLUDE COND=(DUITVDATE,GE,DA2,AND,DUITVDATE,LE,DA3,AND,
               INFONET,EQ,C'ZS',AND,                     
               COUNTRY,EQ,C'BE',AND,                     
              (NATOP,EQ,C'RBT',OR,NATOP,EQ,C'SCR'))       
*                                                         
 OUTFIL OUTREC=(1:PSPO,                                   
               54:LACCNUM001,                                                           
              181:NUMBER_1,TO=PD,LENGTH=9,               
              211:X)             
/*
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: Wed Jan 20, 2016 11:29 am    Post subject: Reply with quote

Gerd Hofmans,

You really don't need to do all that calculations to find the begin and end dates. All you need to do is simply subtract the Days from the date and you would automatically get the last month's end date.

So if the input date is January 19th then simply subtract 19 days from January 19th you would get December 31st of last year. All you need to check is if the input date is a valid one or not. This valid date check can be done using any of DFSORT date functions (TOGREG, TOJUL...). This formula works for any date in the calendar. By doing so you don't have to check if the month is january or not.

You also don't need the semicolons after the constants DA1,2,3. You can simply concatenate your fixed symbols instream.

Here is the JCL to calculate the begin and end dates. I also put in additional checks to set a return code if the input date is an invalid date or an empty file and we are only looking at the first record.

Code:

//STEP0100 EXEC PGM=SORT                                       
//SYSOUT   DD SYSOUT=*                                         
//SORTIN   DD *                                                 
20160314                                                       
20160119                                                       
//SORTOUT  DD SYSOUT=*                                         
//SYSIN    DD *                                                 
  OPTION COPY                                                   
  OPTION COPY,STOPAFT=1,NULLOUT=RC4                           
                                                             
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,8,Y4T,TOGREG=Y4T)),       
                                                             
  IFTHEN=(WHEN=(1,1,CH,NE,C'*'),                             
       OVERLAY=(15:1,8,Y4T,SUBDAYS,7,2,ZD,TOGREG=Y4T(-),     
                27:15,4,C'-01-01'))                           
                                                             
  OUTFIL NULLOFL=RC4,OMIT=(1,1,CH,EQ,C'*'),                   
         BUILD=(C'DA1,C''',01,04,C'-',5,2,C'-',7,2,C'''',/,   
                C'DA2,C''',27,10,C'''',/,                     
                C'DA3,C''',15,10,C'''',                       
                80:X)                                         
//*


In the second step you can have condition code to skip the step if above step returns rc of 4
Code:

//S82      EXEC PGM=SORT,COND=(4,EQ,STEP0100)     


And as for constant symbols you are better off having it concatenated like this

Code:

//SYMNAMES   DD DISP=SHR,DSN=X.XXXXX.DATE1   
//                   DD *
COUNTRY;44,10,CH     
INFONET;54,10,CH     
PSPO;114,8,CH       
DUITVDATE;222,10,CH 
NUMBER_1;296,20,SFF 
LACCNUM001;316,34,CH
NATOP;350,3,CH     

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Gerd Hofmans
Beginner


Joined: 15 Jan 2016
Posts: 20
Topics: 7

PostPosted: Thu Jan 21, 2016 2:02 am    Post subject: Reply with quote

Dear kolusu,
Many thanks for your reply.
It's a very convenient way of learning to become better in DFSORT.
Kind Regards, Gerd.
Back to top
View user's profile Send private message
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