How to Merge records in 2 ps files alternately into 3rd?



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

How to Merge records in 2 ps files alternately into 3rd?

Postby skankatala » Sun Jan 08, 2012 11:29 am

I have 2 ps files.

I want to copy records from both files into another file alternatively.

FILE1:
RECORD1
RECORD2
RECORD3


File2
RECORD4
RECORD5
RECORD6



Output file should be
RECORD1
RECORD4
RECORD2
RECORD5
RECORD3
RECORD6


Please let me know how to do it?
skankatala
 
Posts: 42
Joined: Sun Dec 11, 2011 9:45 am
Location: Hyderabad
Has thanked: 0 time
Been thanked: 0 time

Re: How to Merge records in 2 ps files alternately into 3rd?

Postby dick scherrer » Sun Jan 08, 2012 12:14 pm

Hello,

One way will be to use the sort product in use on your system.

Generate an odd/even sequence number for all of the records in each file (file 1 = 1,3,5,etc, file 2 = 2,4,6,etc). and sort or merge the data by the sequence number. When the final output is written, the sequence number can be discarded.

I suspect there is a more elegant solution, but i'm about to hit the road . . .

Good luck :)
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: How to Merge records in 2 ps files alternately into 3rd?

Postby BillyBoyo » Sun Jan 08, 2012 2:01 pm

If you want to do it in a program:
read file 1
write output
read file 2
write output
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: How to Merge records in 2 ps files alternately into 3rd?

Postby skankatala » Sun Jan 08, 2012 2:07 pm

I want to do it in JCl. Is it possible?
skankatala
 
Posts: 42
Joined: Sun Dec 11, 2011 9:45 am
Location: Hyderabad
Has thanked: 0 time
Been thanked: 0 time

Re: How to Merge records in 2 ps files alternately into 3rd?

Postby BillyBoyo » Sun Jan 08, 2012 2:17 pm

No, JCL can't do anything itself as far as data manipulation is concerned.

If you want to do it without writing a program, the you use a program called, generally, a "utility".

If you don't want to write a program, the best program to use is probably SORT, as Dick suggested above.

What Sort product do you use? DFSORT (ICE messages) or Syncsort (WER messages)?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: How to Merge records in 2 ps files alternately into 3rd?

Postby skankatala » Sun Jan 08, 2012 2:39 pm

We use DFSORT.
skankatala
 
Posts: 42
Joined: Sun Dec 11, 2011 9:45 am
Location: Hyderabad
Has thanked: 0 time
Been thanked: 0 time

Re: How to Merge records in 2 ps files alternately into 3rd?

Postby BillyBoyo » Sun Jan 08, 2012 7:12 pm

You can try the following.

//INTERLVE EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN01 DD *
RECORD1
RECORD2
RECORD3
//SORTIN02 DD *
RECORD4
RECORD5
RECORD6
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
  INREC BUILD=(1,7,X,SEQNUM,7,ZD)
  MERGE FIELDS=(9,7,CH,A),NOEQUALS
  OUTREC BUILD=(1,7)



The INREC BUILD includes your data, a fill character X (which by default is a space) just so you can see the two fields, then a sequence number. The MERGE is carried out using the assigned sequence number as the control field. NOEQUALS is specified because your keys are a generated sequence number so can never be equal. The OUTREC BUILD drops of the sequence number which was added before the MERGE itself.

If you want to see the sequence number, comment out the OUTREC BUILD (* in column 1). If you have any questions about the operations, please first consult the DFSORT manuals and then ask here, explaing what it is that you do not understand.

This is also possible with the MERGE operator of ICETOOL. You might want to look at that, just to get you a start with ICETOOL as well.

The
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: How to Merge records in 2 ps files alternately into 3rd?

Postby BillyBoyo » Mon Jan 09, 2012 3:21 am

This has been nagging at me. Replace the first BUILD in my example with the OVERLAY below.

  INREC OVERLAY=(9:X,SEQNUM,7,ZD)


