Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to sort a file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
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    Post subject: How to sort a file
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

Moderator Team Head


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

PostPosted: Tue Feb 19, 2008 5:34 pm    Post subject: Reply to: How to sort a file
Reply with quote

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

http://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: 8593
Location: Back in jolly old England

PostPosted: Tue Feb 19, 2008 5:53 pm    Post subject:
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    Post subject: Reply to: How to sort a file
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    Post subject: Reply to: How to sort a file
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: 8593
Location: Back in jolly old England

PostPosted: Thu Feb 21, 2008 1:08 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to change 'K' or 'M' use Sort vice_versa DFSORT/ICETOOL 5 Thu May 18, 2017 7:11 am
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Adding big TEXT lines to each record ... bshkris SYNCSORT 4 Sat May 06, 2017 1:40 am
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Issue with NDM process to transmit ES... chetanambi All Other Mainframe Topics 6 Wed May 03, 2017 10:52 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us