Posted: Mon Oct 25, 2004 3:18 pm Post subject: How to sort this file with File-Aid?
Hi all experts,
I am re-written a program from COBOL to C, there is sort step in the skeleton that calls a COBOL program to perform the sort. I am wondering if I can use File-aid or other utilities to sort this without writing a C program. If so could anyone please show me the way. I am very low in main frame skill!
The input file needs to be sorted based on 6 keys, sort key values can be different depends the conditions. Here is the example:
if colums 33-38 contains "member"
key#1 = blank
key#2 = column 77-78, which contains AA,AB,CA,CC....
key#3 = some particular column
key#4 = column 79-80, which contains blank, 01, 02
key#5 = order of the orginal records
if column 77-78 contain "TT"
key#1 = some particular column
key#2 = some particular column
key#3 = some particular column
key#4 = some particular column
key#5 = some particular column
if column 69-70 contain "DL"
key#1 = some particular column
key#2 = some particular column
key#3 = some particular column
key#4 = some particular column
key#5 = some particular column
and so on...
I am wondering if the is a way that I can achieve this goal?
the input file looks like this:
TSS.1R.HZD.CMDS...003133.TSS.1R..... AB
PCSDLST 092 040595M. WILLIS 7134831040 NSTS18411SM2 AA
TSS.1R.PCS.SUPPORT003133.TSS.1R..... AB
UMP.UMP3 004 080295SONJA SUMMERS 7134834217 NSTS21249SM2 AA
USMP.3............003407.USMP.3..... AB
********************************MEMBERFILE01 **********************************
PEMP 033 090195K.B. THOMAS 7134831380 NSTS21286SM2 AA
1CA
PF01 102S OUT 1501 CB01
P03K6097J 04EVENT DEPL HEATERS PWR ON (K2) O CC
P03K6097J L O ON 02 PF01SIO101501 SS 32CD
P03K6097J P03K6097E P33M9001J CE
P03K6097J D555000002008073 CL01
P03K6097JA DISP=213, ITEM=18 CF
P03K6098J 04EVENT DEPL HEATERS PWR OFF (K2) O CC
P03K6098J L O OFF 02 PF01SIO101501 SS 32CD
********************************MEMBERFILE14 **********************************
2CA
P13K0800L 07EVENT MAIN ISO. V. OPEN CC
P13K0800L L S OPEN 01 QQ X S L CD
P13K0800L A01K001J CE
The output will look simmilar to this:
Code:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-
P03K6097J 04EVENT DEPL HEATERS PWR ON (K2) O CC FILE01
P03K6097J L O ON 02 PF01SIO101501 SS 32CD FILE01
P03K6097J P03K6097E P33M9001J CE FILE01
P03K6097J D555000002008073 CL01FILE01
P03K6097JA DISP=213, ITEM=18 CF FILE01
905 53FFAFC30 F0001 U0000004 1 TB FILE28
914 53 O 1.00BIPL08100000400100 10032000.000000TA FILE28
914 53FFAFC30 F0001 U0000004 1 TB FILE28
*Note that the output records is 86 characters long because the COBOL program puts member names at the end of each of records so that it can sort by file names
I am very appreciate all of you who trying to help me on this assignment.
Thank you!
Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
Posted: Mon Oct 25, 2004 3:31 pm Post subject:
nguyenh,
If I understand correctly you are sort fields vary depending upon the contents of the file.
Code:
if colums 33-38 contains "member"
then sort fields=(k1,k2,k3,k4,k5,k6)
if column 77-78 contain "TT"
then sort fields=(k7,k8,k9,k10,k11,k12)
if column 69-70 contain "DL"
then sort fields=(k13,k14,k15,k16,k17,k118)
Can the input file have records which match more than 1 condition? i.e one of the record in the input file has "member" at pos 33 and 'tt' in pos 77 and "DL" in pos 69
How do you intend to sort such records?
Also post the position , format for the key values k1 thru k18.
Hi Kolusu,
First Thank you for your helps,
It's kind wording to explain. here is the actual original COBOL code that I want to replace with File-Aid step. Hope that it helps to explain what I am trying to say. You may delete the code if you think it is too long for this post. Sorry I am not trying to get you do my work, but if you can help me with some hints. I am very appreciated.
Quote:
If I understand correctly you are sort fields vary depending upon the contents of the file.
The answer to this one is yes you are correct.
Quote:
Can the input file have records which match more than 1 condition? i.e one of the record in the input file has "member" at pos 33 and 'tt' in pos 77 and "DL" in pos 69
Not like the one that you provided, because "MEMBER" only appears in these lines:
Code:
********************************MEMBERBFS **********************************
********************************MEMBERFILEHDR **********************************
********************************MEMBERFILE01 **********************************
********************************MEMBERFILE02 **********************************
********************************MEMBERFILE03 **********************************
and so on...
but yes I think it could have something like
"DL" in 69-70 and "TT" in 77-78, and so on
Code:
FD WRK
RECORD CONTAINS 080 CHARACTERS
BLOCK CONTAINS 0 RECORDS
LABEL RECORDS ARE OMITTED
DATA RECORD IS WORK.
01 WORK PIC X(080).
FD OUTT
RECORD CONTAINS 086 CHARACTERS
BLOCK CONTAINS 0 RECORDS
LABEL RECORDS ARE OMITTED
DATA RECORD IS OP.
01 OP PIC X(086).
SD SORTE
RECORD CONTAINS 108 CHARACTERS
DATA RECORD IS SORRT.
01 SORRT.
05 S-SORT PIC X(80).
05 K0 PIC X(06).
05 K1.
10 K-BLK PIC X(1).
10 K-FST PIC X(3).
10 K-LST PIC X(6).
05 K2 PIC X(2).
05 K3 PIC X(4).
05 K4 PIC X(2).
05 K5 PIC 9(7) COMP-3.
WORKING-STORAGE SECTION.
01 IP-REC VALUE 0 PIC 9(10).
01 OP-REC VALUE 0 PIC 9(10).
01 FL-CNT VALUE 0 PIC 9(02).
01 SW-MEM VALUE 0 PIC 9(02).
01 WS-K5 VALUE 0 PIC 9(07) COMP-3.
01 BLANK80 VALUE SPACES PIC X(80).
01 SAVE-KEY VALUE SPACES PIC X(06).
01 SAVE-REC VALUE SPACES PIC X(80).
01 OLD-MSID PIC X(10).
01 OLD-KEY.
05 O-NUM PIC X(4).
05 O-MSID PIC X(10).
01 NEW-KEY.
05 N-NUM PIC X(4).
05 N-MSID PIC X(10).
PROCEDURE DIVISION.
CALL-HEADER.
OPEN INPUT WRK.
OPEN OUTPUT OUTT.
PERFORM 3001-FRM-WORD-SORT
CLOSE WRK.
CLOSE OUTT.
DISPLAY IP-REC.
STOP RUN.
3001-FRM-WORD-SORT.
SORT SORTE ON ASCENDING KEY K0 K1 K2 K3 K4 K5
INPUT PROCEDURE IS 3010-READ THRU 3020-SORT
OUTPUT PROCEDURE IS 3040-RETURN-RECORD THRU 3999-CLOSE.
3010-READ SECTION.
MOVE SPACE TO SORRT.
MOVE SPACE TO K1.
MOVE SPACE TO K2.
MOVE SPACE TO K3.
MOVE SPACE TO K4.
READ WRK INTO INN-IP AT END GO TO 3020-SORT.
MOVE I-RECORD TO SAVE-REC.
ADD 1 TO IP-REC.
ADD 1 TO WS-K5.
IF (I-RECORD = BLANK80) GO TO 3010-READ.
IF (I-MEM = 'MEMBER')
PERFORM BUILD-KEY
GO TO 3010-READ.
IF (I-MEM = 'MEMBER') NEXT SENTENCE ELSE MOVE 0 TO SW-MEM.
MOVE SAVE-KEY TO K0.
MOVE I-TYP TO K2.
MOVE I-SEQ TO K4.
MOVE WS-K5 TO K5.
IF (I-LET = ' ')
MOVE I-FST TO K-FST
ELSE
MOVE I-NO TO K1.
IF (I-TYP = 'TT')
MOVE I-FMT TO K3
ELSE
MOVE ' ' TO K3.
IF (I-TYP = 'CA')
MOVE I-PREFIX TO K3.
IF (I-KEY2 = 'DL') MOVE R-FST TO K3.
IF (I-KEY2 = 'FM') MOVE I-CT TO K3.
IF (I-TYP = 'TB' OR 'TA' OR 'TC')
MOVE T-FMT TO TA-KEY
MOVE TA-KEY TO K1.
IF (I-TYP = 'TB' OR 'TA' OR 'TC') MOVE T-FMT TO K3.
MOVE I-RECORD TO S-SORT.
RELEASE SORRT.
MOVE SPACE TO SORRT.
GO TO 3010-READ.
BUILD-KEY.
IF (SW-MEM = 1) MOVE SAVE-REC TO S-SORT
MOVE SAVE-KEY TO K0
RELEASE SORRT
MOVE SPACE TO SORRT.
ADD 1 TO FL-CNT.
MOVE I-FILE TO SAVE-KEY.
MOVE 1 TO SW-MEM.
3020-SORT SECTION.
MOVE SAVE-KEY TO K0.
MOVE I-RECORD TO S-SORT.
RELEASE SORRT.
MOVE SPACE TO SORRT.
DISPLAY IP-REC.
3040-RETURN-RECORD SECTION.
RETURN SORTE RECORD AT END GO TO 3999-CLOSE.
MOVE S-SORT TO O-RECORD.
MOVE K0 TO O-KEY.
ADD 1 TO OP-REC.
WRITE OP FROM O-RECORD.
* DISPLAY '**** O-RECORD = ' O-RECORD.
GO TO 3040-RETURN-RECORD.
3999-CLOSE SECTION.
DISPLAY OP-REC.
Hi Kolusu,
First, could you please delete my last post. since it would help anyone with I think there was too much uneccessary information there.
Here is the question that i have.
How to use fileaid to peform this sort. assume sort keys are K0-K5:
I want to sort the input file in orders keys K0-K5 base on the following conditions:
Code:
K0 = columns (39-44)
If (column 1 is blank, Or columns 77-78 = "TA", "TB", or "TC")
K1 = columns (11-14)
Else
K1= columns(1-10)
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