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

How to sort a file


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
JAGAN_SRIRAM

New User


Joined: 21 Jul 2007
Posts: 4
Location: INDIA

PostPosted: Tue Feb 19, 2008 5:29 pm
Reply with quote

Hi,
i have a file in the following format

1236 tom
3343 jon
5441 mary
4434 joe
i want to sort the file by using the first four characters. can any one help me(using rexx only)
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Tue Feb 19, 2008 5:34 pm
Reply with quote

You've already answered your question in another topic posted by you:

ibmmainframes.com/viewtopic.php?p=113209&highlight=#113209
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Feb 19, 2008 5:53 pm
Reply with quote

Using REXX - take a look at the CALL instruction to call your sort product into play.
Back to top
View user's profile Send private message
peras

New User


Joined: 20 Feb 2008
Posts: 1
Location: Denmark

PostPosted: Wed Feb 20, 2008 6:40 pm
Reply with quote

If you have Pipe-Rexx installed - it can be done easily.

Read the file into a stem and issue
"pipe stem stemvariabelname. ! sort 1.4 ! newstemvariablename."

Then write the new stem (newstemvariablename) to a dataset.
Back to top
View user's profile Send private message
cpuhawg

Active User


Joined: 14 Jun 2006
Posts: 331
Location: Jacksonville, FL

PostPosted: Wed Feb 20, 2008 6:59 pm
Reply with quote

Here is some sample REXX code for invoking SORT:

Code:

ADDRESS TSO                                                   
 "DELETE ('HLQ.SYSIN1') PURGE"                       
  SYSDS = "('HLQ.SYSIN1')"                             
  "FREE F(SYSIN)"                                           
  "ALLOC DA"||SYSDS||" F(SYSIN) NEW CATALOG",               
              "LRECL(80) BLKSIZE(80) RECFM(F) DSORG(PS)",     
              "TRACKS SPACE(1 1) UNIT(SYSDA)"                 
  NEWSTACK                                                   
  DD01 = "  SORT FIELDS=(1,4,CH,A)"                                 
  DD02 = "  END "
  QUEUE DD01                                                 
  QUEUE DD02                                                 
  QUECT = QUEUED()                                           
  "EXECIO "QUECT" DISKW SYSIN (FINIS"                         
  DELSTACK                                                   
   "FREE F(SORTOUT)"                                         
  OUTDS = "('HLQ.LOOK')"                             
   "DELETE "OUTDS" PURGE"                                     
   "ALLOC DA"||OUTDS||" F(SORTOUT) NEW CATALOG",                       
              "LRECL(130) BLKSIZE(27950) RECFM(F B) DSORG(PS)",         
              "TRACKS SPACE(200 50) UNIT(SYSDA)"                       
  INDSN = "HLQ.INPUT.FILE"                         
   "ALLOC DA('HLQ.SORTWRK1') F(SORTWK01)",                     
          "NEW CATALOG BLKSIZE(27998) RECFM(U) TRACKS SPACE(1000 500)",
          "UNIT(SYSDA)"                                                 
   "ALLOC DA('HLQ.SORTWRK2') F(SORTWK02)",                     
          "NEW CATALOG BLKSIZE(27998) RECFM(U) TRACKS SPACE(1000 500)",
          "UNIT(SYSDA)"                                                 
   "ALLOC F(SYSOUT) SYSOUT(Z)"                                         
   "ALLOC F(SYSUDUMP) DUMMY"                                           
   "ALLOC DA("||INDSN||") F(SORTIN) SHR REUSE"                         
   "CALL 'HLQ.SORT.LIBRARY(SORT)' "                                         
   "FREE FI(SORTWK01)"                                                 
   "FREE FI(SORTWK02)"                                                 
   "DELETE ('HLQ.SORTWRK1') PURGE"                             
   "DELETE ('HLQ.SORTWRK2') PURGE"                             
   "FREE F(SORTIN)"                                                     
   "FREE F(SORTOUT)"                                                   
   "FREE F(SYSOUT)"                                                     
   "FREE F(SYSUDUMP)" 
   "FREE F(SYSIN)"
 


The sort control cards are loaded into HLQ.SYSIN. This particular sort allocates and uses sort work files for dealing with large files. This method prevents problems with storage available to the REXX program. If your files are small, all reference to the sort work files can be removed. Make sure the proper sort library is coded when CALLing the program:
CALL 'HLQ.SORT.LIBRARY(SORT)' "
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Feb 21, 2008 1:08 pm
Reply with quote

And if you can't be bothered going through the delete / define of the files that you use, just use temporary files. They get deleted when you issue the FREE FI(xxxx).

Much easier. This works for both batch and online.
Code:

"FREE  FI(SYSIN,SYSOUT,SORTIN,SORTOUT)"                               
"ALLOC FI(SYSOUT)   SYSOUT(X)"                                       
"ALLOC FI(SYSIN)    NEW TRACKS SPACE(3 3)     RECFM(F B) LRECL(80)"   
"ALLOC FI(SORTIN)   NEW TRACKS SPACE(300 300) RECFM(V B) LRECL(80)"   
"ALLOC FI(SORTOUT)  NEW TRACKS SPACE(300 300) RECFM(V B) LRECL(80)"   
QUEUE " OPTION VLSHRT VLSCMP"                                         
QUEUE " SORT FIELDS=(5,44,CH,A)"                                     
QUEUE "  SUM FIELDS=NONE)"                                           
"EXECIO "QUEUED() "DISKW SYSIN   ( FINIS"                             
"EXECIO * DISKW SORTIN  ( STEM FILE99. FINIS"                         
"CALL *(SORT)"                                                       
"EXECIO * DISKR SORTOUT ( STEM FILE99. FINIS"                         
"FREE  FI(SYSIN,SYSOUT,SORTIN,SORTOUT)"                               
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 -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 4
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top