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

Why sort gives problem when coded as first stmt in program?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Wed Jul 04, 2007 5:59 pm
Reply with quote

I know this has been discussed sometime back but I am not clear with the reason behind it.
Reference http://www.ibmmainframes.com/viewtopic.php?t=19664
When I coded SORT stmt as below-
Code:
 PROCEDURE DIVISION.                                               
     SORT SORT-FILE ON ASCENDING KEY ELEMENT         
......

I received warning message in sysout-
Code:
IGZ0026W The SORT-RETURN special register was never referenced, but the current
         operation in program TEST2 on line number 16 was unsuccessful.

First change I did was to print SORT-RETURN, after that warning message didnt come but still I received unsorted o/p and SORT-RETURN was 20.

Then I changed my code to -
Code:
PROCEDURE DIVISION.                             
     DISPLAY 'IN THE PROGRAM'.                 
     SORT SORT-FILE ON ASCENDING KEY ELEMENT 
.......

And o/p came sorted properly. icon_confused.gif
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Wed Jul 04, 2007 6:51 pm
Reply with quote

when I compared assembly listing in both cases, there is a difference in two cases! ( Please note that I havent changed anything in SORT statement ) For your reference listing is given below,
Without DISPLAY stmt-
Code:
              L     2,296(0,9)              BL=1           
2010          XC    16(2,2),16(2)           SORT-RETURN   
              NI    85(9),X'FB'             TGTFIXD+85     
              L     3,92(0,9)               TGTFIXD+92     
              L     15,496(0,3)             V(IGZESMG )   
              LA    1,607(0,8)              PGMLIT AT +591
              BALR  14,15                                 
A0E8          MVC   240(4,10),232(10)       PSV=1         
              LA    4,362(0,11)             GN=8(00053A)   
              ST    4,232(0,10)             PVN=3         
              BC    15,476(0,11)            RELEASE-PARA   
     GN=8     EQU   *                                     
A0F0          MVC   232(4,10),240(10)       PVN=3         
              L     2,92(0,9)               TGTFIXD+92     
              L     15,496(0,2)             V(IGZESMG )   
              LA    1,606(0,8)              PGMLIT AT +590
              BALR  14,15                                 
A0EC          MVC   244(4,10),236(10)       PSV=2         
              L     11,40(0,12)             PBL=1         
              LA    3,404(0,11)             GN=9(000564)   
              ST    3,236(0,10)             PVN=4         
              BC    15,602(0,11)            RETURN-PARA   
     GN=9     EQU   *                                     
A0F4          MVC   236(4,10),244(10)       PVN=4         
              L     2,92(0,9)               TGTFIXD+92     
              L     15,496(0,2)             V(IGZESMG )   
              LA    1,605(0,8)              PGMLIT AT +589
              BALR  14,15                                 
     GN=24    EQU   * 



With DISPLAY before SORT-
Code:
               L     3,296(0,9)              BL=1           
 3010          XC    16(2,3),16(3)           SORT-RETURN   
               NI    85(9),X'FB'             TGTFIXD+85     
               L     15,496(0,2)             V(IGZESMG )   
               LA    1,621(0,8)              PGMLIT AT +605
               BALR  14,15                                 
 A0E8          MVC   240(4,10),232(10)       PSV=1         
               LA    4,372(0,11)             GN=8(000560)   
               ST    4,232(0,10)             PVN=3         
               BC    15,486(0,11)            RELEASE-PARA   
      GN=8     EQU   *                                     
 A0F0          MVC   232(4,10),240(10)       PVN=3         
               L     2,92(0,9)               TGTFIXD+92     
               L     15,496(0,2)             V(IGZESMG )   
               LA    1,620(0,8)              PGMLIT AT +604
               BALR  14,15                                 
 A0EC          MVC   244(4,10),236(10)       PSV=2         
               L     11,40(0,12)             PBL=1         
               LA    3,414(0,11)             GN=9(00058A)   
               ST    3,236(0,10)             PVN=4         
               BC    15,612(0,11)            RETURN-PARA   
      GN=9     EQU   *                                     
 A0F4          MVC   236(4,10),244(10)       PVN=4         
               L     2,92(0,9)               TGTFIXD+92     
               L     15,496(0,2)             V(IGZESMG )   
               LA    1,619(0,8)              PGMLIT AT +603
               BALR  14,15
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jul 04, 2007 11:03 pm
Reply with quote

Hello,

Sounds like there may be a bit more to your situation. . .

I just looked at a few programs and other than a SECTION or a para-name, SORT is the first cobol statement after the PROCEDURE DIVISION statement and they all work successfully. In the one-time programs, there is no reference to SORT-RETURN and i get no warning nor an error.

You might try inserting a "dummy" paragraph between PROCEDURE DIVISION and SORT just to see if it makes a difference.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu Jul 05, 2007 11:50 am
Reply with quote

Dick,
I tried with a para-name and founf no change in the results. Without display statement I am still getting unsorted o/p and when I add Display I get sorted o/p. icon_sad.gif

I don't know assembler, can somebody justify the two set of code generated for same SORT statement? (Listed above)
Back to top
View user's profile Send private message
Sandy Zimmer

Active Member


Joined: 13 Jun 2007
Posts: 826
Location: Wilmington, DE

PostPosted: Sat Jul 07, 2007 4:28 am
Reply with quote

The way I always did it was:

SORT SORT-FILE ON ASCENDING KEY ELEMENT
input procedure is 1000-sort-input thru 1999-exit
output procedure is 2000-sort-output thru 2999-exit
if sort-return is not zero - abend

I never ever used SECTIONs
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Jul 07, 2007 6:19 am
Reply with quote

Hi Abhijit,

Please post the JCL from this step and the SORT statement including 20 or so lines before and after the SORT statement.

The assembler shown is the rather awful generated stuff - not meant to be worked with for the most part. . . . If you still have it available, including the addresses that should be beside the instructions in the assembler code may be helpful.

Seeing the sort source and surrounding code may help with understanding why different registers were used in the 2 versions.
Back to top
View user's profile Send private message
Sandy Zimmer

Active Member


Joined: 13 Jun 2007
Posts: 826
Location: Wilmington, DE

PostPosted: Mon Jul 09, 2007 12:30 am
Reply with quote

Yes, Dick, I believe you are correct - sortlib is missing from the JCL.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Mon Jul 09, 2007 1:08 pm
Reply with quote

Dick,
I was writing an adhoc program for some query in the forum when I faced this problem. you can see the program posted here-
http://www.ibmmainframes.com/viewtopic.php?t=22462

Jcl was very simple
Code:
//jobcard
//step1 exec pgm=test1
//steplib dd dsn=my.loadlib,disp=shr


@ Sandy,
Where do you want me to specify SORTLIB here?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jul 09, 2007 6:26 pm
Reply with quote

Hi Abhijit,

Yup, remember that one well (it's been kinda recent icon_smile.gif ).

Did you have a chance to capture the addresses/displaments generated by the compiler for the 2 versions of the code?
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 7
No new posts Using API Gateway from CICS program CICS 0
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
Search our Forums:

Back to Top