View previous topic :: :: View next topic
|
Author |
Message |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Hi,
I have a file (LRECL=130,RECFM=FB) with names in it and want to sort it on first name's length. Is it possible with SYNCSORT?
Input:
Code: |
XAVIER P ROMOZ
RAO T CHINTAKINDI
PRASANNA K SEENAIAH
SULEIMAN V JEHANGHIR
|
Output:
Code: |
CHINTAKINDI T RAO
JEHANGHIR V SULEIMAN
ROMOZ P XAVIER
SEENAIAH K PRASANNA
|
Please help.
Thanks. |
|
Back to top |
|
 |
|
|
Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7314
|
|
|
|
Yes, what you have written should be possible, but your output seems to disagree that that is what you want. |
|
Back to top |
|
 |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
I don't understand you  |
|
Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2002 Location: UK
|
|
|
|
ramsri
Is your example input first name, initial, last name? The confusion arises because you have changed the sequence of the fields on the output but this is not mentioned in your requirement. |
|
Back to top |
|
 |
Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7314
|
|
|
|
XAVIER is the second-shortest first name, but appears third in your expected output. Therefore, your expected output is not sorted on length of first name (the first "word" in your data). |
|
Back to top |
|
 |
dick scherrer
Site Director
Joined: 23 Nov 2006 Posts: 19270 Location: Inside the Matrix
|
|
|
|
Hello,
What "rule" did you use to get from your input to your output? |
|
Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2002 Location: UK
|
|
|
|
It looks as though your input is in surname/initial/forename and when you sort you transpose your data to be forename/initial./surname and sort on forename on output. But.. what if a person has no initial? |
|
Back to top |
|
 |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
The rule is to sort names on first character on ascending order. Not seen a name without an initial in that dataset ! |
|
Back to top |
|
 |
Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7314
|
|
|
|
You want to sort on the first character of the third "word" on your input? And rearrange your data? Use PARSE and SQZ in INREC to rearrange your data. SORT FIELDS=(1,1,CH,A).
Obviously this will pickle with no initial, or with embedded blanks in a name (first or last) so ensure that you either can't have those or that you can deal with them. |
|
Back to top |
|
 |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Bill, your IDEA given me results -
Code: |
//STEP0001 EXEC PGM=SORT
//SORTIN DD *
XAVIER P ROMOZ
RAO T CHINTAKINDI
PRASANNA K SEENAIAH
SULEIMAN V JEHANGHIR
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC PARSE=(%01=(ENDBEFR=C' ',FIXLEN=8),
%02=(ENDBEFR=C' ',FIXLEN=1),
%03=(ENDBEFR=C' ',FIXLEN=11)),
BUILD=(%03,X,%02,X,%01)
SORT FIELDS=(1,1,CH,A)
OUTREC BUILD=(1,22,SQZ=(SHIFT=LEFT,MID=C' '))
|
I tried but did not work. Is it possible to get this done using INREC alone? Or, must to use both INREC and OUTREC?
Thanks. |
|
Back to top |
|
 |
Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7314
|
|
|
|
Ramsri, you know that "it doesn't work" is useless without showing us what doesn't work. |
|
Back to top |
|
 |
dick scherrer
Site Director
Joined: 23 Nov 2006 Posts: 19270 Location: Inside the Matrix
|
|
|
|
Hello,
You posted
Quote: |
I have a file (LRECL=130,RECFM=FB) with names in it and want to sort it on first name's length |
then
Quote: |
The rule is to sort names on first character on ascending order. |
You need to post a better set of sample input data and the output you want from that sample input.
What you have posted so far is incomplete, incorrect, and rather confusing.
No one should waste more time on this until a proper situation (understandable request and desired output) has been posted.
d |
|
Back to top |
|
 |
hailashwin
New User
Joined: 16 Oct 2008 Posts: 74 Location: Boston
|
|
|
|
Quote: |
Is it possible to get this done using INREC alone? Or, must to use both INREC and OUTREC? |
An alternate way of doing it only with INREC is below. But makes me wonder why you insist to do away with OUTREC?
Code: |
//SYSIN DD *
INREC IFTHEN=(WHEN=INIT,
PARSE=(%01=(ENDBEFR=C' ',FIXLEN=8),
%02=(ENDBEFR=C' ',FIXLEN=1),
%03=(ENDBEFR=C' ',FIXLEN=11)),
BUILD=(%03,X,%02,X,%01)),
IFTHEN=(WHEN=INIT,
BUILD=(1,22,SQZ=(SHIFT=LEFT,MID=C' ')))
SORT FIELDS=(1,1,CH,A)
|
Thanks,
Ashwin. |
|
Back to top |
|
 |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Ashwin, thanks.....I did not want to "do away" but wonder if it was possible...and you have shown that it was possible Whenever I tried combination of INREC with OUTREC, I end up getting "INEFFICIENT USE OF INREC" warning in SYSOUT because I would have written but could not figure out.
Thanks again. |
|
Back to top |
|
 |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Dick, yes, I have deviated from what I originally asked....I wanted to SORT the names on their length after rearranging them.
Input-
Code: |
XAVIER P ROMOZ
RAO T CHINTAKINDI
PRASANNA K SEENAIAH
SULEIMAN V JEHANGHIR
|
Expected Output-
Code: |
JEHANGHIR V SULEIMAN
SEENAIAH K PRASANNA
CHINTAKINDI T RAO
ROMOZ P XAVIER
|
Thanks. |
|
Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2002 Location: UK
|
|
|
|
Quote: |
SORT the names on their length |
Is that the entire length - forename/initial(s)/surname - or just one of these? |
|
Back to top |
|
 |
Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7314
|
|
|
|
Ramsri,
Extend your records by a new field (INREC) that is the same as the maximum length of the names, populated by using your name field as the source for JFY with SHIFT=RIGHT. SORT on the new field. Looks like you want it descending. Chop the extension off afterwards (OUTREC or OUTFIL) with BUILD (of IFOUTLEN if you already happen to have IFTHEN processing).
Please try to have a complete, clear, question, with sample data which is representative and which exercises what you want to do. |
|
Back to top |
|
 |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Quote: |
xtend your records by a new field (INREC) that is the same as the maximum length of the names
|
How do I know the max. length of a record? For example sake it is easy to find though  |
|
Back to top |
|
 |
Bill Woodger
DFSORT Moderator
Joined: 09 Mar 2011 Posts: 7314
|
|
|
|
If you can't remember the DCB info for the datasets you are working on, then you need to use your fingers and eyes (type and read).
If you don't feel up to that you could always define your SORT key as each individual byte in your field, in reverse order, and remember that you seem to want, or seemed to want at the time of the particular post, descending.
This is getting nowhere, slowly. Unless something magical happens at your end, this topic will be locked. |
|
Back to top |
|
 |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Bill, I understand what has confused you.....Its not the length of dataset but the length of longest name in that dataset is the basis I am looking for.......ideas please. |
|
Back to top |
|
 |
|