If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Order of picking data mismatch in Mainframes DB2 and AIX DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-05-09, 08:55
Satish K Satish K is offline
Registered User
 
Join Date: Nov 2009
Posts: 7
Order of picking data mismatch in Mainframes DB2 and AIX DB2

Hi,

My requirement is that our project is to be converted from Mainframes COBOL to AIX COBOL. But in db2 programs where the data is picked is coming in a different order compared to data picked between Mainframes and AIX.
Because of this i am getting mismatch in the o/p files.

In Mainframes for a db2 query with multiple rows satisfying we are not using CURSOR and in this case -811 error comes and even though we are picking the data and in Mainframes it picks the 2nd row satisfying it but in AIX DB2 it is not picking any rows. So in AIX DB2 also we want to pick the same row picked in Mainframes and in this way we tried several ways but not able to match the Mainframe results.

Can anybody suggest me how to get the solution for this?

Thx,
Satish
Reply With Quote
  #2 (permalink)  
Old 11-05-09, 09:21
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Not clear! Please give an example or if possible, the same code and query that is not 'working'

What version of DB2 are you using ?
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 11-05-09, 09:53
Satish K Satish K is offline
Registered User
 
Join Date: Nov 2009
Posts: 7
Version of AIX DB2 using :- DB2 Client 9.5.4

Query executed :-
SELECT DISTINCT
ROWNUMBER() OVER() AS RN1,
COMM_PROV_ID
FROM (SELECT
COMM_PROV_ID,
ROWNUMBER() OVER() AS RN
FROM DSNT.DWS_MTH_PROVIDER
WHERE PROV_NUMBER LIKE '382205859%' AND
NAME_SORT LIKE 'STERLINGAR%' AND
PROV_STATE = 'MI' AND
SOURCE_CODE = 'UB'
order by COMM_PROV_ID DESC) T where RN = 2

Result got in AIX DB2 :-
RN1 COMM_PROV_ID
-------------------- ------------
1 78290

Result got in Mainframe DB2 QMF :-
COMM
PROV
RN1 ID
----------- -----------
1 78291

---------------------------------------------------------

I am using the above query in the program and moving the result into
output file and also writing to report. So because of the above mismatch the
Mainframe o/p file and AIX o/p file are not matching.

Kindly let me know for any further clarifications.

Thx,
Satish
Reply With Quote
  #4 (permalink)  
Old 11-05-09, 10:00
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You should use ORDER BY to ensure consistent ordering of records.
Reply With Quote
  #5 (permalink)  
Old 11-05-09, 10:22
Satish K Satish K is offline
Registered User
 
Join Date: Nov 2009
Posts: 7
Even though i tried using ORDER BY but it is not picking the same records in Mainframes and AIX.

Can you please suggest me any ways?

Thx,
Satish
Reply With Quote
  #6 (permalink)  
Old 11-05-09, 10:23
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
The order should be in here :

ROWNUMBER() OVER() AS RN

Only then, your RN will be based on a specific order of the ciolumn
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #7 (permalink)  
Old 11-05-09, 10:30
Satish K Satish K is offline
Registered User
 
Join Date: Nov 2009
Posts: 7
I tried by giving as you suggested but even then it is not working :-

One more example :-

SELECT
PROV_SPECIAL
FROM (SELECT
PROV_SPECIAL,
ROWNUMBER() OVER() AS RN
FROM DSNW.DWS_PROVIDER_SPEC
WHERE US_AMIS_PROV_SPEC = ' ')
WHERE RN = 2
order by PROV_SPECIAL DESC

AIX DB2 o/p :-

PROV_SPECIAL
------------
PE

Mainframe o/p :-

PROV
SPECIAL
-------
A0

Why i am picking Row number = 2 because as part of migration from Mainframe to AIX,
in Mainframes if any -811 error comes it picks the second row, but in AIX it doesnt pick any row so i am giving as Row number = 2 in AIX to give same results as in Mainframes, but the results are not matching.

Please guide me further with any ideas.

Thx,
Satish
Reply With Quote
  #8 (permalink)  
Old 11-05-09, 10:53
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by Satish K View Post
Why i am picking Row number = 2
Once again, rows in a database do NOT have any inherent order, so any record can have the row number equal 2. To ensure consistent ordering you must use ORDER BY in the OLAP window specification.
Reply With Quote
  #9 (permalink)  
