IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Sorting input records on length of characters.


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Thu Nov 28, 2013 5:22 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Nov 28, 2013 5:50 pm
Reply with quote

Yes, what you have written should be possible, but your output seems to disagree that that is what you want.
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Thu Nov 28, 2013 6:22 pm
Reply with quote

I don't understand you icon_confused.gif
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Thu Nov 28, 2013 6:43 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Nov 28, 2013 6:58 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Nov 29, 2013 8:28 am
Reply with quote

Hello,

What "rule" did you use to get from your input to your output?
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Nov 29, 2013 3:16 pm
Reply with quote

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
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Fri Nov 29, 2013 5:35 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Nov 29, 2013 5:51 pm
Reply with quote

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
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Fri Nov 29, 2013 6:23 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Nov 29, 2013 7:03 pm
Reply with quote

Ramsri, you know that "it doesn't work" is useless without showing us what doesn't work.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Dec 02, 2013 6:07 am
Reply with quote

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
View user's profile Send private message
hailashwin

New User


Joined: 16 Oct 2008
Posts: 74
Location: Boston

PostPosted: Mon Dec 02, 2013 1:35 pm
Reply with quote

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? icon_confused.gif
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
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Mon Dec 02, 2013 3:35 pm
Reply with quote

Ashwin, thanks.....I did not want to "do away" but wonder if it was possible...and you have shown that it was possible icon_smile.gif 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
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Mon Dec 02, 2013 3:40 pm
Reply with quote

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
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Mon Dec 02, 2013 6:54 pm
Reply with quote

Quote:
SORT the names on their length


Is that the entire length - forename/initial(s)/surname - or just one of these?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Dec 02, 2013 11:13 pm
Reply with quote

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
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Tue Dec 03, 2013 6:24 pm
Reply with quote

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 icon_surprised.gif
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Dec 03, 2013 6:45 pm
Reply with quote

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
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Wed Dec 04, 2013 8:05 am
Reply with quote

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
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Wed Dec 04, 2013 10:03 am
Reply with quote

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
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Wed Dec 04, 2013 4:31 pm
Reply with quote

Gerry, thanks a lot.......you have made my day...... icon_biggrin.gif
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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Dec 04, 2013 6:40 pm
Reply with quote

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
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Thu Dec 05, 2013 7:14 am
Reply with quote

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
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Sun Dec 08, 2013 9:14 am
Reply with quote

Thanks a lot Gerry.......it is always very interesting to learn technical things.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 8
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top