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 

Inserting records thru SORT

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


Joined: 13 May 2003
Posts: 18
Topics: 9
Location: Indore,India

PostPosted: Tue Mar 09, 2004 12:18 pm    Post subject: Inserting records thru SORT Reply with quote

Hi,

I have following 2 FB datasets:

File1:
aaaaaaaa
bbbbbbbb
ccccccccc

File2:
*******

I want to insert File2 record in File1 such that the output is:

*******
aaaaaaaa
*******
bbbbbbbb
*******
ccccccccc

I tried using file2 record as header but it did not work. Pls. let me know if I can do it thru SORT.......

Thanks !!!!
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Tue Mar 09, 2004 12:25 pm    Post subject: Reply with quote

Is the record in File2 always just one record with ******* or can it change to something else?
_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Prayank
Beginner


Joined: 13 May 2003
Posts: 18
Topics: 9
Location: Indore,India

PostPosted: Tue Mar 09, 2004 1:41 pm    Post subject: Reply with quote

Hi Frank,

The record in file 2 is constant. We can do away with file2 and use that as a string in our sort.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Mar 09, 2004 1:42 pm    Post subject: Reply with quote

prayank,

The following DFSORT/ICETOOL Jcl will give you the desired results. If you have syncsort at your shop then change the pgm to synctool.

I assumed that both input1 and input2 are of 80 byte and fb recfm.

The first copy operator takes in in1 file and creates a dynamic sort control card as follows.
Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 OUTFIL FNAMES=OUT,                                                         
 OUTREC=(C'****************                        ',                  X     
         C'                                        ',/,1,80)               


The second operator takes the above created control card and creates the desired output.

Code:

//STEP0100 EXEC PGM=ICETOOL                                 
//TOOLMSG   DD SYSOUT=*                                     
//DFSMSG    DD SYSOUT=*                                     
//OUT       DD SYSOUT=*                                     
//IN1       DD *                                             
****************                                             
//IN2       DD *                                             
AAAAAAAA                                                     
BBBBBBBB                                                     
CCCCCCCC                                                     
//TOOLIN    DD *                                             
  COPY FROM(IN1) USING(CTL1)                                 
  COPY FROM(IN2) USING(CTL2)                                 
