MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cobol Internal Sort on Multiple Record Layouts

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
newuser
Beginner


Joined: 12 Jun 2003
Posts: 16
Topics: 8

PostPosted: Fri Sep 26, 2003 9:13 am    Post subject: Cobol Internal Sort on Multiple Record Layouts Reply with quote

Hello,

I need to sort an input file on 2 fields. The input file is fixed length 25000 byte.
The problem I have is some of the records span multiple lines, say multiple records.
I need to keep those groups together when doing the sort. Here's a sample input file,

Code:

0001AAA1111ASADFJA;DFJ            -line1
0001CCC1122DAF'SDFK'SDKF                   -line2
ADSAF'DKF'A;SDKF'AD;KFD      -line3
0001BBB2222ADFASDFLJAD'KF                   -line4
DADFA'DSFKA'SDKF'DKFDFD      -line5
ADFAKFD';LKDSF'AKSDFSDF      -line6
0001DDD1111DADAFSAFDFF      -line7


Sort parameters are: 3 positions from 5th byte
and 4 positions from 8th byte

A new record is identified by '0001' at the start of the record. If it is not '0001', that means, the record is a continuation of the previous line and this record needs to be grouped together.

So the sample output will be:

Code:

0001AAA1111ASADFJA;DFJ                     -line1
0001BBB2222ADFASDFLJAD'KF                   -line4
DADFA'DSFKA'SDKF'DKFDFD      -line5
ADFAKFD';LKDSF'AKSDFSDF      -line6
0001CCC1122DAF'SDFK'SDKF                   -line2
ADSAF'DKF'A;SDKF'AD;KFD      -line3
0001DDD1111DADAFSAFDFF      -line7

Any suggestion how I can accomplish this ?

Regards!
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Fri Sep 26, 2003 3:03 pm    Post subject: Reply with quote

Newwuser,

Here is an approach you can try.

Your input record length is 25000.


Add another 7 bytes( for the key fields to be sorted ) at the end as shown below

Code:

01 OUTPUT-REC.
   OUT-REC            PIC X(25000).
   OUT-KEY1           PIC X(3).
   OUT-KEY2           PIC X(4).


Define to working storage keys to save the keys
Code:

W-SAVE-KEY1           PIC X(3).
W-SAVE-KEY2           PIC X(7).


so now the output file lrecl is 25007.

In the program read the record and perform the logic.

Code:


 IF IN-REC (1 : 4 ) = '0001'
    MOVE IN-REC             TO OUT-REC

    MOVE IN-REC (5 : 3)     TO W-SAVE-KEY1
                               OUT-KEY1

    MOVE IN-REC (8 : 4)     TO W-SAVE-KEY2
                               OUT-KEY2
 
    WRITE OUTPUT
ELSE
    MOVE IN-REC             TO OUT-REC

    MOVE W-SAVE-KEY1        TO OUT-KEY1

    MOVE W-SAVE-KEY2        TO OUT-KEY2
 
    WRITE OUTPUT
END-IF 



Now every record has a key at the end. Now runa sort step to sort on the key.

Code:

//STEP0100  EXEC  PGM=SORT                                     
//SYSOUT    DD SYSOUT=*                                         
//SORTIN    DD DSN=THE 25007 OUTPUT FILE FROM PGM,                       
//             DISP=SHR                                         
//SORTOUT   DD DSN=YOUR OUTPUT SORTED FILE,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,         
//             SPACE=(CYL,(X,Y),RLSE)
//SYSIN     DD *
  SORT FIELDS=(25001,7,CH,A)    $ SORT ON THE KEY FIELDS
  OUTREC FIELDS=(1,25000)       $ STRIP THE KEY
//*


Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group