|
View previous topic :: View next topic
|
| Author |
Message |
kshirabdhi
New User
Joined: 22 Nov 2007 Posts: 13 Location: Noida
|
|
|
|
Hi All,
I am using SORT to fetch records from a file based on a condition.
Fields part of INCLUDE COND are -
| Code: |
TRAN-CODE PIC 9(05).
TRACE-NUMBER PIC 9(11).
|
Requirement -
Fetch records where
1. TRAN-CODE = 101 and
2. TRACE-NUMBER begins with 9954 OR 9568 (excluding the leading zeros)
Position of TRAN-CODE is 1 and TRACE-NUMBER is 7. Number of digits in TRACE-NUMBER can be from 5 to 11.
Input data -
| Code: |
00101 00000995412
00101 00995412234
00101 00090541274
00101 09568123421
00101 00956895412
00101 00956790989
|
Output -
| Code: |
00101 00000995412
00101 00995412234
00101 09568123421
00101 00956895412 |
I am unable to write the syntax for condition for TRACE-NUMBER. The reason why I am using SORT is , I am extracting data from a file for validation with a report after production implementation.
Please help if SORT has any function/syntax for this. Let me know if I need to furnish more details. |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
quick and dirty ( just to show the logic )
| Code: |
INCLUDE COND=(7,9,CH,EQ,C'000009954',OR,
7,8,CH,EQ,C'00009954',OR,
7,7,CH,EQ,C'0009954',OR,
7,6,CH,EQ,C'009954',OR,
7,5,CH,EQ,C'09954',OR,
7,4,CH,EQ,C'9954',OR,
...
|
|
|
| Back to top |
|
 |
Abid Hasan
New User
Joined: 25 Mar 2013 Posts: 88 Location: India
|
|
|
|
Hello,
Have a look at Substring (operator) comparison tests of INCLUDE function in DFSORT; it should give you what you need.
You can look here, for some information on how to use it. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
The problem with using the substring search is that you are open to "false hits".
A record with non-zero leading "69954", for instance, would be selected.
enrico's suggestion is the way to do it. |
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3112 Location: NYC,USA
|
|
|
|
Try this,
| Code: |
//SORTIN DD *
00101 00000995412
00101 00995412234
00101 00090541274
00101 09568123421
00101 00956895412
00101 00956790989
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC IFTHEN=(WHEN=(1,5,CH,EQ,C'00101'),
OVERLAY=(7:7,11,ZD,M10,LENGTH=11,7:7,11,SQZ=(SHIFT=LEFT))),
IFTHEN=(WHEN=NONE,BUILD=(1,17))
OUTFIL INCLUDE=(7,4,CH,EQ,C'9954',OR,7,4,CH,EQ,C'9568',
AND,1,5,CH,EQ,C'00101'),
BUILD=(1,5,X,7,11,UFF,M11)
OPTION COPY |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Rohit,
If you INCLUDE/OMIT COND= you can avoid the repeated record-type test. There's no point in a case like this of retaining data only to ignore it later.
However, there's not indication that there are other than 00101 records, so why bother?
There's no need for the WHEN=NONE if you are just going to BUILD the same record that already exists.
To use an edit mask to get rid of the leading zeros and then SQZ is a good idea, but I don't think you need to destroy the original data just to recreate it later. Extend the record. You can also use LENGTH=4 on the SQZ, as only four characters are wanted, and IFOUTLEN to limit the records (not no important for a COPY, but for a SORT you'd not need spurious extra data hanging around).
There's also no point, in this case, of recreating the first part of the record in the OUTFIL. It is just sitting there already as 1,6. You could OVERLAY with your second EDIT. However, having not destroyed the input, a simple BUILD to cut off the extension.
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(18:
7,11,
ZD,
M10,
LENGTH=11,
18:
18,11,
JFY=(SHIFT=LEFT,
LENGTH=4))),
IFOUTLEN=21
OUTFIL INCLUDE=(18,4,CH,EQ,C'9954',
OR,
18,4,CH,EQ,C'9568'),
BUILD=(1,17) |
|
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3112 Location: NYC,USA
|
|
|
|
Thanks for the notes Bill. that makes me learn and improve my dfsort logic.
I assumed TS wanted onetime sort card so did try some quick sort but your tips certainly helps.
| Quote: |
| However, there's not indication that there are other than 00101 records, so why bother? |
TS say's
| Quote: |
Fetch records where
1. TRAN-CODE = 101 and
2. TRACE-NUMBER begins with 9954 OR 9568 (excluding the leading zeros) |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, I missed that. There are no other record-types in the sample data. A simple INCLUDE COND= as well, then.
For the actual task, with only two selections, and from a fairly short length of data, enrico's is the best solution. As the number of selections increase, and the length of the data increases, this one comes more into play.
Preserving the original data is not sacrosanct. There are many occasions where changing the data temporarily then setting it back are the best solution to a task. It need not matter if five zeros are removed and five zeros in the same position are added later. However, there is usually no point in doing it just for the sake of doing it.
Note: if dropping the leading zeros for spaces in the original position Abid's SS, with a leading blank for the value, becomes possible. The leading zeros have to be returned later. Although it works, it is likely more expensive.
Oh, and JFY for this is better than SQZ. I'll update my previous post for that. |
|
| Back to top |
|
 |
Abid Hasan
New User
Joined: 25 Mar 2013 Posts: 88 Location: India
|
|
|
|
To Bill,
Thank you, that was helpful and gave quite a few pointers to better the DFSORT logic. |
|
| Back to top |
|
 |
kshirabdhi
New User
Joined: 22 Nov 2007 Posts: 13 Location: Noida
|
|
|
|
I used Bill's trick as the requirement I have mentioned is part of a bigger selection condition and the data length is also larger. It served the purpose.
Thank you all for taking out your valuable time to propose different solutions. I learnt some new SORT tricks. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you already have something which you need to amend for new processing, it is always best to post what you already have. There can be different solutions which each are a better fit for one set of existing control cards or another.
If you can show what you have come up with, we will be able to make concrete suggestions for that context. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|