IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Check the condition and update the output file using SORT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
maki_psg

New User


Joined: 28 Jan 2010
Posts: 47
Location: India

PostPosted: Wed Nov 07, 2012 6:57 pm
Reply with quote

Hi,

I have a requirement to update the output file with default value '000' when the include condition is not met.

For e.g.

//SORTSTEP EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=INPUT FILE,DISP=SHR
//SORTOUT DD DSN=OUTPUT FILE,DISP=MOD
//SYSIN DD *
SORT FIELDS=COPY
INCLUDE COND=(01,14,CH,EQ,C'NUMBER OF RECS')
/*

If the Input file for the above sort step is

LINE1
LINE2
NUMBER OF RECS: 100

Then, the output will be

NUMBER OF RECS: 100

If the Input file is

LINE3
LINE4

Then, the output should be

NUMBER OF RECS: 000

Is it possible to create the above logic using SORT?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Nov 07, 2012 7:00 pm
Reply with quote

Yes, look at OUTFIL reporting functions, especially TRAILERn.
Back to top
View user's profile Send private message
maki_psg

New User


Joined: 28 Jan 2010
Posts: 47
Location: India

PostPosted: Thu Nov 08, 2012 12:45 pm
Reply with quote

Hi Bill,

Thanks for your reply. My requirement is not to print the trailer record.

If a matching record is found from the input file, then I will have to copy the matching record(s) from input to output file (for e.g. Here, I used INCLUDE COND to copy only the matching records).

If there are no matching records, then I will have to set a default value of '000' with a string.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Nov 08, 2012 1:21 pm
Reply with quote

TRAILERn can be used to add a final record at the end of the file. There is no magic that DFSORT knows about to distinguish between what you call a "trailer" and what you call the "matching record".

Look it up, experiment, find out what it can do.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Thu Nov 08, 2012 2:44 pm
Reply with quote

Hello,
You could try this below code,

Code:
//WELLS    EXEC PGM=ICETOOL                                     
//TOOLMSG  DD SYSOUT=*                                           
//DFSMSG   DD SYSOUT=*                                           
//IN       DD DSN=WELLS.SORTIN,DISP=SHR               
//OUT    DD  DSN=WELLS.SORTOUT,DISP=OLD
//SYSOUT   DD SYSOUT=*                                           
//TOOLIN   DD *                                                 
  SUBSET FROM(IN) TO(OUT) INPUT KEEP LAST(1) USING(CTL1)         
/*                                                               
//CTL1CNTL DD *                                                 
  OUTFIL FNAMES=OUT,IFTHEN=(WHEN=(1,15,CH,EQ,C'NUMBER OF RECS:'),
  BUILD=(1,80)),                                                 
  IFTHEN=(WHEN=(1,15,CH,NE,C'NUMBER OF RECS:'),                 
  BUILD=(1:C'NUMBER OF RECS: 000',61X))                         
/*                                                               


Hope it helps.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Nov 08, 2012 3:16 pm
Reply with quote

Vasanthz,

For the second IFTHEN you could use WHEN=NONE and OVERLAY instead of BUILD.

Won't work with an empty file, though there is no indication from TS whether or not that matters :-)
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Thu Nov 08, 2012 3:22 pm
Reply with quote

Hello Bill,
Thanks for the suggestion,
Quote:
For the second IFTHEN you could use WHEN=NONE and OVERLAY instead of BUILD.

Im sure you told me this in one of the earlier posts. But I forgot it icon_confused.gif
Back to top
View user's profile Send private message
maki_psg

New User


Joined: 28 Jan 2010
Posts: 47
Location: India

PostPosted: Thu Nov 08, 2012 4:07 pm
Reply with quote

Thanks Vasanth/Bill.

Code:


//**********************************************************************
//SPLITFLS EXEC PGM=ICETOOL                                             
//**********************************************************************
//TOOLMSG  DD SYSOUT=*                                                 
//DFSMSG   DD SYSOUT=*                                                 
//IN   DD *                                                             
LINE1                                                                   
LINE2                                                                   
NUMBER OF RECS: 100                                                     
NUMBER OF RECS: 200                                                     
/*                                                                     
//OUT  DD SYSOUT=*                                                     
//TOOLIN DD *                                                           
 SUBSET FROM(IN) TO(OUT) INPUT KEEP LAST(1) USING(CTL1)                 
/*                                                                     
//CTL1CNTL DD *                                                         
  OUTFIL FNAMES=OUT,IFTHEN=(WHEN=(1,15,CH,EQ,C'NUMBER OF RECS:'),   
  BUILD=(1,80)),                                                   
  IFTHEN=(WHEN=NONE,                                               
  OVERLAY=(1:C'NUMBER OF RECS: 000',61X))                           
/*                                                                 



The above code works very well. However, if the input file has more than 1 matching record as shown above, then I am not able to copy all the matching records into output file as we had used LAST(1). How could we handle when there are more than 1 matching record?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Nov 08, 2012 4:15 pm
Reply with quote

Well, the first way to do it is to tell us that that situation can exist and include it in your sample data in your initial post. Otherwise we expend effort without reason, and the thing just goes back-and-forth like this.
Back to top
View user's profile Send private message
maki_psg

New User


Joined: 28 Jan 2010
Posts: 47
Location: India

PostPosted: Thu Nov 08, 2012 4:25 pm
Reply with quote

My apologies, Bill. :roll:
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Thu Nov 08, 2012 4:28 pm
Reply with quote

Hello,
If there are multiple occurances then my suggestion of code will not work.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Nov 08, 2012 5:29 pm
Reply with quote

You can try something like this:

Code:
//NUMRECS EXEC PGM=SORT
//SYMNAMES DD *
VALUE-TO-SEARCH-FOR,C'NUMBER OF RECS:'
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
                                                             
  JOINKEYS F1=INA,FIELDS=(1,15,A),SORTED,NOSEQCK
  JOINKEYS F2=INB,FIELDS=(1,15,A),SORTED,NOSEQCK
  JOIN UNPAIRED,F1,F2,ONLY
                                                             
  REFORMAT FIELDS=(F1:1,80,?,F2:1,1)
                                                             
  OPTION COPY
                                                             
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'N'),
                 PUSH=(82:1,1)),
                                                             
        IFTHEN=(WHEN=(81,1,CH,EQ,C'2',
                   AND,82,1,CH,NE,C'N'),
            OVERLAY=(1:VALUE-TO-SEARCH-FOR,X,C'000',81:C'1'))
                                                             
  OUTFIL INCLUDE=(81,1,CH,EQ,C'1'),BUILD=(1,80)
//JNF1CNTL DD *
  OPTION COPY
                                                             
  INCLUDE COND=(1,15,CH,EQ,VALUE-TO-SEARCH-FOR)
//JNF2CNTL DD *
  OPTION COPY,STOPAFT=1
                                                             
  INREC BUILD=(X'FF',14X)
//INA      DD *
LINE1
LINE2
NUMBER OF RECS: 100
NUMBER OF RECS: 200
//INB      DD *
DUMMY RECORD
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 1
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top