//CTL1CNTL  DD *                                             
  OPTION STOPAFT=1                    $ COPY ONLY 1 REC               
  OUTFIL FNAMES=CTL2CNTL,             $ OUTFIL FILE NAME               
  OUTREC=(C' OUTFIL FNAMES=OUT,',/,   $ ACTUAL OUT FILE NAME           
          C' OUTREC=(',               $ CONSTANT OUTREC=(             
          C'C',                       $ CONSTANT C                     
          X'7D',                      $ OPENING QUOTE IN HEX           
          1,40,                       $ FIRST 40 BYTES OF IN1 REC     
          X'7D',                      $ CLOSING QUOTE IN HEX           
          C',',                       $ COMMA                         
          72:C'X',                    $ CONTINUATION MARK IN POS 72   
          /,                          $ BREAK INTO NEW LINE           
          9X,                         $ 9 SPACES                       
          C'C',                       $ CONSTANT C                     
          X'7D',                      $ OPENING QUOTE IN HEX           
          41,40,                      $ NEXT 40 BYTES OF IN1 REC       
          X'7D',                      $ CLOSING QUOTE IN HEX           
          C',/,1,80)',                $ BREAK INTO NEW REC WITH IN2-REC
          80:X)                       $ PAD SPACES                     
//CTL2CNTL  DD DSN=&T1,DISP=(,PASS),SPACE=(TRK,(1,1),RLSE)             
/*                                                                   


Hope this helps...

Cheers

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


Joined: 13 May 2003
Posts: 18
Topics: 9
Location: Indore,India

PostPosted: Tue Mar 09, 2004 1:58 pm    Post subject: Reply with quote

Hi Kolusu,

Your JCL worked well. Thanks for that. But I was not able to understand how it works. It would be great if you can elaborate a little on the logic of this JCL.

Thanks....

Prayank
Back to top
View user's profile Send private message
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Tue Mar 09, 2004 2:39 pm    Post subject: Reply with quote

If the record in the second file is going to be constant, then you do not really need the second file (as you mention).
Code:

//STEP     EXEC PGM=SORT             
//SYSIN    DD *                       
 OPTION COPY                         
 OUTFIL OUTREC=(C'**********',80:X,/,
                1,80)                 
/*                                   
//SORTIN   DD *                       
----+----1----+----2
AAAAAAA                               
BBBBBBBBBBB                           
CCCC                                 
/*                                   
//SORTOUT  DD SYSOUT=*               
//SYSOUT   DD SYSOUT=*               


The output is:

---+----1----+----2
**********         
AAAAAAA           
**********         
BBBBBBBBBBB       
**********         
CCCC               


The slash in OUTFIL OUTREC splits an input record into two. The first has "hardcoded" string of stars and the second record has the first 80 bytes of the first file (as in your first post).
_________________
ALL opinions are welcome.

Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Mar 09, 2004 2:53 pm    Post subject: Reply with quote

prayank,

There is no complicated logic in the solution. Let me try to explain with a simple example.

Let us say you want to add a constant 'prayank' to input records at pos1. Let us say your input file is like this.Input file has 80 bytes lrecl and is fb recfm.

INPUT FILE1:
Code:

ABCD
DEFG
HIJK


you want the output as follows:

OUTPUT:
Code:

PRAYANK ABCD
PRAYANK DEFG
PRAYANK HIJK



To achieve this you will code the following sort control cards
Code:

 SORT FIELDS=COPY
 OUTREC FIELDS=(C'PRAYANK ',       $ CONSTANT PRAYANK IN POS 1
                1,80)              $ COPY THE INPUT REC AS IS


But if we wanted the output in the following manner
Code:

PRAYANK
ABCD
PRAYANK
DEFG
PRAYANK
HIJK


we use the "/" symbol to start a new record.

Now your requirement is similar to the second output. so we are generating control cards similar to how you use regualarly code to add a constant.

We first take your constant file and create the dynamic control cards which will look as below.

Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 OUTFIL FNAMES=OUT,                                                         
 OUTREC=(C'****************                        ',                  X     
         C'                                        ',/,1,80)               


Now the second copy operator will take this as control cards with your actual(file1) and create the output.


Hope this helps you to understand the process here

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Tue Mar 09, 2004 3:22 pm    Post subject: Reply with quote

Here's a simple way to insert the string from the record using DFSORT Symbols:

Code:

//STEP1 EXEC PGM=ICEMAN
//SYSOUT    DD SYSOUT=*
//SORTIN    DD *
****************
/*
//SORTOUT DD DSN=&&S1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//SYSIN DD *
  OPTION COPY
* Create DFSORT Symbols statement:
* CON1,'string'
  OUTREC FIELDS=(C'CON1,''',1,40,C'''',80:X)
/*
//STEP2 EXEC PGM=ICEMAN
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)
//SYSOUT    DD SYSOUT=*
//SORTIN    DD *
AAAAAAAA
BBBBBBBB
CCCCCCCC
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
* Use CON1 symbol to insert a record before each input record
  OUTFIL OUTREC=(CON1,80:X,/,1,80)
/*

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Jul 07, 2004 3:58 am    Post subject: Reply with quote

Hi,

My requirement is a bit different. I need to insert a separator record (say a string of hyphens '---------------------') between a pair of records as shown below.

Code:

Input File:
1-DATA
2-DATA
1-DATA
1-DATA
2-DATA
2-DATA
2-DATA
2-DATA
2-DATA
1-DATA

Output File:
1-DATA
2-DATA
-------------------------
1-DATA
-------------------------
1-DATA
2-DATA
-------------------------
2-DATA
2-DATA
2-DATA
2-DATA
-------------------------
1-DATA
-------------------------


My requirement is that I need to scan for a PAIR of records (As shown above 1- & 2- form a pair) and insert a separator line after every 1 - 2 pairs. If a pair is not available say I have 5 '1-' records followed by a '2-' record, then the separator should be inserted after the 4th '1-' record (four '1-' records - SEPARATOR - '1- & 2-' Pair).

My input file is of length 80 (RECFM=FB). Can I do this using SORT ?

Kindly help,
Phantom
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