Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Excluding the last record for SORT operation in a file

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

New User


Joined: 27 Dec 2007
Posts: 73
Location: India

PostPosted: Wed Oct 08, 2008 2:20 pm    Post subject: Excluding the last record for SORT operation in a file
Reply with quote

Hi,
I have a file with below three records...

'2008-07-22.00.37.44.297630'
'2008-07-22.00.37.44.297631'
'2008-08-05.00.40.02.167578'

I need to write a new file like below

'2008-07-22.00.37.44.297630',
'2008-07-22.00.37.44.297631',
'2008-08-05.00.40.02.167578'

Here, I want the COMMA to be inserted at the end of first two records only. The last record should be left as is.
Back to top
View user's profile Send private message

gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1703
Location: Australia

PostPosted: Wed Oct 08, 2008 3:05 pm    Post subject:
Reply with quote

Hi,

here is one way of achieving it
Code:
//S1       EXEC PGM=ICETOOL                                             
//TOOLMSG  DD SYSOUT=*                                                 
//DFSMSG   DD SYSOUT=*                                                 
//IN       DD *                                                         
'2008-07-22.00.37.44.297630'                                           
'2008-07-22.00.37.44.297631'                                           
'2008-08-05.00.40.02.167578'                                           
//CTL2CNTL DD DSN=&&C1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)       
//         DD *                                                         
  OUTREC OVERLAY=(1,28,29:C',')                                         