This is a more logical representation of what you are doing, extending the record.

Remember, I put the X there just so you get a seperation if you want to view the sequence number to help follow what is going on. It is not needed in your final version.

You can make the ZD a PD instead. Because it is a merge and no record extensions will be held on sortwork areas, it is not going to make much of a difference.

For this particular task, the SEQNUM need only be length 1 for the above to work, but that would be the type of thing which makes people wonder about the code. If you want to do that, document it.

This leads to the point that you don't have to worry about a maximum size for the SEQNUM, as the processing will still work if the sequence number rolls over. Document it that way.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: How to Merge records in 2 ps files alternately into 3rd?

Postby BillyBoyo » Mon Jan 09, 2012 4:38 am

Just one more thing. Here's he same code, but written in a different way.

//INTERLVE EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SYMNAMES DD *
INPUT-RECORD,*,8,CH
COLUMN-AFTER-INPUT-RECORD,*,1,CH
BLANK-INSERTED-FOR-VIEWING-ONLY,=,1,CH
MERGE-SEQNO-IN-EXTENSION,*,7,CH
//SYMNOUT DD SYSOUT=*
//SORTIN01 DD *
RECORD1
RECORD2
RECORD3
//SORTIN02 DD *
RECORD4
RECORD5
RECORD6
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
                                                         
  INREC OVERLAY=(COLUMN-AFTER-INPUT-RECORD:X,SEQNUM,7,ZD)
                                                         
  MERGE FIELDS=(MERGE-SEQNO-IN-EXTENSION,A),NOEQUALS
                                                         
  OUTREC BUILD=(INPUT-RECORD)
                                                         
//*


If you look at the sort cards, you'll see that they now have "named" fields. These are DFSORT Symbols, defined under the SYMNAMES DD statement.

The position, length and type of the named symbols are converted by DFSORT to the traditional method of specification, which is listed along with the rest of the output, like this:

  INREC OVERLAY=(9:X,SEQNUM,7,ZD)   
  MERGE FIELDS=(10,7,CH,A),NOEQUALS
  OUTREC BUILD=(1,8)               


The * in the defintions means use the next available byte position (so for the first definition, that will be 1). The = means use the start position of the previously defined field. Fields can also be defined at an explicit starting position, This-Field,20,4,CH

The translation of your symbols from the above appears as output on the SYMNOUT dd statement:

------- ORIGINAL STATEMENTS FROM SYMNAMES -------
INPUT-RECORD,*,8,CH                             
COLUMN-AFTER-INPUT-RECORD,*,1,CH                 
BLANK-INSERTED-FOR-VIEWING-ONLY,=,1,CH           
MERGE-SEQNO-IN-EXTENSION,*,7,CH                 
                                                 
------------------ SYMBOL TABLE -----------------
INPUT-RECORD,1,8,CH                             
COLUMN-AFTER-INPUT-RECORD,9,1,CH                 
BLANK-INSERTED-FOR-VIEWING-ONLY,9,1,CH           
MERGE-SEQNO-IN-EXTENSION,10,7,CH                 


If you are new to sorting, you might want to consider using the symbols. They are well-documented, with examples, in the manuals. There is a program written in rexx which is available from IBM's DFSORT team which will generate symbols from a Cobol copybook, so that you can use the same names as in a Cobol program.

Symbols help to document; make it more difficult to get the wrong definition of a field; make the code more maintainable (there might be several references to one field, which in the traditional way would have to be changed, correctly, in each place - with symbols, you just change the definition); allow for easy extension of records without having to constantly count how many bytes are in the original record; etc, etc.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: How to Merge records in 2 ps files alternately into 3rd?

Postby skankatala » Mon Jan 09, 2012 8:20 am

Hi Billy.......

:D :D This code helped me. Thank you so much to you and the forum for giving prompt responses.... :D :D
skankatala
 
Posts: 42
Joined: Sun Dec 11, 2011 9:45 am
Location: Hyderabad
Has thanked: 0 time
Been thanked: 0 time

Next

Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post