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
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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: 2455 Location: Hampshire, 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
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 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: 2455 Location: Hampshire, 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
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Ramsri, you know that "it doesn't work" is useless without showing us what doesn't work. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 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: 2455 Location: Hampshire, 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
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
if I understand it correctly, you want the full name ie. first name initial and last name reversed and sorted with longest name first
ie. longest name=lastname + initial + first name
Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=input-file
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,255,BI,D)
INREC IFTHEN=(WHEN=INIT,
PARSE=(%01=(ENDAT=X'40',FIXLEN=126),
%02=(ENDAT=X'40',FIXLEN=1),
%03=(ENDAT=X'40',FIXLEN=126)),
BUILD=(%03,C'?',%02,C'?',%01)),
IFTHEN=(WHEN=(1,1,CH,EQ,1,1,CH),
BUILD=(1,255,SQZ=(SHIFT=RIGHT)))
OUTFIL IFOUTLEN=130,
IFTHEN=(WHEN=INIT,BUILD=(1,255,SQZ=(SHIFT=LEFT))),
IFTHEN=(WHEN=INIT,
FINDREP=(INOUT=(C'?',X'40')))
|
Gerry |
|
Back to top |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Gerry, thanks a lot.......you have made my day......
Can you please help me why length is fixed at 126 when file's length is 130 ?
what does below do?
Code: |
WHEN=(1,1,CH,EQ,1,1,CH)
|
Thanks again. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Ramsri,
I think Gerry was just showing an example, since you've kept any details to yourself.
You, surely, know what the maximum length of the elements of the name can be, and that gives you the theoretical maximum length needed. If your field already exists in that form (firstname, initial, lastname) only, then it is just the length of that field itself that you need to work with. The maximum length for an individual item for the FIXLEN is (field-length - 1 - 1 - 1 - 1). 130 seems a reasonable length, to guess, that would hold all your data, and may be much longer than need. You know your data, we don't.
The IFTHEN is just getting a "true", so is unconditional. I think another IFTHEN=(WHEN=INIT would be better.
I suggested JFY rather than SQZ due to the potential of embedded blanks in names. I assumed you had the rearrangement dealt with and were just keeping it a secret. |
|
Back to top |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi Ramsri,
Quote: |
Can you please help me why length is fixed at 126 when file's length is 130 ?
|
With a file of LRECL=130, neither firstname or last name can exceed length of 126.
eq. firstname = 126 + 1 (space) + 1 (initial) +1 (space) + 1 (lastname)= 130, anything greater than 126 would exceed the input LRECL of 130.
Quote: |
I suggested JFY rather than SQZ due to the potential of embedded blanks in names |
If embedded blanks appeared in names, this process would not work.
Gerry |
|
Back to top |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Thanks a lot Gerry.......it is always very interesting to learn technical things. |
|
Back to top |
|
|
|