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
 

 

Check the condition and update the output file using SORT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
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    Post subject: Check the condition and update the output file using SORT
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Wed Nov 07, 2012 7:00 pm    Post subject: Reply to: Check the condition and update the output file usi
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    Post subject: Reply to: Check the condition and update the output file usi
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Thu Nov 08, 2012 1:21 pm    Post subject: Reply to: Check the condition and update the output file usi
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: 1445
Location: Azeroth

PostPosted: Thu Nov 08, 2012 2:44 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Thu Nov 08, 2012 3:16 pm    Post subject: Reply to: Check the condition and update the output file usi
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: 1445
Location: Azeroth

PostPosted: Thu Nov 08, 2012 3:22 pm    Post subject:
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    Post subject: Reply to: Check the condition and update the output file usi
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Thu Nov 08, 2012 4:15 pm    Post subject: Reply to: Check the condition and update the output file usi
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    Post subject: Reply to: Check the condition and update the output file usi
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: 1445
Location: Azeroth

PostPosted: Thu Nov 08, 2012 4:28 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Thu Nov 08, 2012 5:29 pm    Post subject: Reply to: Check the condition and update the output file usi
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    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 Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 6 Fri Nov 18, 2016 1:48 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


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