Page 1 of 1
SORT verb - help
Posted: Wed Apr 11, 2007 12:24 am
by laifas
I am writing an assignment (Mainframe COBOL using MVS) and I need to sort a file without directly using a utility like Syncsort and I'm having trouble with the input procedure.
The format of the file is
SD B-Sort-File.
01 B-Sort-Record.
05 FirstName Pic X(10). (key2)
05 LastName Pic X(15). (key1)
05 AccountNum Pic X(9).
05 PurchDate Pic 9(6). format is DDMMYY
05 Price Pic 9(5). (Key3)
I am sorting on the 3 keys.
I need to use an input procedure to arrange the records to be:
LastName
FirstName
AccountNum
Price
PurchDate
and to change the date format to YYYYMMDD
My problem is that I don't have a clear picture or example of how to manipulate a file during an input procedure to give the required output for the sorted file.
Sorry if I'm in the wrong section. Since I wasn't using Syncsort direct I didn't know where to post.
Any help is greatly appreciated it. This assignment is way past due and the prof is not good at explaining things
Posted: Wed Apr 11, 2007 1:20 am
by DavidatK
And the Prof wants you to use the COBOL Sort feature, right? Not write your own algorithm? I've got meetings, but when I finish, in about two hours, if no one else has answered your question, we'll see if we can work through it.
Dave
Posted: Wed Apr 11, 2007 3:20 am
by laifas
Correct. He wants us to use the COBOL Sort feature. I'm sure it is just for torture, but what can you expect?
Thanks in advance.
Dani
Posted: Wed Apr 11, 2007 3:41 am
by DavidatK
Hi Dani,
First, check this link out in the IBM COBOL manual. I looked through it an think there are some good examples.
1.12 Sorting and merging files
I personally stay away from the COBOL internal sort as much as possible. I'd rather write two programs and use an external sort, be it DFSORT or SYNCSORT. The internal COBOL Sort is looked down upon here because it is not very efficient. Sometimes an internal sort is just plain required, and if you must sort a very large volume, using the COBOL Sort is the only way. But, if you can get the entire sort set into a COBOL table (Array), I'd write my own algorithm.
After you look through the chapter, or if you have specific questions now, let me know, I'll probably be here for another 1 1/2 hours or so.
Dave
Posted: Wed Apr 11, 2007 4:09 am
by laifas
When you have your SD does it need to mirror the input file you are sorting? I still don't see how to reverse the order for the DMY format I need.
I also don't see how to make the year into 4 digits.
I'm not sure why I keep sticking on this. My prof keeps telling me how 'curious' my code/thinking is.
Am I supposed to just move the fields I need from the input file to the SD file?
Thanks for the site, I spent alot of time there trying to find the wealth of info you gave me.
EDIT:
Oh..can I move from the Input record to Working Storage and back to the SD?
Posted: Wed Apr 11, 2007 4:32 am
by Veera
laifas,
prof is not good at explaining things
, Well we cant blame them.
Here is the code.
Code: Select all
000100******************************************************************00000100
000010 IDENTIFICATION DIVISION.
000300******************************************************************00000300
000400 PROGRAM-ID. WYMD0100. 00000400
000500 AUTHOR. TEST-VEERA. *00000500
000700 DATE-WRITTEN. APRIL 10,2007. *00000700
000800 DATE-COMPILED. *00000800
000070******************************************************************
000120* *
001100* ================================================= *00001100
001200* P R O G R A M I N F O R M A T I O N G U I D E *00001200
001300* ================================================= *00001300
000150* *
000160******************************************************************
000170* *
001700* PURPOSE : COBOL INTERNAL SORT PROGRAM *00001700
000190* *
000360******************************************************************
004900* M O D I F I C A T I O N L O G *00004400
000390******************************************************************
005100* DATE PROGRAMMER/ VERSION REASON *00004600
005200*(MM/DD/CCYY) (START 00) *00004700
000470******************************************************************
006900******************************************************************
000490 ENVIRONMENT DIVISION.
007200******************************************************************00005800
007300* 00005900
000500 CONFIGURATION SECTION.
007500* 00006100
007600 SOURCE-COMPUTER. IBM-370 WITH DEBUGGING MODE. 00006200
007700 OBJECT-COMPUTER. IBM-370. 00006300
007800* 00006400
000530 INPUT-OUTPUT SECTION.
000540 FILE-CONTROL.
000550*
008200 SELECT INPUT-FL ASSIGN TO INPFILE 00006800
008300 FILE STATUS IS 00006900
008400 WS-INPFILE-FL-STATUS. 00007000
000710*
008600 SELECT OUTPUT-FL ASSIGN TO OUTFILE 00007200
008700 ORGANIZATION IS SEQUENTIAL 00007300
008800 FILE STATUS IS 00007400
008900 WS-OUTFILE-FL-STATUS. 00007500
009000* 00007100
009100 SELECT SORT-FILE ASSIGN TO SORTFILE. 00007200
009200 00007600
009300***************************************************************** 00007700
000720 DATA DIVISION.
009500***************************************************************** 00007900
009600* 00008000
009700 FILE SECTION. 00008100
009800* 00008200
009900 FD INPUT-FL 00008300
010000 RECORDING MODE IS F 00008400
010100 LABEL RECORDS ARE STANDARD 00008500
010200 RECORD CONTAINS 45 CHARACTERS 00008600
010300 BLOCK CONTAINS 0 RECORDS 00008700
010400 DATA RECORD IS INPUT-FILE-REC. 00008800
010500* 00008900
010600 01 INPUT-FILE-REC. 00009000
010700 05 INP-FIRST-NAME PIC X(10). 00009100
010800 05 INP-LAST-NAME PIC X(15). 00009200
010900 05 INP-ACCT-NO PIC X(09). 00009300
011000 05 INP-PURCH-DATE PIC 9(06). 00009400
011100 05 INP-PRICE PIC 9(05). 00009500
036100 00034500
036200 FD OUTPUT-FL 00034600
036300 LABEL RECORDS ARE STANDARD 00034700
036400 BLOCK CONTAINS 0 RECORDS 00034800
036500 DATA RECORD IS OUT-FILE-REC. 00034900
010500* 00008900
010600 01 OUT-FILE-REC. 00009000
010700 05 OUT-FIRST-NAME PIC X(10). 00009100
010800 05 OUT-LAST-NAME PIC X(15). 00009200
010900 05 OUT-ACCT-NO PIC X(09). 00009300
011000 05 OUT-PURCH-DATE PIC 9(06). 00009400
011100 05 OUT-PRICE PIC 9(05). 00009500
037000 00035000
037100 SD SORT-FILE 00034600
037200 LABEL RECORDS ARE STANDARD 00034700
037300 BLOCK CONTAINS 0 RECORDS 00034800
037400 DATA RECORD IS SORT-REC. 00034900
037500 00035000
037600 01 SORT-REC. 00035100
010700 05 SORT-KEY. 00009100
010700 10 SRT-FIRST-NAME PIC X(10). 00009100
010800 10 SRT-LAST-NAME PIC X(15). 00009200
011100 10 SRT-PRICE PIC 9(05). 00009500
010900 05 SRT-ACCT-NO PIC X(09). 00009300
011000 05 SRT-PURCH-DATE PIC 9(06). 00009400
037900 00035000
038000***************************************************************** 00035400
038100 WORKING-STORAGE SECTION. 00035500
038200***************************************************************** 00035600
042800* 00040300
042900 01 WS-FILE-STATUS. 00040400
043000 05 WS-INPFILE-FL-STATUS PIC X(02) VALUE SPACES. 00040500
043100 05 WS-OUTFILE-FL-STATUS PIC X(02) VALUE SPACES. 00040600
043200* 00040700
043300***************************************************************** 00040800
052500* 05010001
052600 01 WS-SWITCHES-AND-HOLDS. 05020001
053500 05 WS-EOF-SORTFILE-SW PIC X VALUE 'N'. 05090001
053600 88 EOF-SORTFILE VALUE 'Y'. 05100001
053300 05 WS-EOF-INPFILE-SW PIC X VALUE 'N'. 05090001
053400 88 EOF-INPFILE VALUE 'Y'. 05100001
054000* 05130001
054100 01 WS-COUNTERS. 05140001
055000 05 WS-INREC-CNT PIC 9(07) VALUE ZERO. 05220001
055000 05 WS-OUTREC-CNT PIC 9(07) VALUE ZERO. 05220001
055000 05 WS-RETURN-CNT PIC 9(07) VALUE ZERO. 05220001
056800* 05370001
061600***************************************************************** 13540001
061700 PROCEDURE DIVISION. 13550001
061800******************************************************************13560001
061900 0000-MAIN-PROCESS SECTION. 13570001
062000******************************************************************13580001
062100 0010-MAINLINE. 13590001
062200* 13600001
062300 PERFORM 1000-INIT-PARA 13610001
062400 THRU 1000-EXIT. 13620001
062500 13630001
062600 SORT SORT-FILE
062700 ASCENDING KEY SORT-KEY
062800 INPUT PROCEDURE IS 2000-RELEASE-TO-SORT
062900 THRU 2000-EXIT
063000 OUTPUT PROCEDURE IS 3000-WRITE-OUTFILE
063100 THRU 3000-EXIT.
063200
063300 PERFORM 9000-WRAP-UP-PARA 13670001
063400 THRU 9000-EXIT. 13680001
063500* 13690001
063600 GOBACK. 13700001
063700 13710001
063800***************************************************************** 13720001
063900 1000-INIT-PARA. 13730001
064000***************************************************************** 13740001
064100 13750001
064200 DISPLAY ' SAMPLE PGM FOR COBOL INTERNAL SORT ' 13760001
065000* 13840001
066600 OPEN INPUT INPUT-FL 13980001
066700* 13990001
066800 IF WS-INPFILE-FL-STATUS NOT = '00' 14000001
066900 DISPLAY '1000-INIT-PARA-1 ' 14010001
067000 DISPLAY 'INPUT FILE OPEN ERROR...' 14020001
067100 DISPLAY 'ERROR CODE IS : ' WS-INPFILE-FL-STATUS 14030001
067400 END-IF. 14060001
067500* 14070001
067600 OPEN OUTPUT OUTPUT-FL 14080001
067700 14090001
067800 IF WS-OUTFILE-FL-STATUS NOT = '00' 14100001
067900 DISPLAY '1000-INIT-PARA-2 ' 14110001
068000 DISPLAY 'OUTPUT FILE OPEN ERROR...' 14120001
068100 DISPLAY 'ERROR CODE IS : ' WS-OUTFILE-FL-STATUS 14130001
068400 END-IF. 14160001
068500
077000 1000-EXIT. 14180001
077100 EXIT. 14190001
077200* 14200001
077300***************************************************************** 14220001
077400 2000-RELEASE-TO-SORT. 14230001
077500***************************************************************** 14240001
077800 14270001
096700 MOVE 'N' TO WS-EOF-INPFILE-SW 27580001
096600* 27570001
077900 PERFORM 2100-READ-INPUTFILE
078000 THRU 2100-EXIT
097000 UNTIL EOF-INPFILE. 27610001
078100
078800 2000-EXIT. 14440001
078900 EXIT. 14450001
079000 14460001
079100******************************************************************15410001
079200 2100-READ-INPUTFILE. 15420001
079300******************************************************************15430001
079400***************************************************************** 15440001
096600* 27570001
105100 READ INPUT-FL 28140001
105200 AT END 28140001
105200 MOVE 'Y' TO WS-EOF-INPFILE-SW 28140001
105300 DISPLAY 'END OF I/P FILE REACHED' 28140001
105300 NOT AT END
105700 ADD 1 TO WS-INREC-CNT 28140001
106700 MOVE INP-FIRST-NAME TO SRT-FIRST-NAME
105200 MOVE INP-LAST-NAME TO SRT-LAST-NAME
105200 MOVE INP-PRICE TO SRT-PRICE
105200 MOVE INP-ACCT-NO TO SRT-ACCT-NO
105200 MOVE INP-PURCH-DATE TO SRT-PURCH-DATE
096600* 27570001
085300 RELEASE SORT-REC. 18360001
096600* 27570001
083300 2100-EXIT. 15830001
083400 EXIT. 15840001
083500 15850001
103300******************************************************************18540001
103400 3000-WRITE-OUTFILE. 18550001
000860******************************************************************
103800***************************************************************** 18590001
001760
104000 PERFORM 3100-RETURN-SORT-FILE
104100 THRU 3100-EXIT
104200 UNTIL EOF-SORTFILE.
002810
104400 3000-EXIT.
104500 EXIT.
104600
010782******************************************************************
104800 3100-RETURN-SORT-FILE. 18550001
010870******************************************************************
010890
105100 RETURN SORT-FILE 28140001
105200 AT END MOVE 'Y' TO WS-EOF-SORTFILE-SW 28140001
105300 DISPLAY 'END OF SORT FILE REACHED' 28140001
105400 DISPLAY 'RETURNED FROM SORT = ' WS-RETURN-CNT 28140001
105500 GO TO 3100-EXIT. 28140001
011000
105700 ADD 1 TO WS-RETURN-CNT. 28140001
011020
106700 MOVE SRT-FIRST-NAME TO OUT-FIRST-NAME
106700 MOVE SRT-LAST-NAME TO OUT-LAST-NAME
106700 MOVE SRT-PRICE TO OUT-ACCT-NO
106700 MOVE SRT-ACCT-NO TO OUT-PURCH-DATE
106700 MOVE SRT-PURCH-DATE TO OUT-PRICE
106700*
156900 PERFORM 7000-WRITE-OUTFILE-PARA 31160001
157000 THRU 7000-EXIT. 31170001
106700*
210300 3100-EXIT.
011040 EXIT.
210500
267900******************************************************************31780001
268000 7000-WRITE-OUTFILE-PARA. 31790001
268100******************************************************************31800001
268400***************************************************************** 31830001
011060
269000 WRITE OUT-FILE-REC 31850001
014190
269200 EVALUATE WS-OUTFILE-FL-STATUS 31870001
269300 WHEN '00' 31880001
269400 ADD 1 TO WS-OUTREC-CNT 31890001
269500 INITIALIZE OUT-FILE-REC 31900001
269700 WHEN OTHER 31910001
269800 DISPLAY '7000-WRITE-OUTFILE-PARA ' 31920001
269900 DISPLAY 'OUTPUT FILE WRITE ERROR...' 31930001
270000 DISPLAY 'ERROR CODE IS :' WS-OUTFILE-FL-STATUS 31940001
270300 END-EVALUATE. 31970001
014230
270500 7000-EXIT. 31980001
270600 EXIT. 31990001
273000******************************************************************32240001
273100 9000-WRAP-UP-PARA. 32250001
273200******************************************************************32260001
014232
273400 CLOSE INPUT-FL. 32280001
014390
273600 IF WS-INPFILE-FL-STATUS NOT = '00' 32300001
273700 DISPLAY '9000-WRAP-UP-PARA' 32310001
273800 DISPLAY 'INPUT FILE CLOSE ERROR...' 32320001
273900 DISPLAY 'ERROR CODE IS : ' WS-INPFILE-FL-STATUS 32330001
274200 END-IF. 32360001
274300 32370001
274400 CLOSE OUTPUT-FL. 32380001
274500 32390001
274600 IF WS-OUTFILE-FL-STATUS NOT = '00' 32400001
274700 DISPLAY '9000-WRAP-UP-PARA' 32410001
274800 DISPLAY 'OUTPUT FILE CLOSE ERROR...' 32420001
274900 DISPLAY 'ERROR CODE IS : ' WS-OUTFILE-FL-STATUS 32430001
275200 END-IF. 32460001
275300 32470001
279500 DISPLAY '*********************************************' 32890001
279600 DISPLAY ' ' 32900001
280300 DISPLAY 'TOTAL RECORDS READ FROM THE I/P FILE = '
280400 WS-INREC-CNT
280300 DISPLAY 'TOTAL RECORDS WRITTEN TO THE O/P FILE = '
280400 WS-OUTREC-CNT
280500 DISPLAY 'TOTAL RECORDS RETURNED FROM SORT = '
280600 WS-RETURN-CNT.
282400 33140001
282500 9000-EXIT. 33150001
282600 EXIT. 33160001
286100******************************************************************33511003
P.S : I DINT CHECK UR DATE PART CHANGE. I GUESS IT CAN BE
HANDLED.
Thanks,
Veera
Posted: Wed Apr 11, 2007 4:48 am
by DavidatK
Lets start with the simple first, changing the date from DDMMYY to CCYYMMDD.
Now it looks like you need to use the PURCHDATE as part of your sort, I?ll assume true. So you need to convert the DDMMYY format to CCYYMMDD in your INPUT PROCEDURE, before it gets sorted.
I would redefine the PURCHDATE in the input record like this:
Code: Select all
01 INPUT-RECORD.
:
05 PURCHDATE PIC 9(6).
05 PURCHDATE-DDMMYY REDEFINES PURCHDATE.
10 DD PIC 99.
10 MM PIC 99.
10 YY PIC 99.
:
and define the sort PURCHDATE as
Code: Select all
01 SORT-RECORD.
:
05 PURCHDATE PIC 9(8).
05 PURCHDATE-CCYYMMDD REDEFINES PURCHDATE.
10 CC PIC 99.
10 YY PIC 99.
10 MM PIC 99.
10 DD PIC 99.
:
There are two ways to convert the date format. You can move each field (i.e. DD, MM, YY) or use MOVE CORRESPONDING. As below.
Code: Select all
MOVE DD OF PURCHDATE-DDMMYY TO DD OF PURCHDATE-CCYYMMDD.
MOVE MM OF PURCHDATE-DDMMYY TO MM OF PURCHDATE-CCYYMMDD.
MOVE YY OF PURCHDATE-DDMMYY TO YY OF PURCHDATE-CCYYMMDD.
--or?
MOVE CORESPONDING PURCHDATE-DDMMYY TO PURCHDATE-CCYYMMDD.
--In both cases you are going to have to populate the CC (century), so, you?ll have to decide upon a date that if the YY is greater then the CC is 19 and less than the CC is 20. We?ll take 50.
IF YY OF PURCHDATE-CCYYMMDD > 50
THEN
MOVE ?19? TO CC OF PURCHDATE-CCYYMMDD
ELSE
MOVE ?20? TO CC OF PURCHDATE-CCYYMMDD
END-IF.
So, now, the INPUT-RECORD PURCHDATE is formatted DDMMYY and the record you are going to sort is formatted CCYYMMDD.
Dave
Posted: Wed Apr 11, 2007 8:36 am
by laifas
Thanks guys, you've been a huge help. I can only figure its NOT the professor and I am unusually dense where COBOL is concerned.
Posted: Wed Apr 11, 2007 9:29 pm
by DavidatK
laifas,
Glad Veera and I could give you some help.
Let us know how your assignment turned out, and come back with any other questions/problems you might encounter, we're glad to help
Dave
Posted: Thu Apr 12, 2007 1:24 am
by Veera
Yeah Dave , lets wish his assignment goes well.
Thanks,
Veera.
Posted: Sat Apr 14, 2007 11:35 pm
by laifas
Well, I wasn't able to do it exactly as you guys suggested but it helped me to get both of the files sorted the way I needed. I ran aground on the Merge so I'm stuck again.
I'm not currently sure if I have my JCL wrong or if its that i'm not retrieving the file sorted by Syncsort right. It could be something else I suppose.
At any rate, thanks for getting me as far as I have gotten. If I'm not sure on where I've gone wrong should I post in both Utilities and JCL or just whichever one I think is the most likely issue?
Dani
Posted: Sun Apr 15, 2007 12:34 am
by Veera
Dani
You can post in Utilities and please note that put ur code and your
requirement clearly. Also give details about ur file attributes
layouts and the fields postion you want to merge.
Thanks,
Veera.
Topic deleted by Admin
Posted: Wed Jan 27, 2016 8:12 pm
by academyindia4
<< Content deleted By Admin >>