Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Header and trailer for each record in SORTOUT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
rammraju

New User


Joined: 05 Mar 2005
Posts: 65
Location: Hyderabad

PostPosted: Fri Aug 22, 2008 10:35 am    Post subject: Header and trailer for each record in SORTOUT
Reply with quote

Hi all,
My input file looks like
Code:
Rec1
Rec2
Rec3
.
.

I am trying to prepare a output file which looks the below way

Code:
Header
Rec1
Trailer
Header
Rec2
Trailer
Header
Rec3
Trailer
.
.


The header and trailer needs to repeat for all the records.

Can someone please let me know if it can be done with DFSORT, if so how?

Thanks in advance,
Back to top
View user's profile Send private message

Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2180
Location: @my desk

PostPosted: Fri Aug 22, 2008 12:07 pm    Post subject:
Reply with quote

Ram,

This can be done using the below DFSORT job.
I have assumed an FB file of LRECL=80. You can modify it as per your file attributes.

Code:
//STEP01   EXEC PGM=SORT                     
//SYSOUT   DD SYSOUT=*                       
//SORTOUT  DD SYSOUT=*                       
//SORTIN   DD *                             
Rec1                                         
Rec2                                         
Rec3                                         
//SYSIN    DD *                             
 OPTION COPY                                 
 OUTFIL BUILD=(C'Header',/,1,80,/,C'Trailer')


SORTOUT
Code:
Header
Rec1   
Trailer
Header
Rec2   
Trailer
Header
Rec3   
Trailer


Thanks,
Arun
Back to top
View user's profile Send private message
rammraju

New User


Joined: 05 Mar 2005
Posts: 65
Location: Hyderabad

PostPosted: Wed Aug 27, 2008 1:21 am    Post subject: Reply to: Header and trailer for each record in SORTOUT
Reply with quote

Thank you very much Arun,
This helps if the Header and Trailer are small (having less characters), what if the Header/Trailer is a record of say 100 characters long and has multiple lines.

Ex:

Code:
HeaderLin1.....
HeaderLin2.....
HeaderLin3.....
Rec1.....
TrailerLin1.....
TrailerLin2.....
HeaderLin1.....
HeaderLin2.....
HeaderLin3.....
Rec2.....
TrailerLin1.....
TrailerLin2.....
HeaderLin1.....
HeaderLin2.....
HeaderLin3.....
Rec3.....
TrailerLin1.....
TrailerLin2.....
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Wed Aug 27, 2008 1:59 am    Post subject:
Reply with quote

Quote:
what if the Header/Trailer is a record of say 100 characters long and has multiple lines.


The same technique can be used, but note that the Header and Trailers records CANNOT be longer than the LRECL. If you had Header/Trailer records of 100 characters, the LRECL would have to be at least 100. That said, you could do what you asked about like this:

Code:

//S1   EXEC PGM=SORT                     
//SYSOUT   DD SYSOUT=*                       
//SORTIN DD DSN=...  input file (FB/100)
//SORTOUT  DD DSN=...  output file (FB/100)   
//SYSIN    DD *                             
 OPTION COPY                                 
 OUTFIL BUILD=(C'HeaderLin1...',/,
   C'HeaderLin2...',
   C'HeaderLin3...',
    1,100,/,
   C'TrailerLin1...',/,
   C'TrailerLin2...')


Of course, with a 100 character string, you need to observe the rules for continuation of literals. You could either code each 100 character string as one literal - for example:

