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
 

 

Moving character data to smallint in db2

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

New User


Joined: 19 Jan 2009
Posts: 59
Location: hyderabad

PostPosted: Thu Jul 14, 2016 12:38 am    Post subject: Moving character data to smallint in db2
Reply with quote

Hi All,
Came across a piece of code in one program, where the program is taking user input from online screen and inserting the same in db2 table.
Now,the input field corresponding to the online map is defined as alphanumeric in cobol; say
Code:
IPFLD-FID pic x(03).

The corresponding column in db2, where this value will be inserted is defined as SMALLINT.
When numeric input is keyed thru online, the insertion is good as expected; but if character input is given(for testing purpose,which ideally should not be the case), i am seeing the value is getting changed to numeric and getting inserted. Ex: abc is getting converted to 123 and getting inserted.
Could you throw some light on this.
Back to top
View user's profile Send private message

Akatsukami

Global Moderator


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

PostPosted: Thu Jul 14, 2016 2:01 am    Post subject:
Reply with quote

Likely DB2 is stripping off the zones and interpreting the result as binary coded decimal. Do you really mean "abc", or did you mean "ABC"?
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

PostPosted: Thu Jul 14, 2016 3:21 am    Post subject:
Reply with quote

Its because of the collating sequence that has the values 0 through 9 .
Quote:
but if character input is given(for testing purpose, which ideally should not be the case), i am seeing the value is getting changed to numeric and getting inserted. Ex: abc is getting converted to 123 and getting inserted.
Raise a defect and ask to validate before inserting.
Back to top
View user's profile Send private message
rikdeb

New User


Joined: 19 Jan 2009
Posts: 59
Location: hyderabad

PostPosted: Thu Jul 14, 2016 11:35 pm    Post subject: Reply to: Moving character data to smallint in db2
Reply with quote

Hi Rohit and Akatsukami,
Thanks for your help.Today i tried with both ábc' and 'ABC' .Both the cases it took the value 123. I was trying with random characters like xyz, and it took 789. I think as rohit said ,it is for the collating sequence 0 thru 9.
However i want to know more, how this actually works.I am looking for it in google, but if you have any more information, please pass on the same.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


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

PostPosted: Fri Jul 15, 2016 12:05 am    Post subject:
Reply with quote

You of course know that the characters (as well as everything else) are represented in memory and on mass storage as binary patterns. If you were to edit a data set using the ISPF editor, and set HEX ON, you might see something like this:
Code:

123 abc ABC xyz
---------------
FFF48884CCC4AAA
123012301230789

(Note that space is a character, and occupies one byte.)
The first line is glyphs (displayed or printed characters), one per byte. The third line is the high nybble of each byte, and the fourth is the low nybble.

The high nybble is called, for historical reasons, a "zone"; the three leftmost bytes is the example are "zoned decimal" (COBOL DISPLAY, PL/I CHAR or PIC). When converting to binary (COBOL COMP-5, PL/I FIXED BIN}, the code doing the conversion ignores the zones and interprets the low nybbles as decimal digits.

Knowing this (and EBCDIC mapping of glyphs to binary patterns), you can see why, if each of those three-character fields is moved to a binary field,
the value of the field will be 123, 123, 123, and 789, respectively.
Back to top
View user's profile Send private message
rikdeb

New User


Joined: 19 Jan 2009
Posts: 59
Location: hyderabad

PostPosted: Fri Jul 15, 2016 12:21 am    Post subject: Reply to: Moving character data to smallint in db2
Reply with quote

Thanks a lot Akatsukami !. Indeed a vry nice & useful explanation.
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 ODPP(Optim Data privacy Provider) Iss... Rama kishore IBM Tools 1 Mon Nov 07, 2016 5:46 pm
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm
No new posts output data in CSV Format janmejay COBOL Programming 8 Sat Oct 15, 2016 2:20 pm
This topic is locked: you cannot edit posts or make replies. output data in CSV Format janmejay DFSORT/ICETOOL 3 Sat Oct 15, 2016 2:16 pm
No new posts FTP Server and FTP.DATA vasanthz All Other Mainframe Topics 2 Wed Oct 12, 2016 11:49 pm


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