//OUT      DD SYSOUT=*                                                 
//TOOLIN   DD *                                                         
COPY FROM(IN) USING(CTL1)                                               
COPY FROM(IN) TO(OUT) USING(CTL2)                                       
COPY FROM(IN) TO(OUT) USING(CTL3)                                       
/*                                                                     
//CTL1CNTL DD *                                                         
  OUTFIL FNAMES=CTL2CNTL,REMOVECC,NODETAIL,                             
    BUILD=(80X),                                                       
    TRAILER1=('  OPTION STOPAFT=',COUNT-1=(M11,LENGTH=8))               
/*     
//CTL3CNTL DD *                                                         
  OPTION COPY                                                           
  OUTFIL FNAMES=OUT,REMOVECC,NODETAIL,                                 
    TRAILER1=(1,80)                                                     
/*                                                                       


Gerry
Back to top
View user's profile Send private message
technut

New User


Joined: 27 Dec 2007
Posts: 73
Location: India

PostPosted: Wed Oct 08, 2008 4:06 pm    Post subject: Reply to: Excluding the last record for SORT operation in a
Reply with quote

Thanks a lot for responding.. I tried your option and it yielded below output..

'2008-07-22.00.37.44.297630',
'2008-07-22.00.37.44.297631',

The last line was omitted as a whole.. I want the last record to be present in the output with no COMMAs at the end..!

I have never used ICETOOL before... It could be my unawareness!..
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Oct 08, 2008 5:22 pm    Post subject:
Reply with quote

Here is icetool job for what you want to do

Code:

//STEP050  EXEC PGM=ICETOOL
//TOOLMSG  DD SYSOUT=*     
//DFSMSG    DD SYSOUT=*   
//IN   DD *                                                   
'2008-07-22.00.37.44.297630'                                 
'2008-07-22.00.37.44.297631'                                 
'2008-08-05.00.40.02.167578'                                 
/*                                                           
//TMP1 DD  DSN=&&TEMP1,DISP=(NEW,PASS),SPACE=(CYL,(1,10),RLSE)
//TMP2CNTL DD  DSN=&&TEMP2,                                   
//      DISP=(NEW,PASS),SPACE=(CYL,(1,10),RLSE)               
//OUT  DD  SYSOUT=*                                           
//TOOLIN   DD *                                               
  COPY FROM(IN) TO(TMP1) USING(CTL1)                         
  COPY FROM(TMP1) TO(TMP2CNTL) USING(CTL2)                   
  COPY FROM(TMP1) TO(OUT) USING(TMP2)                         
/*                                                           
//CTL1CNTL DD *                                               
  SORT FIELDS=COPY                                           
  INREC FIELDS=(1,28,29:C',',81:SEQNUM,8,ZD)                   
/*                                                             
//CTL2CNTL DD *                                               
  SORT FIELDS=COPY                                             
  OUTFIL FNAMES=TMP2CNTL,NODETAIL,REMOVECC,                   
  HEADER2=(3:'OPTION COPY'),                                   
  TRAILER2=(2X,                                               
  3:'OUTREC IFTHEN=(WHEN=(81,8,ZD,EQ,',COUNT=(EDIT=(TTTTTTTT)),       
  '),',/,                                                     
  3:'BUILD=(1,28,29:X)),',/,                                   
  3:'IFTHEN=(WHEN=NONE,BUILD=(1,29))')                         
/*                                                             

Output:
Code:

'2008-07-22.00.37.44.297630',
'2008-07-22.00.37.44.297631',
'2008-08-05.00.40.02.167578'
Back to top
View user's profile Send private message
technut

New User


Joined: 27 Dec 2007
Posts: 73
Location: India

PostPosted: Wed Oct 08, 2008 6:05 pm    Post subject: Reply to: Excluding the last record for SORT operation in a
Reply with quote

Thanks a lot..!!!!!!! It worked............
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 Oct 08, 2008 9:10 pm    Post subject:
Reply with quote

If you have z/OS DFSORT V1R5 PTF UK90013 (July, 2008) installed, you can do this quite easily like this:

Code:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN DD *
'2008-07-22.00.37.44.297630'
'2008-07-22.00.37.44.297631'
'2008-08-05.00.40.02.167578'
/*
//OUT DD SYSOUT=*
//TOOLIN   DD    *
DATASORT FROM(IN) TO(OUT) LAST USING(CTL1)
/*
//CTL1CNTL DD *
  INREC OVERLAY=(29:C',')
  SORT FIELDS=(1,1,CH,A)
/*


Note that the INREC statement is applied to the data records, but NOT to the LAST record.
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1703
Location: Australia

PostPosted: Thu Oct 09, 2008 2:20 am    Post subject:
Reply with quote

Hi,

my cut and paste omitted the below code, the job should have failed with a cc of 12.


Code:
//CTL3CNTL DD *                                                         
  OPTION COPY                                                           
  OUTFIL FNAMES=OUT,REMOVECC,NODETAIL,                                 
    TRAILER1=(1,80)                                                     
/*                                                                     



Gerry
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: Thu Oct 09, 2008 3:54 am    Post subject:
Reply with quote

I edited that into your job.

I suspect there are better ways to do this even without DATASORT, but since DFSORT/ICETOOL now has DATASORT, I won't bother to figure it out.
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Thu Oct 09, 2008 6:55 am    Post subject:
Reply with quote

Frank,

How about this one. But I can't test this now icon_sad.gif
Code:
//STEP1   EXEC PGM=ICETOOL                 
//IN      DD *                             
'2008-07-22.00.37.44.297630'               
'2008-07-22.00.37.44.297631'               
'2008-08-05.00.40.02.167578'               
/*                                         
//TOOLMSG   DD SYSOUT=*                     
//DFSMSG    DD SYSOUT=*                     
//T1        DD DSN=&&T1,DISP=(,PASS)       
//OUT       DD SYSOUT=*                     
//TOOLIN    DD *                           
  COPY FROM(IN) TO(T1) USING(CTL1)         
  SELECT FROM(T1) TO(OUT) ON(1,28,CH) LAST
/* 
//CTL1CNTL  DD *                           
   INREC OVERLAY=(29:C',')                 
   OUTFIL FNAMES=T1,REMOVECC,TRAILER1=(1,28)
/* 
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1703
Location: Australia

PostPosted: Thu Oct 09, 2008 7:18 am    Post subject:
Reply with quote

Hi Arun,

as long as the input file does not contain duplicates else your code will drop duplicates, also using LAST may not preserve the output file in the same sequence.


Gerry
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Thu Oct 09, 2008 11:07 am    Post subject:
Reply with quote

Hi all,

Here's an updated one which takes care of Gerry's considerations.
Code:
//STEP1   EXEC PGM=ICETOOL                             
//IN      DD *                                         
'2008-07-22.00.37.44.297630'                           
'2008-07-22.00.37.44.297631'                           
'2008-08-05.00.40.02.167578'                           
//*                                                   
//TOOLMSG   DD SYSOUT=*                               
//DFSMSG    DD SYSOUT=*                               
//T1        DD DSN=&&T1,DISP=(,PASS)                   
//OUT       DD SYSOUT=*                               
//TOOLIN    DD *                                       
  SORT FROM(IN) TO(T1)  USING(CTL1)                   
  SORT FROM(T1) TO(OUT) USING(CTL2)                   
//CTL1CNTL  DD *                                       
   INREC OVERLAY=(29:C',',81:SEQNUM,4,ZD)             
   SORT FIELDS=(81,4,ZD,D)                             
//CTL2CNTL  DD *                                       
   INREC IFTHEN=(WHEN=INIT,OVERLAY=(89:SEQNUM,4,ZD)), 
         IFTHEN=(WHEN=(89,4,ZD,EQ,1),OVERLAY=(29:C' '))
   SORT FIELDS=(81,4,ZD,A)                             
   OUTFIL FNAMES=OUT,BUILD=(1,80)                     
/*
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: Thu Oct 09, 2008 9:41 pm    Post subject:
Reply with quote

Your first solution was actually better then this new one.

FWIW, here's another variation on that theme:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=...  input file (FB/80)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//SYM DD DSN=&&S1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//SYSIN    DD    *
  OPTION COPY
  OUTFIL FNAMES=T1,OVERLAY=(81:SEQNUM,8,ZD)
  OUTFIL FNAMES=SYM,REMOVECC,NODETAIL,
    BUILD=(80X),
    TRAILER1=('LASTR,+',COUNT=(M11,LENGTH=8))
/*
//S2    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)
//SORTIN DD DSN=...  input file (FB/80)
//SORTOUT DD DSN=...  output file (FB/80)
//SYSIN DD    *
  OPTION COPY
  INREC IFOUTLEN=80,
    IFTHEN=(WHEN=(81,8,ZD,NE,LASTR),OVERLAY=(29:C','))
/*
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Thu Oct 09, 2008 11:34 pm    Post subject:
Reply with quote

Quote:
Your first solution was actually better then this new one.

I do agree that. But while posting that I assumed that there are no duplicates in the input and also that the records are in sorted order (which the OP has not mentioned) as pointed out by Gerry. Thanks for your point. icon_smile.gif
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 SORT BUT RETAIN HIGHEST VALUE ON NON-... leondan22 DFSORT/ICETOOL 2 Thu Dec 14, 2017 8:13 pm
No new posts ISSUE IN copying Sequential file reco... thesumitk JCL & VSAM 2 Wed Dec 13, 2017 3:07 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts File Tailoring -- Temporary dataset i... samzee71 CLIST & REXX 3 Fri Dec 01, 2017 3:12 am
No new posts Rexx - File tailoring samzee71 CLIST & REXX 10 Thu Nov 30, 2017 10:47 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us