Code:

  OUTFIL BUILD=(C'H2345678901234567890123456789012345678901234567890123*
 45678901234567890123456789012345678901234567890',/,
  C'H234567890123456789012345678901234567890123456789012345678901234567*
 890123456789012345678901234567890',/,
 ...


with the continuation indicator (*) in column 72.

Or you could break the 100 character string into parts - for example:

Code:

  OUTFIL BUILD=(C'H2345678901234567890123456789012345678901234567890',
  C'12345678901234567890123456789012345678901234567890',/,
  C'H23456789012345678901234567890123456789012345678901234567890',
  C'1234567890123456789012345678901234567890',/,
  ...


Does that answer your question?
Back to top
View user's profile Send private message
rammraju

New User


Joined: 05 Mar 2005
Posts: 65
Location: Hyderabad

PostPosted: Wed Aug 27, 2008 2:06 am    Post subject: Reply to: Header and trailer for each record in SORTOUT
Reply with quote

Yes, this answers my question

I am curious to know if it is possible to read the Header and Trailer from two different files and prepare the same output.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Wed Aug 27, 2008 2:18 am    Post subject:
Reply with quote

Yes, you can do that by creating DFSORT Symbols for the needed strings that you can use in the OUTFIL BUILD operand.

If you want me to show you how, show an example of the record(s) in the Header file, and the record(s) in the Trailer file and identify the starting position and length of the string(s) you want to use. Also, give the RECFM and LRECL of the Header file, the Trailer file and the Data file.
Back to top
View user's profile Send private message
rammraju

New User


Joined: 05 Mar 2005
Posts: 65
Location: Hyderabad

PostPosted: Wed Aug 27, 2008 6:14 am    Post subject: Reply to: Header and trailer for each record in SORTOUT
Reply with quote

Here is my requirement

Header file: (LRECL=80,RECFM=FB)
Code:
HHHHHHHHHHHHHH......
EEEEEEEEEEEEEE......
AAAAAAAAAAAAAA......
DDDDDDDDDDDDDD......


Trailer file: (LRECL=80,RECFM=FB)
Code:
TTTTTTTTTTTTTT......
AAAAAAAAAAAAAA......
IIIIIIIIIIIIII......
LLLLLLLLLLLLLL......


Data file: (LRECL=80,RECFM=FB)
Code:
RECORD1
RECORD2
RECORD3
.
.
.


The output should look as (LRECL=80,RECFM=80)
Code:
HHHHHHHHHHHHHH......
EEEEEEEEEEEEEE......
AAAAAAAAAAAAAA......
DDDDDDDDDDDDDD......
RECORD1
TTTTTTTTTTTTTT......
AAAAAAAAAAAAAA......
IIIIIIIIIIIIII......
LLLLLLLLLLLLLL......
HHHHHHHHHHHHHH......
EEEEEEEEEEEEEE......
AAAAAAAAAAAAAA......
DDDDDDDDDDDDDD......
RECORD2
TTTTTTTTTTTTTT......
AAAAAAAAAAAAAA......
IIIIIIIIIIIIII......
LLLLLLLLLLLLLL......
HHHHHHHHHHHHHH......
EEEEEEEEEEEEEE......
AAAAAAAAAAAAAA......
DDDDDDDDDDDDDD......
RECORD3
TTTTTTTTTTTTTT......
AAAAAAAAAAAAAA......
IIIIIIIIIIIIII......
LLLLLLLLLLLLLL......
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1288
Location: Chennai, India

PostPosted: Wed Aug 27, 2008 12:10 pm    Post subject: Reply to: Header and trailer for each record in SORTOUT
Reply with quote

Techies,

Can SYMNAMES be used for creating DFSORT symbols from more than one input record?

For the above requirement Can we use the input header file and create 4 DFSORT symbols for all the 4 header records in the input file?
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2180
Location: @my desk

PostPosted: Wed Aug 27, 2008 6:37 pm    Post subject:
Reply with quote

Ram,

Can you try out this job.

Code:
//STEP1    EXEC PGM=ICETOOL                               
//TOOLMSG  DD SYSOUT=*                                     
//DFSMSG   DD SYSOUT=*                                     
//C1       DD DSN=&&C1,DISP=(,PASS),DCB=(RECFM=FB,LRECL=80)
//C2       DD DSN=&&C2,DISP=(,PASS),DCB=(RECFM=FB,LRECL=80)
//S1       DD DSN=&&S1,DISP=(,PASS),DCB=(RECFM=FB,LRECL=80)
//S2       DD DSN=&&S2,DISP=(,PASS),DCB=(RECFM=FB,LRECL=80)
//H1       DD DSN=Header.file...................
//H1       DD DSN=Trailer.file..................
//TOOLIN   DD *                                           
 COPY FROM(H1) USING(CTL1)                                         
 COPY FROM(T1) USING(CTL2)                                         
//CTL1CNTL DD *                                                     
  OPTION COPY                                                       
  OUTFIL FNAMES=S1,BUILD=(C'H',SEQNUM,2,ZD,C',''',1,73,C'''',80:X) 
  OUTFIL FNAMES=C1,                                                 
         IFTHEN=(WHEN=INIT,                                         
                 BUILD=(16X,C'H',SEQNUM,2,ZD,C',/,',80:X),HIT=NEXT),
         IFTHEN=(WHEN=(18,2,ZD,EQ,1),                               
                 OVERLAY=(2X,C'OUTFIL BUILD=(',80:X)),REMOVECC,     
  HEADER1=(2X,C'OPTION COPY'),                                     
  TRAILER1=(15X,16:C'1,80,/,')                                     
/*                                                                 
//CTL2CNTL DD *                                                     
  OPTION COPY                                                       
  OUTFIL FNAMES=S2,BUILD=(C'T',SEQNUM,2,ZD,C',''',1,73,C'''',80:X) 
  OUTFIL FNAMES=C2,                                                 
         IFTHEN=(WHEN=INIT,                                         
                 BUILD=(16X,C'T',SEQNUM,2,ZD,C',/,',80:X)),         
         IFTHEN=(WHEN=(18,2,ZD,EQ,4),                               
                 OVERLAY=(20:C')  ',80:X))
/*                                       
//STEP2    EXEC PGM=SORT                 
//SYSOUT   DD SYSOUT=*                   
//SORTOUT  DD SYSOUT=*                   
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)   
//         DD DSN=&&S2,DISP=(OLD,PASS)   
//SORTIN   DD DSN=Input.file............................                 
//SYSIN    DD DSN=&&C1,DISP=(OLD,PASS)   
//         DD DSN=&&C2,DISP=(OLD,PASS)   


But this job requires you to give the number of trailer records in CTL2CNTL - IFTHEN=(WHEN=(18,2,ZD,EQ,4). And as the SYMNAMES dataset requires an LRECL of 80,FB, this approach imposes a limit on the header/trailer length you can have. icon_sad.gif

Frank,
Waiting for your expert solution..... icon_smile.gif

Thanks,
Arun
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Wed Aug 27, 2008 10:13 pm    Post subject:
Reply with quote

Ram,

Here's a DFSORT/ICETOOL job that will do what you asked for. Note that since the limit for a symbol constant is 64 characters, we have to break up each 80 character header/trailer line into two symbols of 40 characters each.

Code:

//S1   EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//HD DD *
HHHHHHHHHHHHHH......
EEEEEEEEEEEEEE......
AAAAAAAAAAAAAA......
DDDDDDDDDDDDDD......
/*
//TR DD *
TTTTTTTTTTTTTT......
AAAAAAAAAAAAAA......
IIIIIIIIIIIIII......
LLLLLLLLLLLLLL......
/*
//HDSYM DD DSN=&&HS,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//TRSYM DD DSN=&&TS,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD SYSOUT=*
//TOOLIN DD *
COPY FROM(HD) USING(CTL1)
COPY FROM(TR) USING(CTL2)
/*
//CTL1CNTL DD *
  OUTFIL FNAMES=HDSYM,
    BUILD=(C'HA',SEQNUM,1,ZD,C',''',1,40,C'''',80:X,/,
           C'HB',SEQNUM,1,ZD,C',''',41,40,C'''')
/*
//CTL2CNTL DD *
  OUTFIL FNAMES=TRSYM,
    BUILD=(C'TA',SEQNUM,1,ZD,C',''',1,40,C'''',80:X,/,
           C'TB',SEQNUM,1,ZD,C',''',41,40,C'''')
/*
//S2   EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SYMNAMES DD DSN=&&HS,DISP=(OLD,PASS)
//         DD DSN=&&TS,DISP=(OLD,PASS)
//SORTIN DD DSN=...  input file (FB/80)
//SORTOUT  DD DSN=...  output file (FB/80)
//SYSIN    DD *
 OPTION COPY
 OUTFIL BUILD=(HA1,HB1,/,HA2,HB2,/,HA3,HB3,/,HA4,HB4,/,
    1,80,/,
  TA1,TB1,/,TA2,TB2,/,TA3,TB3,/,TA4,TB4)
/*
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1288
Location: Chennai, India

PostPosted: Thu Aug 28, 2008 11:38 am    Post subject: Reply to: Header and trailer for each record in SORTOUT
Reply with quote

Arun,

Code:
//H1       DD DSN=Trailer.file..................


Is that a typo? I guess the DD name should be T1 instead of H1.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2180
Location: @my desk

PostPosted: Thu Aug 28, 2008 12:59 pm    Post subject:
Reply with quote

Aaru,
Quote:
Is that a typo? I guess the DD name should be T1 instead of H1.

Yes it is............ icon_cry.gif

Thanks,
Arun
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1288
Location: Chennai, India

PostPosted: Thu Aug 28, 2008 1:54 pm    Post subject: Reply to: Header and trailer for each record in SORTOUT
Reply with quote

Arun,

Quote:
Yes it is............


Ok. I had pointed it out so that OP is not confused. Else, he would come back saying that the posted JCL is not working.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2180
Location: @my desk

PostPosted: Thu Aug 28, 2008 3:17 pm    Post subject:
Reply with quote

Ram,

Please try the below JCL. I have taken care of the limitations of my previous JCL. You dont need to know the number of header/trailer records

Code:
//STEP1    EXEC PGM=ICETOOL                                     
//TOOLMSG  DD SYSOUT=*                                           
//DFSMSG   DD SYSOUT=*                                           
//C1       DD DSN=&&C1,DISP=(MOD,PASS),DCB=(RECFM=FB,LRECL=80)   
//C2       DD DSN=&&C2,DISP=(,PASS),DCB=(RECFM=FB,LRECL=80)     
//S1       DD DSN=&&S1,DISP=(MOD,PASS),DCB=(RECFM=FB,LRECL=80)   
//H1       DD DSN=header-file.............FB,LRECL=80           
//T1       DD DSN=trailer-file............FB,LRECL=80           
//TOOLIN   DD *                                                 
 COPY FROM(H1) USING(CTL1)                                       
 COPY FROM(T1) USING(CTL2)                                       
 SPLICE FROM(C2) TO(C1) ON(24,2,ZD) WITH(26,3) WITHALL KEEPNODUPS
//CTL1CNTL DD *                                                 
  OPTION COPY                                                   
  OUTFIL FNAMES=S1,                                             
         BUILD=(C'HA',SEQNUM,2,ZD,C',''',1,40,C'''',80:X,/,     
                C'HB',SEQNUM,2,ZD,C',''',41,40,C'''')           
  OUTFIL FNAMES=C1,IFOUTLEN=80,                                 
         IFTHEN=(WHEN=INIT,                                     
                 BUILD=(16X,C'HA',SEQNUM,2,ZD,                   
                            C',HB',SEQNUM,2,ZD,C',/,'),HIT=NEXT),
         IFTHEN=(WHEN=(19,2,ZD,EQ,1),                           
                 OVERLAY=(2X,C'OUTFIL BUILD=(')),REMOVECC,       
  HEADER1=(2X,C'OPTION COPY'),                                   
  TRAILER1=(16X,C'1,80,/,')                                     
/*                                                               
//CTL2CNTL DD *                                                 
  OPTION COPY                                                   
  OUTFIL FNAMES=S1,                                             
         BUILD=(C'TA',SEQNUM,2,ZD,C',''',1,40,C'''',80:X,/,     
                C'TB',SEQNUM,2,ZD,C',''',41,40,C'''')           
  OUTFIL FNAMES=C2,IFOUTLEN=80,                                 
         IFTHEN=(WHEN=INIT,                                     
                 BUILD=(16X,C'TA',SEQNUM,2,ZD,                   
                            C',TB',SEQNUM,2,ZD,C',/,')),REMOVECC,
  TRAILER1=(23X,COUNT=(M11,LENGTH=2),')  ')                     
/*                                                               
//STEP2    EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                   
//SORTOUT  DD SYSOUT=*                                   
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)                   
//SYSIN    DD DSN=&&C1,DISP=(OLD,PASS)                   
//SORTIN   DD DSN=input-file..............FB,LRECL=80     


Aaru,
I corrected my typo too icon_lol.gif

Thanks,
Arun
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts sort with previous record anatol DFSORT/ICETOOL 9 Thu Oct 06, 2016 2:36 am
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm
No new posts Change date (DD/MM/YY) in 2nd record ... uday kiran DFSORT/ICETOOL 12 Wed Sep 07, 2016 10:57 pm
No new posts Using 'parm' to vary SORTOUT record v... Sysaron DFSORT/ICETOOL 13 Wed Sep 07, 2016 9:24 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us