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

DB2 v8 mode - Order By clause not permitted


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rockish

Active User


Joined: 05 Jun 2009
Posts: 185
Location: Planet Earth

PostPosted: Thu Dec 31, 2009 10:08 pm
Reply with quote

Hello,

I am new to my work place. I was trying to execute a singleton select query like the following from a COBOL program,

Code:
SELECT a,b,c INTO :H, :H, :H
FROM Table1
WHERE col1 = :H
ORDER BY col2 DESC
FETCH FIRST ROW ONLY;


But, I get a compilation error as below,
Code:
DSNH109I E     DSNHAPLY LINE 360 COL 15  "ORDER BY" CLAUSE NOT PERMITTED


This syntax use to work well in my previous workplaces and I think usage of SELECT.. INTO.. ORDER BY is possible in DB2 v8 NFM.

I would now like to check the mode of DB2 v8 that my shop is in. Is there a command or a place where I can check it myself ?
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Dec 31, 2009 10:20 pm
Reply with quote

rockish wrote:
I think usage of SELECT.. INTO.. ORDER BY is possible in DB2 v8 NFM.

You think incorrectly. DB2 UDB for z/OS v8 Messages quite definitely states:
Quote:
A SELECT INTO statement cannot include ORDER BY, because the result cannot be more than a single row.
Back to top
View user's profile Send private message
rockish

Active User


Joined: 05 Jun 2009
Posts: 185
Location: Planet Earth

PostPosted: Thu Dec 31, 2009 10:25 pm
Reply with quote

Thanks for your reply.

Well, Yeah.. I indeed checked the messages in DB2 v8 and DB2 v9 guides as well. And I got the message you have quoted.

But I still remember like, I have written such queries in Cobol modules in my previous projects and they use to work.

Am in a totally confused state as now icon_sad.gif
Back to top
View user's profile Send private message
rockish

Active User


Joined: 05 Jun 2009
Posts: 185
Location: Planet Earth

PostPosted: Thu Dec 31, 2009 10:46 pm
Reply with quote

Well, I was doing a lit bit more of googling and found the following,

As per the red book titled 'DB2 UDB for z/OS Version 8: Everything You Ever Wanted to Know, ... and More' , in section 4.26, Page number 385
Quote:
The SELECT INTO statement must produce a result that contains a single row; else an
SQLCODE -811 is returned. Prior to DB2 V7, there was no way of ensuring that only a single
row could be returned when using a SELECT INTO statement. You had to use a cursor, and
the program itself would have to read in only the first row that matched the predicates and
throw away all other rows. With the addition of the FETCH FIRST n ROWS ONLY clause in
V7, this situation can be avoided. V7 allows you to code the FETCH FIRST ROWS ONLY
clause on a SELECT INTO statement to indicate that only one row is to be returned to the
program, even if multiple rows match the WHERE criteria. However, you could not specify the
ORDER BY clause to affect which row was returned.
With DB2 for z/OS Version 8, you can now specify the ORDER BY clause as well. When you
use both the FETCH FIRST 1 ROW ONLY and ORDER BY clauses, the result set is retrieved
and ordered first, and then the first row is returned. For example, using the sample employee
table, for all employees with a salary of more than $40000, put the salary of the employee
who has been employed the longest in host variable :HV1. This query can be coded as
shown in Example 4-8.
Code:
Example 4-8 SELECT INTO using ORDER BY
SELECT SALARY
FROM DSN8810.EMP
INTO :HV1
WHERE SALARY > 40000
ORDER BY HIREDATE FETCH FIRST ROW ONLY;

This functionality is only available in New-function mode.


With more thanks to google, I managed to find out my DB2 version and mode using a DB2 command,

Code:
DSN7100I  _DSN2 DSN7GCMD                                           
*** BEGIN DISPLAY OF GROUP(........) GROUP LEVEL(...) MODE(N)       
                  PROTOCOL LEVEL(2)  GROUP ATTACH NAME(....)       
--------------------------------------------------------------------
DB2                                    DB2 SYSTEM    IRLM           
MEMBER   ID  SUBSYS CMDPREF   STATUS   LVL NAME      SUBSYS IRLMPROC
-------- --- ----   --------  -------- --- --------  ----   --------
........   0 DSN2   _DSN2     ACTIVE   810 DCU9      RLM2   RLM2PROC
--------------------------------------------------------------------
*** END DISPLAY OF GROUP(........)                                 
DSN9022I  _DSN2 DSN7GCMD 'DISPLAY GROUP ' NORMAL COMPLETION         
***                                                                 

And it clearly uses Db2 v8 in NFM

Now, I totally dont understand why my compilation fails !!!!!

Any clues anybody ???
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Fri Jan 01, 2010 12:21 am
Reply with quote

Playing with this a bit, it seems to be an issue with the particular precompiler. I can only suggest that you contact the DB2 mavens at IBM, and follow their instructions implicitly.
Back to top
View user's profile Send private message
rockish

Active User


Joined: 05 Jun 2009
Posts: 185
Location: Planet Earth

PostPosted: Fri Jan 01, 2010 12:25 am
Reply with quote

hehe.. yeah.. after all that is why I posted this in the forum so that someone could help me with their suggestions :-)
Back to top
View user's profile Send private message
senthilssg

New User


Joined: 09 Dec 2005
Posts: 64
Location: USA

PostPosted: Mon Jan 04, 2010 7:31 am
Reply with quote

Please check with your DBA which version of DB2 precompiler is currently using in your shop .

This can be check by looking the version number in the job output of pre compilation JCL ie compilation listing

Note: -DIS GROUP command says what is the status of DB2 catalog with respect to DB2 migration .
If your shop use DB2 v7 pre compiler in DB2 v8 also , you may get this error .

Thanks
Senthil
Back to top
View user's profile Send private message
rockish

Active User


Joined: 05 Jun 2009
Posts: 185
Location: Planet Earth

PostPosted: Wed Jan 06, 2010 1:44 am
Reply with quote

Thanks for your information Senthil. I will check the pre-compiler version..
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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts HILITE on Browse mode? TSO/ISPF 2
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
No new posts Rotate partition-logical & physic... DB2 0
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
No new posts Difference when accessing dataset in ... JCL & VSAM 7
Search our Forums:

Back to Top