|
View previous topic :: View next topic
|
| Author |
Message |
maki_psg
New User
Joined: 28 Jan 2010 Posts: 47 Location: India
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| Yes, look at OUTFIL reporting functions, especially TRAILERn. |
|
| Back to top |
|
 |
maki_psg
New User
Joined: 28 Jan 2010 Posts: 47 Location: India
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
vasanthz
Global Moderator

Joined: 28 Aug 2007 Posts: 1753 Location: Tirupur, India
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
vasanthz
Global Moderator

Joined: 28 Aug 2007 Posts: 1753 Location: Tirupur, India
|
|
|
|
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  |
|
| Back to top |
|
 |
maki_psg
New User
Joined: 28 Jan 2010 Posts: 47 Location: India
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| 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 |
|
 |
maki_psg
New User
Joined: 28 Jan 2010 Posts: 47 Location: India
|
|
|
|
| My apologies, Bill. :roll: |
|
| Back to top |
|
 |
vasanthz
Global Moderator

Joined: 28 Aug 2007 Posts: 1753 Location: Tirupur, India
|
|
|
|
Hello,
If there are multiple occurances then my suggestion of code will not work. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|