Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

right justify db2 column while searching data

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
cdhami

New User


Joined: 24 Jan 2006
Posts: 28

PostPosted: Sat Oct 02, 2010 5:58 pm    Post subject: right justify db2 column while searching data
Reply with quote

Hi all,
I have a unique problem with respect to db2 table query.

There is a column TRS_AMOUNT which is in char x(17) format ( stored from online screen as characters but input format is 9(15)v(2)) e.g if value is 10, the table contains

value as "10,00______" as it is character.

Problem is when i am using my SQL

EXEC SQL
SELECT FROM TBL
WHERE TRS_AMOUNT > "100,00______"
END-EXEC
i m expecting sqlcode100, but I am getting record bcos
"10,00_____" > "100,00____" in character comparision.

Question:
How do i resolve this as query is not working fine.
1. Is there any way in which i can right justify the db2 column and then do comparision with right justified character variable??
2. Any other way possible?

the Amt column is required to be in character format as it may contain non numeric data also (wild cards *).

Let me know
thanks in advance
cdhami
Back to top
View user's profile Send private message

Raghu navaikulam

Active User


Joined: 27 Sep 2008
Posts: 186
Location: chennai

PostPosted: Sat Oct 02, 2010 10:02 pm    Post subject: Reply to: right justify db2 column while searching data
Reply with quote

Hi cdhami

Quote:
There is a column TRS_AMOUNT which is in char x(17) format ( stored from online screen as characters but input format is 9(15)v(2)) e.g if value is 10, the table contains

value as "10,00______" as it is character.


If you are getting the data from CICS screen, then you can use the built-in function BIF DEEDIT to remove non-numeric characters from the input.

Eg. You entered ******12345678.90 on the screen. After BIF DEEDIT the data became 1234567890. The last two position can be considered as decimal positions(based on the field you used).

The syntax : EXEC CICS BIF DEEDIT FIELD(data-area) EN-EXEC.

Regards
Raghu
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10231
Location: italy

PostPosted: Sat Oct 02, 2010 10:04 pm    Post subject: Reply to: right justify db2 column while searching data
Reply with quote

the problem is not with Your sql, rather with the design !
why in &heaven a field supposedly a numeric value is defined as a char ?

it would be better to fix the design rather than tweak the sql
Back to top
View user's profile Send private message
cdhami

New User


Joined: 24 Jan 2006
Posts: 28

PostPosted: Sat Oct 02, 2010 10:23 pm    Post subject:
Reply with quote

Thanks for reply.
the reason the field is kept as character is because the amount field is a parameter which can be kept as wild character also. e.g. '*' is also permitted value to be stored.

This has caused the data definition to be kept as characters.

This should answer raghu's question also.

kindly let me know if any way is present.

Thanks
Cdhami
Back to top
View user's profile Send private message
Raghu navaikulam

Active User


Joined: 27 Sep 2008
Posts: 186
Location: chennai

PostPosted: Sat Oct 02, 2010 10:41 pm    Post subject: Reply to: right justify db2 column while searching data
Reply with quote

Hi Cdhami

Where you data is stored? in DB2 Tables? or Files?
DB2 will not store any wild char in a numeric data type.
You should clarify this, then only a solution can be obtained!

Regards
Raghu
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10231
Location: italy

PostPosted: Sat Oct 02, 2010 11:06 pm    Post subject: Reply to: right justify db2 column while searching data
Reply with quote

since the ts posted in the DB2 forum and
There is a column TRS_AMOUNT which is in char x(17)

I guess that' s all db2 related

this is just a sample of poor everything, design, no prototyping no due diligence in approaching the whole project

and ...
Code:
WHERE TRS_AMOUNT > "100,00______"


given the TS example the field is supposedly left aligned,
for a right aligned mischief the query should really look like
WHERE TRS_AMOUNT > "bbbbbbbbbbb100,00"

the only thing at this point is to confirm the bad design and a strong suggestion to review the whole thing
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Sat Oct 02, 2010 11:09 pm    Post subject:
Reply with quote

Hello,

Quote:
DB2 will not store any wild char in a numeric data type.
You should clarify this, then only a solution can be obtained!

It is important to read the topic completely . . .

Quote:
the reason the field is kept as character is because the amount field is a parameter which can be kept as wild character also. e.g. '*' is also permitted value to be stored.

This has caused the data definition to be kept as characters.

This should answer raghu's question also.
explains why the definition is character. . .

As suggested, this is not a good design. How are rules defined for which characters should compare higher or lower than which numeric values. I've not before seen an attempt to use wildcards in the middle of an actual number. . .

If only the numeric value is to be compared (i.e. 1000 versus 10000 with no "wildcard"ing), a separate numeric field might be defined in the table and comparisons done against this.

No matter how this is implemented, i believe there will be problems/issues.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1280
Location: Belgium

PostPosted: Mon Oct 04, 2010 3:25 pm    Post subject:
Reply with quote

first the design :
it could be solved a nullable numeric column where null correspond with '*'

secondly as it is now :

Code:
with tab1 as (
select '100,00             ' as col1 from sysibm.sysdummy1
union all
select '10,00              ' as col1 from sysibm.sysdummy1
union all
select '1,00               ' as col1 from sysibm.sysdummy1
union all
select '10100,01           ' as col1 from sysibm.sysdummy1
union all
select '*                  ' as col1 from sysibm.sysdummy1
)

select case when strip(col1) = '*' then -1.00 else dec(strip(col1)) end from tab1
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1280
Location: Belgium

PostPosted: Mon Oct 04, 2010 3:39 pm    Post subject:
Reply with quote

or to compare :
Code:
where col1 <> '*              '
  and dec(strip(col1)) > 100.00
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1280
Location: Belgium

PostPosted: Mon Oct 04, 2010 9:39 pm    Post subject:
Reply with quote

oops, actually DEC() doesn't interpret comma very well it just stops at it.
If you need the part after comma maximum 2,you'll need something like this :

Code:
  dec(substr(strip(col1),1,posstr (strip(col1),',') - 1),15,2)
+ dec(substr(strip(col1),posstr(strip(col1),',') + 1,2),15,2 ) / 100


if the part after comma is variable in length (in the example max 5)
you'll need this :
Code:
  dec(substr(strip(col1),1,posstr (strip(col1),',') - 1),15,5)
+ dec(substr(strip(col1),posstr(strip(col1),',') + 1),15,5 )
  / power(10,length(substr(strip(col1),posstr(strip(col1),',') + 1)))
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Export flat file data into excel sheet murali.andaluri DFSORT/ICETOOL 2 Mon Mar 20, 2017 5:39 pm
No new posts Append data from two files into a sin... Praveen04 DFSORT/ICETOOL 5 Thu Mar 16, 2017 7:29 pm
No new posts SPUFI -- Joining 3 tables – data in... Sysaron DB2 2 Wed Mar 08, 2017 4:18 am
No new posts Overriding PS data in rexx Shaheen Shaik CLIST & REXX 8 Fri Mar 03, 2017 5:08 pm
No new posts JCL to get submitted once dataset has... vinu78 JCL & VSAM 17 Thu Feb 16, 2017 7:32 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us