Old 11-05-09, 11:48
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
Satish K, This is just a guess, but the Mainframe is probably EBCIDIC and AIX is probably ASCII. The different code sets could be causing your sorting problems.
Reply With Quote
  #10 (permalink)  
Old 11-05-09, 13:12
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
Satish K, Another possibility. ORDER BY will ensure the order of a unique set of column values. If the column values you are sorting are not unique, the order of these duplicate rows can not be guaranteed. If nothing changes, the rows will probably come back in the same order for the same query. But if the rows are moved to different pages in the table space (Delete / Insert, Reorg, etc.) they may (or may not) be returned in the same order.

If possible, can you try adding another column to the ORDER BY that will make the columns ordered Unique with your ROW_NUMBER() OLAP function?
Reply With Quote
  #11 (permalink)  
Old 11-05-09, 13:47
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
I guessed that Satish K doesn't know "ORDER BY in the OLAP window specification" which all three(sathyaram_s, Nick Ivanov and Stealth DBA) suggested.

And, result must be one row only. So, DISTINCT and "ROWNUMBER() OVER() AS RN1" must be unnecessary.

The query would be like this:

SELECT -- DISTINCT
/* ROWNUMBER() OVER() AS RN1 */ 1,
COMM_PROV_ID
FROM (SELECT
COMM_PROV_ID,
ROWNUMBER() OVER(order by COMM_PROV_ID DESC) AS RN
FROM DSNT.DWS_MTH_PROVIDER
WHERE PROV_NUMBER LIKE '382205859%' AND
NAME_SORT LIKE 'STERLINGAR%' AND
PROV_STATE = 'MI' AND
SOURCE_CODE = 'UB'
/* order by COMM_PROV_ID DESC */) T where RN = 2
Reply With Quote
  #12 (permalink)  
Old 11-06-09, 09:03
Satish K Satish K is offline
Registered User
 
Join Date: Nov 2009
Posts: 7
Even i tried many ways it is showing the same :-

The mode of retreival in Mainframes DB2 is EBCDIC and in AIX is ASCII, so how can i make changes in my query to make the mode of retreival as EBCDIC while executing in AIX.

Example for mismatch :-
SELECT PROV_SPECIAL FROM DSNW.DWS_PROVIDER_SPEC
WHERE US_AMIS_PROV_SPEC = ' '
FETCH FIRST 10 ROWS ONLY

In Mainframes showing as :-

PROV
SPECIAL
-------
AL
A0
A0
A0
A0
A0
A0
A0
A0
A0

In AIX showing as :-

PROV_SPECIAL
------------
02
02
03
03
03
03
03
04
04
04

Kindly guide me further with your valuable suggestions.

Thx,
Satish
Reply With Quote
  #13 (permalink)  
Old 11-06-09, 10:07
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
If the column has only upper alpahbet and numeric digit, then try following for ASCII mode:
Code:
 ORDER BY
       TRANSLATE( PROV_SPECIAL
                , '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' -- ASCII sequence
                , 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' -- EBCDIC sequence
                ) DESC
If the column includes other characters, you can add these characters.

Last edited by tonkuma; 11-06-09 at 10:11.
Reply With Quote
  #14 (permalink)  
Old 11-06-09, 10:31
Satish K Satish K is offline
Registered User
 
Join Date: Nov 2009
Posts: 7
The same query got executed successfully in mainframes and not able to get executed in AIX :-


AIX-PROD ==>db2 "SELECT PROV_SPECIAL FROM DSNW.DWS_PROVIDER_SPEC
> WHERE US_AMIS_PROV_SPEC = ' '
> ORDER BY TRANSLATE(PROV_SPECIAL, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') DESC
> FETCH FIRST 10 ROWS ONLY
> "
SQL0440N No authorized routine named "TRANSLATE" of type "FUNCTION" having
compatible arguments was found. SQLSTATE=42884
Reply With Quote
  #15 (permalink)  
Old 11-06-09, 10:34
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
Satish K, you should only have to Translate it at one location. If you can Translate the z/OS output to ASCII, the AIX data is already in ASCII.

By the way, if you have z/OS V9, you can look at the functions ASCII_STR and EBCDIC_STR for conversion.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On